| 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 #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 AdblockPlus::JsEngine& jsEngine) | 11 AdblockPlus::JsEngine& jsEngine) |
| 12 { | 12 { |
| 13 const v8::Locker locker(isolate); | 13 const v8::Locker locker(isolate); |
| 14 AdblockPlus::JsEngine::IsolateSetter isolateSetter(isolate); |
| 14 const v8::HandleScope handleScope; | 15 const v8::HandleScope handleScope; |
| 15 return v8::Context::New(0, AdblockPlus::GlobalJsObject::Create(jsEngine)); | 16 return v8::Context::New(0, AdblockPlus::GlobalJsObject::Create(jsEngine)); |
| 16 } | 17 } |
| 17 | 18 |
| 18 v8::Local<v8::Script> CompileScript(const std::string& source, const std::stri
ng& filename) | 19 v8::Local<v8::Script> CompileScript(const std::string& source, const std::stri
ng& filename) |
| 19 { | 20 { |
| 20 const v8::Local<v8::String> v8Source = AdblockPlus::Utils::ToV8String(source
); | 21 const v8::Local<v8::String> v8Source = AdblockPlus::Utils::ToV8String(source
); |
| 21 if (filename.length()) | 22 if (filename.length()) |
| 22 { | 23 { |
| 23 const v8::Local<v8::String> v8Filename = AdblockPlus::Utils::ToV8String(fi
lename); | 24 const v8::Local<v8::String> v8Filename = AdblockPlus::Utils::ToV8String(fi
lename); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 52 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, | 53 AdblockPlus::JsError::JsError(const v8::Handle<v8::Value> exception, |
| 53 const v8::Handle<v8::Message> message) | 54 const v8::Handle<v8::Message> message) |
| 54 : std::runtime_error(ExceptionToString(exception, message)) | 55 : std::runtime_error(ExceptionToString(exception, message)) |
| 55 { | 56 { |
| 56 } | 57 } |
| 57 | 58 |
| 58 AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem, | 59 AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem, |
| 59 WebRequest* const webRequest, | 60 WebRequest* const webRequest, |
| 60 ErrorCallback* const errorCallback) | 61 ErrorCallback* const errorCallback) |
| 61 : fileSystem(*fileSystem), webRequest(*webRequest), | 62 : fileSystem(*fileSystem), webRequest(*webRequest), |
| 62 errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()), | 63 errorCallback(*errorCallback), isolate(v8::Isolate::New()), |
| 63 context(CreateContext(isolate, *this)) | 64 context(CreateContext(isolate, *this)) |
| 64 { | 65 { |
| 65 } | 66 } |
| 66 | 67 |
| 67 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc
e, | 68 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc
e, |
| 68 const std::string& filename) | 69 const std::string& filename) |
| 69 { | 70 { |
| 70 const Context context(*this); | 71 const Context context(*this); |
| 71 const v8::TryCatch tryCatch; | 72 const v8::TryCatch tryCatch; |
| 72 const v8::Local<v8::Script> script = CompileScript(source, filename); | 73 const v8::Local<v8::Script> script = CompileScript(source, filename); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
ents& arguments) | 124 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum
ents& arguments) |
| 124 { | 125 { |
| 125 const Context context(*this); | 126 const Context context(*this); |
| 126 JsValueList list; | 127 JsValueList list; |
| 127 for (int i = 0; i < arguments.Length(); i++) | 128 for (int i = 0; i < arguments.Length(); i++) |
| 128 list.push_back(JsValuePtr(new JsValue(*this, arguments[i]))); | 129 list.push_back(JsValuePtr(new JsValue(*this, arguments[i]))); |
| 129 return list; | 130 return list; |
| 130 } | 131 } |
| 131 | 132 |
| 132 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) | 133 AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) |
| 133 : locker(jsEngine.isolate), handleScope(), | 134 : locker(jsEngine.isolate), isolateSetter(jsEngine.isolate), handleScope(), |
| 134 contextScope(jsEngine.context) | 135 contextScope(jsEngine.context) |
| 135 { | 136 { |
| 136 } | 137 } |
| 138 |
| 139 AdblockPlus::JsEngine::IsolateSetter::IsolateSetter(v8::Isolate* isolate) |
| 140 : isolate(isolate) |
| 141 { |
| 142 isolate->Enter(); |
| 143 } |
| 144 |
| 145 AdblockPlus::JsEngine::IsolateSetter::~IsolateSetter() |
| 146 { |
| 147 isolate->Exit(); |
| 148 } |
| OLD | NEW |