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

Side by Side Diff: src/JsEngine.cpp

Issue 29365532: Issue #3594 - Remove `globalJsObject` and add `GetGlobalObject()` (Closed)
Patch Set: use JsContext Created Nov. 28, 2016, 5:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/JsContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons t ScopedV8IsolatePtr& isolate) 84 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons t ScopedV8IsolatePtr& isolate)
85 { 85 {
86 JsEnginePtr result(new JsEngine(isolate)); 86 JsEnginePtr result(new JsEngine(isolate));
87 87
88 const v8::Locker locker(result->GetIsolate()); 88 const v8::Locker locker(result->GetIsolate());
89 const v8::Isolate::Scope isolateScope(result->GetIsolate()); 89 const v8::Isolate::Scope isolateScope(result->GetIsolate());
90 const v8::HandleScope handleScope(result->GetIsolate()); 90 const v8::HandleScope handleScope(result->GetIsolate());
91 91
92 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), 92 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(),
93 v8::Context::New(result->GetIsolate()))); 93 v8::Context::New(result->GetIsolate())));
94 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( 94 AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->GetGlobalObject()) ;
95 result->GetIsolate(), *result->context)->Global();
96 result->globalJsObject = JsValuePtr(new JsValue(result, globalContext));
97 AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->globalJsObject);
98 return result; 95 return result;
99 } 96 }
100 97
98 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject()
99 {
100 JsContext context(shared_from_this());
101 return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Glob al()));
Eric 2016/11/28 17:51:27 `JsContext` creates a scope that's entered upon co
sergei 2016/11/29 09:47:12 I would merely like to clarify here that not "the
Eric 2016/11/30 17:59:46 Right. I had a problem on an earlier iteration of
102 };
sergei 2016/11/29 09:47:12 Nit: no semicolon.
Eric 2016/11/30 17:59:46 Done.
103
101 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 104 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
102 const std::string& filename) 105 const std::string& filename)
103 { 106 {
104 const JsContext context(shared_from_this()); 107 const JsContext context(shared_from_this());
105 const v8::TryCatch tryCatch; 108 const v8::TryCatch tryCatch;
106 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source, 109 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source,
107 filename); 110 filename);
108 CheckTryCatch(tryCatch); 111 CheckTryCatch(tryCatch);
109 v8::Local<v8::Value> result = script->Run(); 112 v8::Local<v8::Value> result = script->Run();
110 CheckTryCatch(tryCatch); 113 CheckTryCatch(tryCatch);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (!val) 240 if (!val)
238 throw std::runtime_error("LogSystem cannot be null"); 241 throw std::runtime_error("LogSystem cannot be null");
239 242
240 logSystem = val; 243 logSystem = val;
241 } 244 }
242 245
243 246
244 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 247 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
245 AdblockPlus::JsValuePtr value) 248 AdblockPlus::JsValuePtr value)
246 { 249 {
247 if (!globalJsObject) 250 auto global = GetGlobalObject();
251 if (!global)
248 throw std::runtime_error("Global object cannot be null"); 252 throw std::runtime_error("Global object cannot be null");
249 253 global->SetProperty(name, value);
250 globalJsObject->SetProperty(name, value);
251 } 254 }
OLDNEW
« no previous file with comments | « src/JsContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld