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

Unified Diff: src/JsEngine.cpp

Issue 10190024: Use our own isolate instead of the default one (Closed)
Patch Set: Created April 17, 2013, 1:44 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
Index: src/JsEngine.cpp
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -6,16 +6,17 @@
namespace
{
v8::Handle<v8::Context> CreateContext(
v8::Isolate* isolate,
AdblockPlus::JsEngine& jsEngine)
{
const v8::Locker locker(isolate);
+ AdblockPlus::JsEngine::IsolateSetter isolateSetter(isolate);
const v8::HandleScope handleScope;
return v8::Context::New(0, AdblockPlus::GlobalJsObject::Create(jsEngine));
}
v8::Local<v8::Script> CompileScript(const std::string& source, const std::string& filename)
{
const v8::Local<v8::String> v8Source = AdblockPlus::Utils::ToV8String(source);
if (filename.length())
@@ -54,17 +55,17 @@ AdblockPlus::JsError::JsError(const v8::
: std::runtime_error(ExceptionToString(exception, message))
{
}
AdblockPlus::JsEngine::JsEngine(FileSystem* const fileSystem,
WebRequest* const webRequest,
ErrorCallback* const errorCallback)
: fileSystem(*fileSystem), webRequest(*webRequest),
- errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()),
+ errorCallback(*errorCallback), isolate(v8::Isolate::New()),
context(CreateContext(isolate, *this))
{
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
const Context context(*this);
@@ -125,12 +126,23 @@ AdblockPlus::JsValueList AdblockPlus::Js
const Context context(*this);
JsValueList list;
for (int i = 0; i < arguments.Length(); i++)
list.push_back(JsValuePtr(new JsValue(*this, arguments[i])));
return list;
}
AdblockPlus::JsEngine::Context::Context(const JsEngine& jsEngine)
- : locker(jsEngine.isolate), handleScope(),
+ : locker(jsEngine.isolate), isolateSetter(jsEngine.isolate), handleScope(),
contextScope(jsEngine.context)
{
}
+
+AdblockPlus::JsEngine::IsolateSetter::IsolateSetter(v8::Isolate* isolate)
+ : isolate(isolate)
+{
+ isolate->Enter();
+}
+
+AdblockPlus::JsEngine::IsolateSetter::~IsolateSetter()
+{
+ isolate->Exit();
+}

Powered by Google App Engine
This is Rietveld