Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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 Loading... | |
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 } |
LEFT | RIGHT |