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

Unified Diff: src/JsEngine.cpp

Issue 29409580: Issue 5013 - Make parameter const ref when applicable. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebased Created April 12, 2017, 8:49 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
===================================================================
--- a/src/JsEngine.cpp
+++ b/src/JsEngine.cpp
@@ -107,17 +107,17 @@
std::weak_ptr<JsEngine> weakJsEngine = jsEngine;
jsEngine->timer->SetTimer(std::chrono::milliseconds(arguments[1]->IntegerValue()), [weakJsEngine, timerTaskIterator]
{
if (auto jsEngine = weakJsEngine.lock())
jsEngine->CallTimerTask(timerTaskIterator);
});
}
-void JsEngine::CallTimerTask(TimerTasks::const_iterator 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;
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])));
callback.Call(callbackArgs);
@@ -140,17 +140,17 @@
JsEnginePtr result(new JsEngine(isolate, std::move(timer)));
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->GetIsolate(),
v8::Context::New(result->GetIsolate())));
- AdblockPlus::GlobalJsObject::Setup(result, appInfo, result->GetGlobalObject());
+ AdblockPlus::GlobalJsObject::Setup(*result, appInfo, result->GetGlobalObject());
return result;
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalObject()
{
JsContext context(shared_from_this());
return JsValuePtr(new JsValue(shared_from_this(), context.GetV8Context()->Global()));
}
@@ -164,34 +164,34 @@
filename);
CheckTryCatch(tryCatch);
v8::Local<v8::Value> result = script->Run();
CheckTryCatch(tryCatch);
return JsValuePtr(new JsValue(shared_from_this(), result));
}
void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
- AdblockPlus::JsEngine::EventCallback callback)
+ const AdblockPlus::JsEngine::EventCallback& callback)
{
if (!callback)
{
RemoveEventCallback(eventName);
return;
}
std::lock_guard<std::mutex> lock(eventCallbacksMutex);
eventCallbacks[eventName] = callback;
}
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, AdblockPlus::JsValueList& 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;
@@ -226,17 +226,17 @@
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject()
{
const JsContext context(shared_from_this());
return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New()));
}
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback(
- v8::InvocationCallback callback)
+ const v8::InvocationCallback& callback)
{
const JsContext context(shared_from_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,
@@ -265,30 +265,30 @@
return list;
}
AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const
{
return fileSystem;
}
-void AdblockPlus::JsEngine::SetFileSystem(AdblockPlus::FileSystemPtr val)
+void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemPtr& val)
{
if (!val)
throw std::runtime_error("FileSystem cannot be null");
fileSystem = val;
}
AdblockPlus::WebRequestPtr AdblockPlus::JsEngine::GetWebRequest() const
{
return webRequest;
}
-void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val)
+void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestPtr& val)
{
if (!val)
throw std::runtime_error("WebRequest cannot be null");
webRequest = val;
}
void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callback)
@@ -311,25 +311,25 @@
return !localCopy || localCopy();
}
AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const
{
return logSystem;
}
-void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
+void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val)
{
if (!val)
throw std::runtime_error("LogSystem cannot be null");
logSystem = val;
}
void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
- AdblockPlus::JsValuePtr value)
+ const AdblockPlus::JsValuePtr& value)
{
auto global = GetGlobalObject();
if (!global)
throw std::runtime_error("Global object cannot be null");
global->SetProperty(name, value);
}

Powered by Google App Engine
This is Rietveld