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

Unified Diff: src/JsEngine.cpp

Issue 29418664: Issue 5162 - JsContext() takes a JsEngine& (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 20, 2017, 7:53 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
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -109,17 +109,17 @@
{
if (auto jsEngine = weakJsEngine.lock())
jsEngine->CallTimerTask(timerTaskIterator);
});
}
void JsEngine::CallTimerTask(const TimerTasks::const_iterator& timerTaskIterator)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
JsValue callback(shared_from_this(), v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[0]));
JsValueList callbackArgs;
for (int i = 2; i < timerTaskIterator->arguments.size(); i++)
callbackArgs.emplace_back(JsValue(shared_from_this(),
v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i])));
callback.Call(callbackArgs);
timerTasks.erase(timerTaskIterator);
}
@@ -147,24 +147,24 @@
v8::Context::New(result->GetIsolate())));
auto global = result->GetGlobalObject();
AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global);
return result;
}
AdblockPlus::JsValue AdblockPlus::JsEngine::GetGlobalObject()
{
- JsContext context(shared_from_this());
+ JsContext context(*this);
return JsValue(shared_from_this(), context.GetV8Context()->Global());
}
AdblockPlus::JsValue AdblockPlus::JsEngine::Evaluate(const std::string& source,
const std::string& filename)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
const v8::TryCatch tryCatch;
const v8::Handle<v8::Script> script = CompileScript(GetIsolate(), source,
filename);
CheckTryCatch(tryCatch);
v8::Local<v8::Value> result = script->Run();
CheckTryCatch(tryCatch);
return JsValue(shared_from_this(), result);
}
@@ -202,42 +202,42 @@
void AdblockPlus::JsEngine::Gc()
{
while (!v8::V8::IdleNotification());
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
return JsValue(shared_from_this(), Utils::ToV8String(GetIsolate(), val));
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val));
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
return JsValue(shared_from_this(), v8::Boolean::New(val));
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewObject()
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
return JsValue(shared_from_this(), v8::Object::New());
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback(
const v8::InvocationCallback& callback)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
// Note: we are leaking this weak pointer, no obvious way to destroy it when
// it's no longer used
std::weak_ptr<JsEngine>* data =
new std::weak_ptr<JsEngine>(shared_from_this());
v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback,
v8::External::New(data));
return JsValue(shared_from_this(), templ->GetFunction());
@@ -252,17 +252,17 @@
JsEnginePtr result = data->lock();
if (!result)
throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?");
return result;
}
AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Arguments& arguments)
{
- const JsContext context(shared_from_this());
+ const JsContext context(*this);
JsValueList list;
for (int i = 0; i < arguments.Length(); i++)
list.push_back(JsValue(shared_from_this(), arguments[i]));
return list;
}
AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const
{
« 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