| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 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 const auto i = GetIsolate(); | 100 JsContext context(shared_from_this()); |
|
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
| |
| 101 const v8::Locker locker(i); | 101 return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Glob al())); |
| 102 const v8::Isolate::Scope isolateScope(i); | 102 } |
| 103 const v8::HandleScope handleScope(i); | |
| 104 return JsValuePtr(new JsValue(shared_from_this(), v8::Local<v8::Context>::New( i, *context)->Global())); | |
| 105 }; | |
| 106 | 103 |
| 107 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, | 104 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, |
| 108 const std::string& filename) | 105 const std::string& filename) |
| 109 { | 106 { |
| 110 const JsContext context(shared_from_this()); | 107 const JsContext context(shared_from_this()); |
| 111 const v8::TryCatch tryCatch; | 108 const v8::TryCatch tryCatch; |
| 112 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source, | 109 const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source, |
| 113 filename); | 110 filename); |
| 114 CheckTryCatch(tryCatch); | 111 CheckTryCatch(tryCatch); |
| 115 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... | |
| 248 | 245 |
| 249 | 246 |
| 250 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 247 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 251 AdblockPlus::JsValuePtr value) | 248 AdblockPlus::JsValuePtr value) |
| 252 { | 249 { |
| 253 auto global = GetGlobalObject(); | 250 auto global = GetGlobalObject(); |
| 254 if (!global) | 251 if (!global) |
| 255 throw std::runtime_error("Global object cannot be null"); | 252 throw std::runtime_error("Global object cannot be null"); |
| 256 global->SetProperty(name, value); | 253 global->SetProperty(name, value); |
| 257 } | 254 } |
| LEFT | RIGHT |