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

Delta Between Two Patch Sets: src/JsEngine.cpp

Issue 29365532: Issue #3594 - Remove `globalJsObject` and add `GetGlobalObject()` (Closed)
Left Patch Set: use JsContext Created Nov. 28, 2016, 5:47 p.m.
Right Patch Set: nit fix Created Nov. 30, 2016, 5:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/JsContext.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->GetGlobalObject()) ; 94 AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->GetGlobalObject()) ;
95 return result; 95 return result;
96 } 96 }
97 97
98 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject() 98 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject()
99 { 99 {
100 JsContext context(shared_from_this()); 100 JsContext context(shared_from_this());
101 return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Glob al())); 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 }; 102 }
sergei 2016/11/29 09:47:12 Nit: no semicolon.
Eric 2016/11/30 17:59:46 Done.
103 103
104 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 104 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
105 const std::string& filename) 105 const std::string& filename)
106 { 106 {
107 const JsContext context(shared_from_this()); 107 const JsContext context(shared_from_this());
108 const v8::TryCatch tryCatch; 108 const v8::TryCatch tryCatch;
109 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source, 109 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source,
110 filename); 110 filename);
111 CheckTryCatch(tryCatch); 111 CheckTryCatch(tryCatch);
112 v8::Local<v8::Value> result = script->Run(); 112 v8::Local<v8::Value> result = script->Run();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 246
247 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 247 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
248 AdblockPlus::JsValuePtr value) 248 AdblockPlus::JsValuePtr value)
249 { 249 {
250 auto global = GetGlobalObject(); 250 auto global = GetGlobalObject();
251 if (!global) 251 if (!global)
252 throw std::runtime_error("Global object cannot be null"); 252 throw std::runtime_error("Global object cannot be null");
253 global->SetProperty(name, value); 253 global->SetProperty(name, value);
254 } 254 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld