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

Unified Diff: src/FileSystemJsObject.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/FileSystemJsObject.cpp
===================================================================
--- a/src/FileSystemJsObject.cpp
+++ b/src/FileSystemJsObject.cpp
@@ -28,32 +28,32 @@
using namespace AdblockPlus;
namespace
{
class IoThread : public Thread
{
public:
- IoThread(JsEnginePtr jsEngine, JsValuePtr callback)
+ IoThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback)
: Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()),
callback(callback)
{
}
protected:
JsEnginePtr jsEngine;
FileSystemPtr fileSystem;
- JsValuePtr callback;
+ JsConstValuePtr callback;
};
class ReadThread : public IoThread
{
public:
- ReadThread(JsEnginePtr jsEngine, JsValuePtr callback,
+ ReadThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback,
const std::string& path)
: IoThread(jsEngine, callback), path(path)
{
}
void Run()
{
std::string content;
@@ -83,17 +83,17 @@
private:
std::string path;
};
class WriteThread : public IoThread
{
public:
- WriteThread(JsEnginePtr jsEngine, JsValuePtr callback,
+ WriteThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback,
const std::string& path, const std::string& content)
: IoThread(jsEngine, callback), path(path), content(content)
{
}
void Run()
{
std::string error;
@@ -122,17 +122,17 @@
private:
std::string path;
std::string content;
};
class MoveThread : public IoThread
{
public:
- MoveThread(JsEnginePtr jsEngine, JsValuePtr callback,
+ MoveThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback,
const std::string& fromPath, const std::string& toPath)
: IoThread(jsEngine, callback), fromPath(fromPath), toPath(toPath)
{
}
void Run()
{
std::string error;
@@ -159,17 +159,17 @@
private:
std::string fromPath;
std::string toPath;
};
class RemoveThread : public IoThread
{
public:
- RemoveThread(JsEnginePtr jsEngine, JsValuePtr callback,
+ RemoveThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback,
const std::string& path)
: IoThread(jsEngine, callback), path(path)
{
}
void Run()
{
std::string error;
@@ -196,17 +196,17 @@
private:
std::string path;
};
class StatThread : public IoThread
{
public:
- StatThread(JsEnginePtr jsEngine, JsValuePtr callback,
+ StatThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback,
const std::string& path)
: IoThread(jsEngine, callback), path(path)
{
}
void Run()
{
std::string error;
@@ -239,17 +239,17 @@
private:
std::string path;
};
v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 2)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.read requires 2 parameters"));
if (!converted[1]->IsFunction())
return v8::ThrowException(Utils::ToV8String(isolate,
"Second argument to _fileSystem.read must be a function"));
@@ -257,17 +257,17 @@
converted[0]->AsString());
readThread->Start();
return v8::Undefined();
}
v8::Handle<v8::Value> WriteCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 3)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.write requires 3 parameters"));
if (!converted[2]->IsFunction())
return v8::ThrowException(Utils::ToV8String(isolate,
"Third argument to _fileSystem.write must be a function"));
@@ -275,17 +275,17 @@
converted[0]->AsString(), converted[1]->AsString());
writeThread->Start();
return v8::Undefined();
}
v8::Handle<v8::Value> MoveCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 3)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.move requires 3 parameters"));
if (!converted[2]->IsFunction())
return v8::ThrowException(Utils::ToV8String(isolate,
"Third argument to _fileSystem.move must be a function"));
@@ -293,17 +293,17 @@
converted[0]->AsString(), converted[1]->AsString());
moveThread->Start();
return v8::Undefined();
}
v8::Handle<v8::Value> RemoveCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 2)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.remove requires 2 parameters"));
if (!converted[1]->IsFunction())
return v8::ThrowException(Utils::ToV8String(isolate,
"Second argument to _fileSystem.remove must be a function"));
@@ -311,17 +311,17 @@
converted[0]->AsString());
removeThread->Start();
return v8::Undefined();
}
v8::Handle<v8::Value> StatCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 2)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.stat requires 2 parameters"));
if (!converted[1]->IsFunction())
return v8::ThrowException(Utils::ToV8String(isolate,
"Second argument to _fileSystem.stat must be a function"));
@@ -329,33 +329,33 @@
converted[0]->AsString());
statThread->Start();
return v8::Undefined();
}
v8::Handle<v8::Value> ResolveCallback(const v8::Arguments& arguments)
{
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments);
v8::Isolate* isolate = arguments.GetIsolate();
if (converted.size() != 1)
return v8::ThrowException(Utils::ToV8String(isolate,
"_fileSystem.resolve requires 1 parameter"));
std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0]->AsString());
return Utils::ToV8String(isolate, resolved);
}
}
-JsValuePtr FileSystemJsObject::Setup(JsEngine& jsEngine, const JsValuePtr& obj)
+JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj)
{
- obj->SetProperty("read", jsEngine.NewCallback(::ReadCallback));
- obj->SetProperty("write", jsEngine.NewCallback(::WriteCallback));
- obj->SetProperty("move", jsEngine.NewCallback(::MoveCallback));
- obj->SetProperty("remove", jsEngine.NewCallback(::RemoveCallback));
- obj->SetProperty("stat", jsEngine.NewCallback(::StatCallback));
- obj->SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback));
+ obj.SetProperty("read", *jsEngine.NewCallback(::ReadCallback));
+ obj.SetProperty("write", *jsEngine.NewCallback(::WriteCallback));
+ obj.SetProperty("move", *jsEngine.NewCallback(::MoveCallback));
+ obj.SetProperty("remove", *jsEngine.NewCallback(::RemoveCallback));
+ obj.SetProperty("stat", *jsEngine.NewCallback(::StatCallback));
+ obj.SetProperty("resolve", *jsEngine.NewCallback(::ResolveCallback));
return obj;
}

Powered by Google App Engine
This is Rietveld