Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -6,16 +6,17 @@ |
namespace |
{ |
v8::Handle<v8::Context> CreateContext( |
v8::Isolate* isolate, |
AdblockPlus::JsEngine& jsEngine) |
{ |
const v8::Locker locker(isolate); |
+ AdblockPlus::JsEngine::IsolateSetter isolateSetter(isolate); |
const v8::HandleScope handleScope; |
return v8::Context::New(0, AdblockPlus::GlobalJsObject::Create(jsEngine)); |
} |
v8::Local<v8::Script> CompileScript(const std::string& source, const std::string& filename) |
{ |
const v8::Local<v8::String> v8Source = AdblockPlus::Utils::ToV8String(source); |
if (filename.length()) |
@@ -54,17 +55,17 @@ AdblockPlus::JsError::JsError(const v8:: |
: std::runtime_error(ExceptionToString(exception, message)) |
{ |
} |
AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem, |
WebRequest* const webRequest, |
ErrorCallback* const errorCallback) |
: fileSystem(*fileSystem), webRequest(*webRequest), |
- errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()), |
+ errorCallback(*errorCallback), isolate(v8::Isolate::New()), |
context(CreateContext(isolate, *this)) |
{ |
} |
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source, |
const std::string& filename) |
{ |
const Context context(*this); |
@@ -125,12 +126,23 @@ AdblockPlus::JsValueList AdblockPlus::Js |
const Context context(*this); |
JsValueList list; |
for (int i = 0; i < arguments.Length(); i++) |
list.push_back(JsValuePtr(new JsValue(*this, arguments[i]))); |
return list; |
} |
AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine) |
- : locker(jsEngine.isolate), handleScope(), |
+ : locker(jsEngine.isolate), isolateSetter(jsEngine.isolate), handleScope(), |
contextScope(jsEngine.context) |
{ |
} |
+ |
+AdblockPlus::JsEngine::IsolateSetter::IsolateSetter(v8::Isolate* isolate) |
+ : isolate(isolate) |
+{ |
+ isolate->Enter(); |
+} |
+ |
+AdblockPlus::JsEngine::IsolateSetter::~IsolateSetter() |
+{ |
+ isolate->Exit(); |
+} |