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

Unified Diff: src/FilterEngine.cpp

Issue 29410664: Issue 5013 - Use const JsValue and pass reference where applicable (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 12, 2017, 3:24 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/FilterEngine.cpp
===================================================================
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -168,17 +168,17 @@
auto sync = std::make_shared<Sync>();
auto isConnectionAllowedCallback = params.isConnectionAllowedCallback;
if (isConnectionAllowedCallback)
jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool
{
sync->Wait();
return jsEngine->IsConnectionAllowed();
});
- jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](const JsValueList& params)
+ jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowedCallback](const JsConstValueList& params)
{
filterEngine->firstRun = params.size() && params[0]->AsBool();
if (isConnectionAllowedCallback)
{
std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAllowedCallback]()->bool
{
auto filterEngine = weakFilterEngine.lock();
@@ -196,19 +196,19 @@
// until we are done.
const JsContext context(jsEngine);
// Set the preconfigured prefs
JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject();
for (FilterEngine::Prefs::const_iterator it = params.preconfiguredPrefs.begin();
it != params.preconfiguredPrefs.end(); it++)
{
- preconfiguredPrefsObject->SetProperty(it->first, it->second);
+ preconfiguredPrefsObject->SetProperty(it->first, *it->second);
}
- jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject);
+ jsEngine->SetGlobalProperty("_preconfiguredPrefs", *preconfiguredPrefsObject);
// Load adblockplus scripts
for (int i = 0; !jsSources[i].empty(); i += 2)
jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
}
FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine,
const FilterEngine::CreationParameters& params)
{
@@ -457,17 +457,17 @@
}
void FilterEngine::RemoveUpdateAvailableCallback()
{
jsEngine->RemoveEventCallback("updateAvailable");
}
void FilterEngine::UpdateAvailable(
- const FilterEngine::UpdateAvailableCallback& callback, const JsValueList& params) const
+ const FilterEngine::UpdateAvailableCallback& callback, const JsConstValueList& params) const
{
if (params.size() >= 1 && !params[0]->IsNull())
callback(params[0]->AsString());
}
void FilterEngine::ForceUpdateCheck(
const FilterEngine::UpdateCheckDoneCallback& callback)
{
@@ -479,17 +479,17 @@
jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone,
this, eventName, callback, std::placeholders::_1));
params.push_back(jsEngine->NewValue(eventName));
}
func->Call(params);
}
void FilterEngine::UpdateCheckDone(const std::string& eventName,
- const FilterEngine::UpdateCheckDoneCallback& callback, const JsValueList& params)
+ const FilterEngine::UpdateCheckDoneCallback& callback, const JsConstValueList& params)
{
jsEngine->RemoveEventCallback(eventName);
std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
callback(error);
}
void FilterEngine::SetFilterChangeCallback(const FilterEngine::FilterChangeCallback& callback)
@@ -511,34 +511,34 @@
std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const
{
auto prefValue = GetPref("allowed_connection_type");
if (prefValue->AsString().empty())
return nullptr;
return std::unique_ptr<std::string>(new std::string(prefValue->AsString()));
}
-void FilterEngine::FilterChanged(const FilterEngine::FilterChangeCallback& callback, const JsValueList& params) const
+void FilterEngine::FilterChanged(const FilterEngine::FilterChangeCallback& callback, const JsConstValueList& params) const
{
std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
- JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
+ JsConstValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
callback(action, *item);
}
void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
- const JsValueList& params) const
+ const JsConstValueList& params) const
{
if (params.size() < 1)
return;
if (!params[0]->IsObject())
{
return;
}
- callback(NotificationPtr(new Notification(std::move(*params[0]))));
+ callback(NotificationPtr(new Notification(params[0]->Clone())));
hub 2017/04/12 15:28:20 This is the tricky part. Before that patch we rece
}
int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) const
{
JsConstValueList params;
params.push_back(jsEngine->NewValue(v1));
params.push_back(jsEngine->NewValue(v2));

Powered by Google App Engine
This is Rietveld