OLD | NEW |
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 | 5 |
6 namespace | 6 namespace |
7 { | 7 { |
8 v8::Handle<v8::Context> CreateContext( | 8 v8::Handle<v8::Context> CreateContext( |
| 9 const AdblockPlus::AppInfo& appInfo, |
9 AdblockPlus::ErrorCallback& errorCallback, | 10 AdblockPlus::ErrorCallback& errorCallback, |
10 AdblockPlus::WebRequest& webRequest) | 11 AdblockPlus::WebRequest& webRequest) |
11 { | 12 { |
12 const v8::Locker locker(v8::Isolate::GetCurrent()); | 13 const v8::Locker locker(v8::Isolate::GetCurrent()); |
13 const v8::HandleScope handleScope; | 14 const v8::HandleScope handleScope; |
14 const v8::Handle<v8::ObjectTemplate> global = | 15 const v8::Handle<v8::ObjectTemplate> global = |
15 AdblockPlus::GlobalJsObject::Create(errorCallback, webRequest); | 16 AdblockPlus::GlobalJsObject::Create(appInfo, errorCallback, webRequest); |
16 return v8::Context::New(0, global); | 17 return v8::Context::New(0, global); |
17 } | 18 } |
18 | 19 |
19 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str
ing& filename) | 20 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str
ing& filename) |
20 { | 21 { |
21 const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str()); | 22 const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str()); |
22 if (filename.length()) | 23 if (filename.length()) |
23 { | 24 { |
24 const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str()
); | 25 const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str()
); |
25 return v8::Script::Compile(v8Source, v8Filename); | 26 return v8::Script::Compile(v8Source, v8Filename); |
(...skipping 30 matching lines...) Expand all Loading... |
56 return error.str(); | 57 return error.str(); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, | 61 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, |
61 const v8::Handle<v8::Message> message) | 62 const v8::Handle<v8::Message> message) |
62 : std::runtime_error(ExceptionToString(exception, message)) | 63 : std::runtime_error(ExceptionToString(exception, message)) |
63 { | 64 { |
64 } | 65 } |
65 | 66 |
66 AdblockPlus::JsEngine::JsEngine(const FileReader* const fileReader, | 67 AdblockPlus::JsEngine::JsEngine(const AppInfo& appInfo, |
| 68 const FileReader* const fileReader, |
67 WebRequest* const webRequest, | 69 WebRequest* const webRequest, |
68 ErrorCallback* const errorCallback) | 70 ErrorCallback* const errorCallback) |
69 : fileReader(fileReader), context(CreateContext(*errorCallback, *webRequest)) | 71 : fileReader(fileReader), |
| 72 context(CreateContext(appInfo, *errorCallback, *webRequest)) |
70 { | 73 { |
71 } | 74 } |
72 | 75 |
73 std::string AdblockPlus::JsEngine::Evaluate(const std::string& source, | 76 std::string AdblockPlus::JsEngine::Evaluate(const std::string& source, |
74 const std::string& filename) | 77 const std::string& filename) |
75 { | 78 { |
76 const v8::Locker locker(v8::Isolate::GetCurrent()); | 79 const v8::Locker locker(v8::Isolate::GetCurrent()); |
77 const v8::HandleScope handleScope; | 80 const v8::HandleScope handleScope; |
78 const v8::Context::Scope contextScope(context); | 81 const v8::Context::Scope contextScope(context); |
79 const v8::TryCatch tryCatch; | 82 const v8::TryCatch tryCatch; |
(...skipping 10 matching lines...) Expand all Loading... |
90 const std::auto_ptr<std::istream> file = fileReader->Read(scriptPath); | 93 const std::auto_ptr<std::istream> file = fileReader->Read(scriptPath); |
91 if (!*file) | 94 if (!*file) |
92 throw std::runtime_error("Unable to load script " + scriptPath); | 95 throw std::runtime_error("Unable to load script " + scriptPath); |
93 Evaluate(Slurp(*file)); | 96 Evaluate(Slurp(*file)); |
94 } | 97 } |
95 | 98 |
96 void AdblockPlus::JsEngine::Gc() | 99 void AdblockPlus::JsEngine::Gc() |
97 { | 100 { |
98 while (!v8::V8::IdleNotification()); | 101 while (!v8::V8::IdleNotification()); |
99 } | 102 } |
OLD | NEW |