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

Unified Diff: src/JsEngine.cpp

Issue 5653480979038208: Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates (Closed)
Patch Set: Added a unit test. Changed the global object injection routine. Created June 10, 2015, 8:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld