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

Unified Diff: src/JsEngine.cpp

Issue 29365532: Issue #3594 - Remove `globalJsObject` and add `GetGlobalObject()` (Closed)
Patch Set: Created Nov. 28, 2016, 2:05 p.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
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -91,13 +91,19 @@
result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(),
v8::Context::New(result->GetIsolate())));
- v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New(
- result->GetIsolate(), *result->context)->Global();
- result->globalJsObject = JsValuePtr(new JsValue(result, globalContext));
- AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->globalJsObject);
+ AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->GetGlobalObject());
return result;
}
+AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject()
+{
+ const auto i = GetIsolate();
sergei 2016/11/28 15:04:33 Why not to use JsContext context(shared_from_this(
Eric 2016/11/28 15:33:24 That should work. The code here is a minimal extra
+ const v8::Locker locker(i);
+ const v8::Isolate::Scope isolateScope(i);
+ const v8::HandleScope handleScope(i);
+ return JsValuePtr(new JsValue(shared_from_this(), v8::Local<v8::Context>::New(i, *context)->Global()));
+};
+
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
@@ -244,8 +250,8 @@
void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
AdblockPlus::JsValuePtr value)
{
- if (!globalJsObject)
+ auto global = GetGlobalObject();
+ if (!global)
throw std::runtime_error("Global object cannot be null");
-
- globalJsObject->SetProperty(name, value);
+ global->SetProperty(name, value);
}
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld