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

Unified Diff: src/JsEngine.cpp

Issue 29527588: Issue 5570 - Make V8 isolate injectable into JsEngine (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 25, 2017, 8:32 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
Index: src/JsEngine.cpp
diff --git a/src/JsEngine.cpp b/src/JsEngine.cpp
index f0d022dc8688f13f857e56fd508bf1d5a454662a..090efb57be687ce86cca66aad9da60d2b52ae846 100644
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -72,24 +72,42 @@ namespace
static V8Initializer initializer;
}
};
-}
-using namespace AdblockPlus;
+ /**
+ * Scope based isolate manager. Creates a new isolate instance on
+ * constructing and disposes it on destructing. In addition it initilizes V8.
+ */
+ class ScopedV8Isolate : public AdblockPlus::IV8IsolateProvider
+ {
+ public:
+ ScopedV8Isolate()
+ {
+ V8Initializer::Init();
+ v8::Isolate::CreateParams isolateParams;
+ isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
+ isolate = v8::Isolate::New(isolateParams);
+ }
-AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
-{
- V8Initializer::Init();
- v8::Isolate::CreateParams isolateParams;
- isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
- isolate = v8::Isolate::New(isolateParams);
-}
+ ~ScopedV8Isolate()
+ {
+ isolate->Dispose();
+ isolate = nullptr;
+ }
-AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate()
-{
- isolate->Dispose();
- isolate = nullptr;
+ v8::Isolate* Get() override
+ {
+ return isolate;
+ }
+ private:
+ ScopedV8Isolate(const ScopedV8Isolate&);
+ ScopedV8Isolate& operator=(const ScopedV8Isolate&);
+
+ v8::Isolate* isolate;
+ };
}
+using namespace AdblockPlus;
+
JsEngine::JsWeakValuesList::~JsWeakValuesList()
{
}
@@ -130,15 +148,20 @@ void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID)
callback.Call(timerParams);
}
-AdblockPlus::JsEngine::JsEngine(Platform& platform)
+AdblockPlus::JsEngine::JsEngine(Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate)
: platform(platform)
+ , isolate(std::move(isolate))
{
}
AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo,
- Platform& platform)
+ Platform& platform, std::unique_ptr<IV8IsolateProvider> isolate)
{
- JsEnginePtr result(new JsEngine(platform));
+ if (!isolate)
+ {
+ isolate.reset(new ScopedV8Isolate());
+ }
+ JsEnginePtr result(new JsEngine(platform, std::move(isolate)));
const v8::Locker locker(result->GetIsolate());
const v8::Isolate::Scope isolateScope(result->GetIsolate());

Powered by Google App Engine
This is Rietveld