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

Side by Side Diff: src/JsEngine.cpp

Issue 10198022: Pass application data into libadblockplus (Closed)
Patch Set: Merged upstream, addressed issues, renamed AppInfo fields Created April 17, 2013, 2:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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::Context> CreateContext( 9 v8::Handle<v8::Context> CreateContext(
10 v8::Isolate* isolate, 10 v8::Isolate* isolate,
11 const AdblockPlus::AppInfo& appInfo,
11 AdblockPlus::JsEngine& jsEngine) 12 AdblockPlus::JsEngine& jsEngine)
12 { 13 {
13 const v8::Locker locker(isolate); 14 const v8::Locker locker(isolate);
14 const v8::HandleScope handleScope; 15 const v8::HandleScope handleScope;
15 const v8::Handle<v8::ObjectTemplate> global = 16 const v8::Handle<v8::ObjectTemplate> global =
16 AdblockPlus::GlobalJsObject::Create(jsEngine); 17 AdblockPlus::GlobalJsObject::Create(appInfo, jsEngine);
17 return v8::Context::New(0, global); 18 return v8::Context::New(0, global);
18 } 19 }
19 20
20 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename) 21 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename)
21 { 22 {
22 const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str()); 23 const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str());
23 if (filename.length()) 24 if (filename.length())
24 { 25 {
25 const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str() ); 26 const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str() );
26 return v8::Script::Compile(v8Source, v8Filename); 27 return v8::Script::Compile(v8Source, v8Filename);
(...skipping 23 matching lines...) Expand all
50 return error.str(); 51 return error.str();
51 } 52 }
52 } 53 }
53 54
54 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, 55 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception,
55 const v8::Handle<v8::Message> message) 56 const v8::Handle<v8::Message> message)
56 : std::runtime_error(ExceptionToString(exception, message)) 57 : std::runtime_error(ExceptionToString(exception, message))
57 { 58 {
58 } 59 }
59 60
60 AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem, 61 AdblockPlus::JsEngine::JsEngine(const AppInfo& appInfo,
62 FileSystem* const fileSystem,
61 WebRequest* const webRequest, 63 WebRequest* const webRequest,
62 ErrorCallback* const errorCallback) 64 ErrorCallback* const errorCallback)
63 : fileSystem(*fileSystem), webRequest(*webRequest), 65 : fileSystem(*fileSystem), webRequest(*webRequest),
64 errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()), 66 errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()),
65 context(CreateContext(isolate, *this)) 67 context(CreateContext(isolate, appInfo, *this))
66 { 68 {
67 } 69 }
68 70
69 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 71 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
70 const std::string& filename) 72 const std::string& filename)
71 { 73 {
72 const Context context(*this); 74 const Context context(*this);
73 const v8::TryCatch tryCatch; 75 const v8::TryCatch tryCatch;
74 const v8::Handle<v8::Script> script = CompileScript(source, filename); 76 const v8::Handle<v8::Script> script = CompileScript(source, filename);
75 CheckTryCatch(tryCatch); 77 CheckTryCatch(tryCatch);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 for (int i = 0; i < arguments.Length(); i++) 131 for (int i = 0; i < arguments.Length(); i++)
130 list.push_back(JsValuePtr(new JsValue(*this, arguments[i]))); 132 list.push_back(JsValuePtr(new JsValue(*this, arguments[i])));
131 return list; 133 return list;
132 } 134 }
133 135
134 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) 136 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine)
135 : locker(jsEngine.isolate), handleScope(), 137 : locker(jsEngine.isolate), handleScope(),
136 contextScope(jsEngine.context) 138 contextScope(jsEngine.context)
137 { 139 {
138 } 140 }
OLDNEW
« src/AppInfoJsObject.cpp ('K') | « src/GlobalJsObject.cpp ('k') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld