Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -41,6 +41,26 @@ |
if (tryCatch.HasCaught()) |
throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); |
} |
+ |
+ class V8Initializer |
+ { |
+ V8Initializer() |
+ { |
+ v8::V8::Initialize(); |
+ } |
+ |
+ ~V8Initializer() |
+ { |
+ v8::V8::Dispose(); |
+ } |
+ public: |
+ static void Init() |
+ { |
+ // it's threadsafe since C++11 and it will be instantiated only once and |
+ // destroyed at the application exit |
+ static V8Initializer initializer; |
+ } |
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
|
+ }; |
} |
AdblockPlus::JsEngine::JsEngine() |
@@ -50,6 +70,7 @@ |
AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) |
{ |
+ V8Initializer::Init(); |
JsEnginePtr result(new JsEngine()); |
const v8::Locker locker(result->isolate); |