Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/JsEngine.cpp

Issue 10305024: Simplify context setup, set properties on the global object directly instead of using templates (Closed)
Left Patch Set: Created April 18, 2013, 6:26 a.m.
Right Patch Set: Unbitrotted patch Created April 18, 2013, 11:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "GlobalJsObject.h" 4 #include "GlobalJsObject.h"
5 #include "Utils.h" 5 #include "Utils.h"
6 6
7 namespace 7 namespace
8 { 8 {
9 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename) 9 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename)
10 { 10 {
(...skipping 28 matching lines...) Expand all
39 return error.str(); 39 return error.str();
40 } 40 }
41 } 41 }
42 42
43 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, 43 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception,
44 const v8::Handle<v8::Message> message) 44 const v8::Handle<v8::Message> message)
45 : std::runtime_error(ExceptionToString(exception, message)) 45 : std::runtime_error(ExceptionToString(exception, message))
46 { 46 {
47 } 47 }
48 48
49 AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem, 49 AdblockPlus::JsEngine::JsEngine(const AppInfo& appInfo,
50 FileSystem* const fileSystem,
50 WebRequest* const webRequest, 51 WebRequest* const webRequest,
51 ErrorCallback* const errorCallback) 52 ErrorCallback* const errorCallback)
52 : fileSystem(*fileSystem), webRequest(*webRequest), 53 : fileSystem(*fileSystem), webRequest(*webRequest),
53 errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()) 54 errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent())
54 { 55 {
55 const v8::Locker locker(isolate); 56 const v8::Locker locker(isolate);
56 const v8::HandleScope handleScope; 57 const v8::HandleScope handleScope;
57 58
58 context = v8::Context::New(); 59 context = v8::Context::New();
59 AdblockPlus::GlobalJsObject::Setup(*this, 60 AdblockPlus::GlobalJsObject::Setup(*this, appInfo,
60 JsValuePtr(new JsValue(*this, context->Global()))); 61 JsValuePtr(new JsValue(*this, context->Global())));
61 } 62 }
62 63
63 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 64 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
64 const std::string& filename) 65 const std::string& filename)
65 { 66 {
66 const Context context(*this); 67 const Context context(*this);
67 const v8::TryCatch tryCatch; 68 const v8::TryCatch tryCatch;
68 const v8::Handle<v8::Script> script = CompileScript(source, filename); 69 const v8::Handle<v8::Script> script = CompileScript(source, filename);
69 CheckTryCatch(tryCatch); 70 CheckTryCatch(tryCatch);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 for (int i = 0; i < arguments.Length(); i++) 134 for (int i = 0; i < arguments.Length(); i++)
134 list.push_back(JsValuePtr(new JsValue(*this, arguments[i]))); 135 list.push_back(JsValuePtr(new JsValue(*this, arguments[i])));
135 return list; 136 return list;
136 } 137 }
137 138
138 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) 139 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine)
139 : locker(jsEngine.isolate), handleScope(), 140 : locker(jsEngine.isolate), handleScope(),
140 contextScope(jsEngine.context) 141 contextScope(jsEngine.context)
141 { 142 {
142 } 143 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld