Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/JsEngine.cpp

Issue 4978827532959744: Issue 1549 - initialize v8::V8 (Closed)
Patch Set: Created Nov. 10, 2014, 9:36 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld