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

Unified Diff: src/JsEngine.cpp

Issue 6233220328718336: Issue #3593, #1197- fix isolate management (Closed)
Patch Set: rebase fix v8 initialization Created May 20, 2016, 3:22 p.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 | « src/JsContext.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/JsEngine.cpp
diff --git a/src/JsEngine.cpp b/src/JsEngine.cpp
index 73a786a9dddd2b2da8b5483d48bda35c613ecb25..4b6de5c029ac4909dc4c6000510d3cb52d9df7f4 100644
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -16,7 +16,6 @@
*/
#include <AdblockPlus.h>
-
#include "GlobalJsObject.h"
#include "JsContext.h"
#include "JsError.h"
@@ -65,23 +64,35 @@ namespace
};
}
-AdblockPlus::JsEngine::JsEngine()
- : isolate(v8::Isolate::GetCurrent())
+AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
{
+ V8Initializer::Init();
+ isolate = v8::Isolate::New();
}
-AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo)
+AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate()
{
- V8Initializer::Init();
- JsEnginePtr result(new JsEngine());
+ isolate->Dispose();
+ isolate = nullptr;
+}
+
+AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate)
+ : isolate(isolate)
+{
+}
+
+AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, const ScopedV8IsolatePtr& isolate)
+{
+ JsEnginePtr result(new JsEngine(isolate));
- const v8::Locker locker(result->isolate);
- const v8::HandleScope handleScope;
+ const v8::Locker locker(result->GetIsolate());
+ const v8::Isolate::Scope isolateScope(result->GetIsolate());
+ const v8::HandleScope handleScope(result->GetIsolate());
- result->context.reset(new v8::Persistent<v8::Context>(result->isolate,
- v8::Context::New(result->isolate)));
+ result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(),
+ v8::Context::New(result->GetIsolate())));
v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New(
- result->isolate, *result->context)->Global();
+ result->GetIsolate(), *result->context)->Global();
result->globalJsObject = JsValuePtr(new JsValue(result, globalContext));
AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->globalJsObject);
return result;
@@ -92,7 +103,7 @@ AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc
{
const JsContext context(shared_from_this());
const v8::TryCatch tryCatch;
- const v8::Handle<v8::Script> script = CompileScript(isolate, source,
+ const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source,
filename);
CheckTryCatch(tryCatch);
v8::Local<v8::Value> result = script->Run();
@@ -127,14 +138,14 @@ AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
{
const JsContext context(shared_from_this());
return JsValuePtr(new JsValue(shared_from_this(),
- Utils::ToV8String(isolate, val)));
+ Utils::ToV8String(GetIsolate(), val)));
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val)
{
const JsContext context(shared_from_this());
return JsValuePtr(new JsValue(shared_from_this(),
- v8::Number::New(isolate, val)));
+ v8::Number::New(GetIsolate(), val)));
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val)
« no previous file with comments | « src/JsContext.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld