| 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-2015 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 static void Init() | 64 static void Init() |
| 65 { | 65 { |
| 66 // it's threadsafe since C++11 and it will be instantiated only once and | 66 // it's threadsafe since C++11 and it will be instantiated only once and |
| 67 // destroyed at the application exit | 67 // destroyed at the application exit |
| 68 static V8Initializer initializer; | 68 static V8Initializer initializer; |
| 69 } | 69 } |
| 70 }; | 70 }; |
| 71 } | 71 } |
| 72 | 72 |
| 73 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() | 73 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
| 74 : isolate(v8::Isolate::New()) | 74 { |
| 75 { | 75 V8Initializer::Init(); |
| 76 isolate = v8::Isolate::New(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() | 79 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() |
| 79 { | 80 { |
| 80 isolate->Dispose(); | 81 isolate->Dispose(); |
| 81 isolate = nullptr; | 82 isolate = nullptr; |
| 82 } | 83 } |
| 83 | 84 |
| 84 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) | 85 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) |
| 85 : isolate(isolate ? isolate : std::make_shared<ScopedV8Isolate>()) | 86 : isolate(isolate) |
| 86 { | 87 { |
| 87 } | 88 } |
| 88 | 89 |
| 89 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons
t ScopedV8IsolatePtr& isolate) | 90 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons
t ScopedV8IsolatePtr& isolate) |
| 90 { | 91 { |
| 91 V8Initializer::Init(); | |
| 92 JsEnginePtr result(new JsEngine(isolate)); | 92 JsEnginePtr result(new JsEngine(isolate)); |
| 93 | 93 |
| 94 const v8::Locker locker(result->GetIsolate()); | 94 const v8::Locker locker(result->GetIsolate()); |
| 95 const v8::Isolate::Scope isolateScope(result->GetIsolate()); | 95 const v8::Isolate::Scope isolateScope(result->GetIsolate()); |
| 96 const v8::HandleScope handleScope(result->GetIsolate()); | 96 const v8::HandleScope handleScope(result->GetIsolate()); |
| 97 | 97 |
| 98 result->context.reset(new v8::UniquePersistent<v8::Context>(result->GetIsolate
(), | 98 result->context.reset(new v8::UniquePersistent<v8::Context>(result->GetIsolate
(), |
| 99 v8::Context::New(result->GetIsolate()))); | 99 v8::Context::New(result->GetIsolate()))); |
| 100 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( | 100 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( |
| 101 result->GetIsolate(), *result->context)->Global(); | 101 result->GetIsolate(), *result->context)->Global(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 | 249 |
| 250 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 250 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 251 AdblockPlus::JsValuePtr value) | 251 AdblockPlus::JsValuePtr value) |
| 252 { | 252 { |
| 253 if (!globalJsObject) | 253 if (!globalJsObject) |
| 254 throw std::runtime_error("Global object cannot be null"); | 254 throw std::runtime_error("Global object cannot be null"); |
| 255 | 255 |
| 256 globalJsObject->SetProperty(name, value); | 256 globalJsObject->SetProperty(name, value); |
| 257 } | 257 } |
| LEFT | RIGHT |