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

Unified Diff: src/JsEngine.cpp

Issue 29417605: Issue 5034 - Part 3: Create plain JsValue instead of JsValuePtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Pass JsEngine by ref Created April 20, 2017, 1:01 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/GlobalJsObject.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
@@ -111,20 +111,20 @@
jsEngine->CallTimerTask(timerTaskIterator);
});
}
void JsEngine::CallTimerTask(const TimerTasks::const_iterator& timerTaskIterator)
{
const JsContext context(shared_from_this());
JsValue callback(shared_from_this(), v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[0]));
- JsConstValueList callbackArgs;
+ JsValueList callbackArgs;
for (int i = 2; i < timerTaskIterator->arguments.size(); i++)
- callbackArgs.emplace_back(new JsValue(shared_from_this(),
- v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i])));
+ callbackArgs.emplace_back(JsValue(shared_from_this(),
+ v8::Local<v8::Value>::New(GetIsolate(), *timerTaskIterator->arguments[i])));
callback.Call(callbackArgs);
timerTasks.erase(timerTaskIterator);
}
AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer)
: isolate(isolate)
, fileSystem(new DefaultFileSystem())
, webRequest(new DefaultWebRequest())
@@ -182,17 +182,17 @@
}
void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName)
{
std::lock_guard<std::mutex> lock(eventCallbacksMutex);
eventCallbacks.erase(eventName);
}
-void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, const AdblockPlus::JsConstValueList& params)
+void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, const AdblockPlus::JsValueList& params)
{
EventCallback callback;
{
std::lock_guard<std::mutex> lock(eventCallbacksMutex);
auto it = eventCallbacks.find(eventName);
if (it == eventCallbacks.end())
return;
callback = it->second;
@@ -200,40 +200,38 @@
callback(params);
}
void AdblockPlus::JsEngine::Gc()
{
while (!v8::V8::IdleNotification());
}
-AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
+AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(const std::string& val)
{
const JsContext context(shared_from_this());
- return JsValuePtr(new JsValue(shared_from_this(),
- Utils::ToV8String(GetIsolate(), val)));
+ return JsValue(shared_from_this(), Utils::ToV8String(GetIsolate(), val));
}
-AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val)
+AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(int64_t val)
{
const JsContext context(shared_from_this());
- return JsValuePtr(new JsValue(shared_from_this(),
- v8::Number::New(GetIsolate(), val)));
+ return JsValue(shared_from_this(), v8::Number::New(GetIsolate(), val));
}
-AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val)
+AdblockPlus::JsValue AdblockPlus::JsEngine::NewValue(bool val)
{
const JsContext context(shared_from_this());
- return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val)));
+ return JsValue(shared_from_this(), v8::Boolean::New(val));
}
-AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject()
+AdblockPlus::JsValue AdblockPlus::JsEngine::NewObject()
{
const JsContext context(shared_from_this());
- return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New()));
+ return JsValue(shared_from_this(), v8::Object::New());
}
AdblockPlus::JsValue AdblockPlus::JsEngine::NewCallback(
const v8::InvocationCallback& callback)
{
const JsContext context(shared_from_this());
// Note: we are leaking this weak pointer, no obvious way to destroy it when
@@ -252,22 +250,22 @@
std::weak_ptr<JsEngine>* data =
static_cast<std::weak_ptr<JsEngine>*>(external->Value());
JsEnginePtr result = data->lock();
if (!result)
throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?");
return result;
}
-AdblockPlus::JsConstValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Arguments& arguments)
+AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Arguments& arguments)
{
const JsContext context(shared_from_this());
- JsConstValueList list;
+ JsValueList list;
for (int i = 0; i < arguments.Length(); i++)
- list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i])));
+ list.push_back(JsValue(shared_from_this(), arguments[i]));
return list;
}
AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const
{
return fileSystem;
}
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld