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

Unified Diff: src/JsEngine.cpp

Issue 29416579: Issue 5034 - Part 1: Pass a JsValue directly to SetProperty() and return from GetProperty() (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 18, 2017, 9:17 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 | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('j') | 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
@@ -140,24 +140,25 @@
JsEnginePtr result(new JsEngine(isolate, std::move(timer)));
const v8::Locker locker(result->GetIsolate());
const v8::Isolate::Scope isolateScope(result->GetIsolate());
const v8::HandleScope handleScope(result->GetIsolate());
result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(),
v8::Context::New(result->GetIsolate())));
- AdblockPlus::GlobalJsObject::Setup(*result, appInfo, result->GetGlobalObject());
+ auto global = result->GetGlobalObject();
+ AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global);
return result;
}
-AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject()
+AdblockPlus::JsValue AdblockPlus::JsEngine::GetGlobalObject()
{
JsContext context(shared_from_this());
- return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Global()));
+ return JsValue(shared_from_this(), context.GetV8Context()->Global());
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
const JsContext context(shared_from_this());
const v8::TryCatch tryCatch;
const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source,
@@ -321,15 +322,15 @@
if (!val)
throw std::runtime_error("LogSystem cannot be null");
logSystem = val;
}
void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
- const AdblockPlus::JsValuePtr& value)
+ const AdblockPlus::JsValue& value)
{
auto global = GetGlobalObject();
- if (!global)
+ if (global.IsUndefined() || global.IsNull())
sergei 2017/04/19 10:24:31 It's different, previously it was possible to set
hub 2017/04/19 14:47:11 Done.
throw std::runtime_error("Global object cannot be null");
- global->SetProperty(name, value);
+ global.SetProperty(name, value);
}
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld