Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -79,10 +79,8 @@ |
const v8::HandleScope handleScope; |
result->context.reset(result->isolate, v8::Context::New(result->isolate)); |
- v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( |
- result->isolate, result->context)->Global(); |
- AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
- JsValuePtr(new JsValue(result, globalContext))); |
+ AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
+ result->GetGlobalJsObject()); |
return result; |
} |
@@ -227,3 +225,22 @@ |
logSystem = val; |
} |
+ |
+AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalJsObject() |
+{ |
+ if (!globalJsObject) |
Eric
2015/06/10 17:48:16
There's really no need to use deferred evaluation
|
+ { |
+ v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( |
+ isolate, context)->Global(); |
+ globalJsObject = JsValuePtr( |
+ new JsValue(JsEnginePtr(shared_from_this()), globalContext)); |
+ } |
+ return globalJsObject; |
+} |
+ |
+void AdblockPlus::JsEngine::SetGlobalJsObject(AdblockPlus::JsValuePtr global) |
+{ |
+ if (!global) |
+ throw std::runtime_error("Global object cannot be null"); |
+ globalJsObject = global; |
+} |