Left: | ||
Right: |
OLD | NEW |
---|---|
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-2015 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 public: | 58 public: |
59 static void Init() | 59 static void Init() |
60 { | 60 { |
61 // it's threadsafe since C++11 and it will be instantiated only once and | 61 // it's threadsafe since C++11 and it will be instantiated only once and |
62 // destroyed at the application exit | 62 // destroyed at the application exit |
63 static V8Initializer initializer; | 63 static V8Initializer initializer; |
64 } | 64 } |
65 }; | 65 }; |
66 } | 66 } |
67 | 67 |
68 AdblockPlus::JsEngine::JsEngine() | 68 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
69 : isolate(v8::Isolate::GetCurrent()) | 69 : isolate(v8::Isolate::New()) |
Eric
2015/08/05 22:29:16
This is changing the behavior non-trivially, since
sergei
2015/11/16 16:52:09
There is no any default isolate. It `v8::Isolate::
Eric
2015/11/17 21:27:43
Sure there is. See isolate.cc:340
Isolate* Iso
| |
70 { | 70 { |
71 } | 71 } |
72 | 72 |
73 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() | |
74 { | |
75 isolate->Dispose(); | |
Eric
2015/08/05 22:29:16
If we initialize with 'New()' rather than 'GetCurr
sergei
2015/11/16 16:52:09
Do you mean we should create a typedef on `std::sh
Eric
2015/11/17 21:27:43
No.
| |
76 isolate = nullptr; | |
77 } | |
78 | |
79 AdblockPlus::JsEngine::JsEngine() | |
80 { | |
81 } | |
82 | |
73 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) | 83 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) |
74 { | 84 { |
75 V8Initializer::Init(); | 85 V8Initializer::Init(); |
76 JsEnginePtr result(new JsEngine()); | 86 JsEnginePtr result(new JsEngine()); |
77 | 87 |
78 const v8::Locker locker(result->isolate); | 88 const v8::Locker locker(result->isolate); |
79 const v8::HandleScope handleScope; | 89 const v8::Isolate::Scope isolateScope(result->isolate); |
90 const v8::HandleScope handleScope(result->isolate); | |
80 | 91 |
81 result->context.reset(result->isolate, v8::Context::New(result->isolate)); | 92 result->context.reset(result->isolate, v8::Context::New(result->isolate)); |
82 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( | 93 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( |
83 result->isolate, result->context)->Global(); | 94 result->isolate, result->context)->Global(); |
84 AdblockPlus::GlobalJsObject::Setup(result, appInfo, | 95 AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
85 JsValuePtr(new JsValue(result, globalContext))); | 96 JsValuePtr(new JsValue(result, globalContext))); |
86 return result; | 97 return result; |
87 } | 98 } |
88 | 99 |
89 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, | 100 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 return logSystem; | 231 return logSystem; |
221 } | 232 } |
222 | 233 |
223 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) | 234 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) |
224 { | 235 { |
225 if (!val) | 236 if (!val) |
226 throw std::runtime_error("LogSystem cannot be null"); | 237 throw std::runtime_error("LogSystem cannot be null"); |
227 | 238 |
228 logSystem = val; | 239 logSystem = val; |
229 } | 240 } |
OLD | NEW |