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

Unified Diff: src/WebRequestJsObject.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/WebRequestJsObject.cpp
===================================================================
--- a/src/WebRequestJsObject.cpp
+++ b/src/WebRequestJsObject.cpp
@@ -24,24 +24,24 @@
#include "Utils.h"
#include "WebRequestJsObject.h"
namespace
{
class WebRequestThread : public AdblockPlus::Thread
{
public:
- WebRequestThread(const AdblockPlus::JsEnginePtr& jsEngine, const AdblockPlus::JsValueList& arguments)
+ WebRequestThread(const AdblockPlus::JsEnginePtr& jsEngine, const AdblockPlus::JsConstValueList& arguments)
: Thread(true), jsEngine(jsEngine), url(arguments[0]->AsString())
{
if (!url.length())
throw std::runtime_error("Invalid string passed as first argument to GET");
{
- AdblockPlus::JsValuePtr headersObj = arguments[1];
+ AdblockPlus::JsConstValuePtr headersObj = arguments[1];
if (!headersObj->IsObject())
throw std::runtime_error("Second argument to GET must be an object");
std::vector<std::string> properties = headersObj->GetOwnPropertyNames();
for (const auto& header : properties)
{
std::string headerValue = headersObj->GetProperty(header)->AsString();
if (header.length() && headerValue.length())
@@ -74,50 +74,50 @@
resultObject->SetProperty("responseStatus", result.responseStatus);
resultObject->SetProperty("responseText", result.responseText);
AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject();
for (const auto& header : result.responseHeaders)
{
headersObject->SetProperty(header.first, header.second);
}
- resultObject->SetProperty("responseHeaders", headersObject);
+ resultObject->SetProperty("responseHeaders", *headersObject);
AdblockPlus::JsConstValueList params;
params.push_back(resultObject);
callback->Call(params);
}
private:
AdblockPlus::JsEnginePtr jsEngine;
std::string url;
AdblockPlus::HeaderList headers;
- AdblockPlus::JsValuePtr callback;
+ AdblockPlus::JsConstValuePtr callback;
};
v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments)
{
WebRequestThread* thread;
try
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
if (converted.size() != 3u)
throw std::runtime_error("GET requires exactly 3 arguments");
thread = new WebRequestThread(jsEngine, converted);
}
catch (const std::exception& e)
{
using AdblockPlus::Utils::ToV8String;
v8::Isolate* isolate = arguments.GetIsolate();
return v8::ThrowException(ToV8String(isolate, e.what()));
}
thread->Start();
return v8::Undefined();
}
}
-AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup(
- AdblockPlus::JsEngine& jsEngine, const AdblockPlus::JsValuePtr& obj)
+AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup(
+ AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj)
{
- obj->SetProperty("GET", jsEngine.NewCallback(::GETCallback));
+ obj.SetProperty("GET", *jsEngine.NewCallback(::GETCallback));
return obj;
}
« src/FilterEngine.cpp ('K') | « src/WebRequestJsObject.h ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld