Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 23 matching lines...) Expand all Loading... | |
34 } | 34 } |
35 else | 35 else |
36 return v8::Script::Compile(v8Source); | 36 return v8::Script::Compile(v8Source); |
37 } | 37 } |
38 | 38 |
39 void CheckTryCatch(const v8::TryCatch& tryCatch) | 39 void CheckTryCatch(const v8::TryCatch& tryCatch) |
40 { | 40 { |
41 if (tryCatch.HasCaught()) | 41 if (tryCatch.HasCaught()) |
42 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); | 42 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); |
43 } | 43 } |
44 | |
45 class V8Initializer | |
46 { | |
47 V8Initializer() | |
48 { | |
49 v8::V8::Initialize(); | |
50 } | |
51 | |
52 ~V8Initializer() | |
53 { | |
54 v8::V8::Dispose(); | |
55 } | |
56 public: | |
57 static void Init() | |
58 { | |
59 // it's threadsafe since C++11 and it will be instantiated only once and | |
60 // destroyed at the application exit | |
61 static V8Initializer initializer; | |
62 } | |
Wladimir Palant
2014/11/11 20:55:40
Wouldn't it make more sense (meaning more obvious
sergei
2014/11/12 10:11:32
Nit: I am not sure whether the linker can optimize
Wladimir Palant
2014/11/12 10:18:36
Yes, order of initialization is something I wasn't
| |
63 }; | |
44 } | 64 } |
45 | 65 |
46 AdblockPlus::JsEngine::JsEngine() | 66 AdblockPlus::JsEngine::JsEngine() |
47 : isolate(v8::Isolate::GetCurrent()) | 67 : isolate(v8::Isolate::GetCurrent()) |
48 { | 68 { |
49 } | 69 } |
50 | 70 |
51 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) | 71 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) |
52 { | 72 { |
73 V8Initializer::Init(); | |
53 JsEnginePtr result(new JsEngine()); | 74 JsEnginePtr result(new JsEngine()); |
54 | 75 |
55 const v8::Locker locker(result->isolate); | 76 const v8::Locker locker(result->isolate); |
56 const v8::HandleScope handleScope; | 77 const v8::HandleScope handleScope; |
57 | 78 |
58 result->context.reset(result->isolate, v8::Context::New(result->isolate)); | 79 result->context.reset(result->isolate, v8::Context::New(result->isolate)); |
59 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( | 80 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( |
60 result->isolate, result->context)->Global(); | 81 result->isolate, result->context)->Global(); |
61 AdblockPlus::GlobalJsObject::Setup(result, appInfo, | 82 AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
62 JsValuePtr(new JsValue(result, globalContext))); | 83 JsValuePtr(new JsValue(result, globalContext))); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 return logSystem; | 216 return logSystem; |
196 } | 217 } |
197 | 218 |
198 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) | 219 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) |
199 { | 220 { |
200 if (!val) | 221 if (!val) |
201 throw std::runtime_error("LogSystem cannot be null"); | 222 throw std::runtime_error("LogSystem cannot be null"); |
202 | 223 |
203 logSystem = val; | 224 logSystem = val; |
204 } | 225 } |
OLD | NEW |