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(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback) |
+ IoThread(const JsEnginePtr& jsEngine, const JsValue& callback) |
: Thread(true), jsEngine(jsEngine), fileSystem(jsEngine->GetFileSystem()), |
callback(callback) |
{ |
} |
protected: |
JsEnginePtr jsEngine; |
FileSystemPtr fileSystem; |
- JsConstValuePtr callback; |
+ JsValue callback; |
}; |
class ReadThread : public IoThread |
{ |
public: |
- ReadThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback, |
+ ReadThread(const JsEnginePtr& jsEngine, const JsValue& callback, |
const std::string& path) |
: IoThread(jsEngine, callback), path(path) |
{ |
} |
void Run() |
{ |
std::string content; |
@@ -68,32 +68,32 @@ |
error = e.what(); |
} |
catch (...) |
{ |
error = "Unknown error while reading from " + path; |
} |
const JsContext context(jsEngine); |
- JsValuePtr result = jsEngine->NewObject(); |
- result->SetProperty("content", content); |
- result->SetProperty("error", error); |
- JsConstValueList params; |
+ auto result = jsEngine->NewObject(); |
+ result.SetProperty("content", content); |
+ result.SetProperty("error", error); |
+ JsValueList params; |
params.push_back(result); |
- callback->Call(params); |
+ callback.Call(params); |
} |
private: |
std::string path; |
}; |
class WriteThread : public IoThread |
{ |
public: |
- WriteThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback, |
+ WriteThread(const JsEnginePtr& jsEngine, const JsValue& callback, |
const std::string& path, const std::string& content) |
: IoThread(jsEngine, callback), path(path), content(content) |
{ |
} |
void Run() |
{ |
std::string error; |
@@ -108,31 +108,31 @@ |
error = e.what(); |
} |
catch (...) |
{ |
error = "Unknown error while writing to " + path; |
} |
const JsContext context(jsEngine); |
- JsValuePtr errorValue = jsEngine->NewValue(error); |
- JsConstValueList params; |
+ auto errorValue = jsEngine->NewValue(error); |
+ JsValueList params; |
params.push_back(errorValue); |
- callback->Call(params); |
+ callback.Call(params); |
} |
private: |
std::string path; |
std::string content; |
}; |
class MoveThread : public IoThread |
{ |
public: |
- MoveThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback, |
+ MoveThread(const JsEnginePtr& jsEngine, const JsValue& callback, |
const std::string& fromPath, const std::string& toPath) |
: IoThread(jsEngine, callback), fromPath(fromPath), toPath(toPath) |
{ |
} |
void Run() |
{ |
std::string error; |
@@ -145,31 +145,31 @@ |
error = e.what(); |
} |
catch (...) |
{ |
error = "Unknown error while moving " + fromPath + " to " + toPath; |
} |
const JsContext context(jsEngine); |
- JsValuePtr errorValue = jsEngine->NewValue(error); |
- JsConstValueList params; |
+ auto errorValue = jsEngine->NewValue(error); |
+ JsValueList params; |
params.push_back(errorValue); |
- callback->Call(params); |
+ callback.Call(params); |
} |
private: |
std::string fromPath; |
std::string toPath; |
}; |
class RemoveThread : public IoThread |
{ |
public: |
- RemoveThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback, |
+ RemoveThread(const JsEnginePtr& jsEngine, const JsValue& callback, |
const std::string& path) |
: IoThread(jsEngine, callback), path(path) |
{ |
} |
void Run() |
{ |
std::string error; |
@@ -182,31 +182,31 @@ |
error = e.what(); |
} |
catch (...) |
{ |
error = "Unknown error while removing " + path; |
} |
const JsContext context(jsEngine); |
- JsValuePtr errorValue = jsEngine->NewValue(error); |
- JsConstValueList params; |
+ auto errorValue = jsEngine->NewValue(error); |
+ JsValueList params; |
params.push_back(errorValue); |
- callback->Call(params); |
+ callback.Call(params); |
} |
private: |
std::string path; |
}; |
class StatThread : public IoThread |
{ |
public: |
- StatThread(const JsEnginePtr& jsEngine, const JsConstValuePtr& callback, |
+ StatThread(const JsEnginePtr& jsEngine, const JsValue& callback, |
const std::string& path) |
: IoThread(jsEngine, callback), path(path) |
{ |
} |
void Run() |
{ |
std::string error; |
@@ -220,133 +220,133 @@ |
error = e.what(); |
} |
catch (...) |
{ |
error = "Unknown error while calling stat on " + path; |
} |
const JsContext context(jsEngine); |
- JsValuePtr result = jsEngine->NewObject(); |
- result->SetProperty("exists", statResult.exists); |
- result->SetProperty("isFile", statResult.isFile); |
- result->SetProperty("isDirectory", statResult.isDirectory); |
- result->SetProperty("lastModified", statResult.lastModified); |
- result->SetProperty("error", error); |
+ auto result = jsEngine->NewObject(); |
+ result.SetProperty("exists", statResult.exists); |
+ result.SetProperty("isFile", statResult.isFile); |
+ result.SetProperty("isDirectory", statResult.isDirectory); |
+ result.SetProperty("lastModified", statResult.lastModified); |
+ result.SetProperty("error", error); |
- JsConstValueList params; |
+ JsValueList params; |
params.push_back(result); |
- callback->Call(params); |
+ callback.Call(params); |
} |
private: |
std::string path; |
}; |
v8::Handle<v8::Value> ReadCallback(const v8::Arguments& arguments) |
{ |
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); |
- AdblockPlus::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()) |
+ if (!converted[1].IsFunction()) |
return v8::ThrowException(Utils::ToV8String(isolate, |
"Second argument to _fileSystem.read must be a function")); |
ReadThread* const readThread = new ReadThread(jsEngine, converted[1], |
- converted[0]->AsString()); |
+ 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::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()) |
+ if (!converted[2].IsFunction()) |
return v8::ThrowException(Utils::ToV8String(isolate, |
"Third argument to _fileSystem.write must be a function")); |
WriteThread* const writeThread = new WriteThread(jsEngine, converted[2], |
- converted[0]->AsString(), converted[1]->AsString()); |
+ 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::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()) |
+ if (!converted[2].IsFunction()) |
return v8::ThrowException(Utils::ToV8String(isolate, |
"Third argument to _fileSystem.move must be a function")); |
MoveThread* const moveThread = new MoveThread(jsEngine, converted[2], |
- converted[0]->AsString(), converted[1]->AsString()); |
+ 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::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()) |
+ if (!converted[1].IsFunction()) |
return v8::ThrowException(Utils::ToV8String(isolate, |
"Second argument to _fileSystem.remove must be a function")); |
RemoveThread* const removeThread = new RemoveThread(jsEngine, converted[1], |
- converted[0]->AsString()); |
+ 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::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()) |
+ if (!converted[1].IsFunction()) |
return v8::ThrowException(Utils::ToV8String(isolate, |
"Second argument to _fileSystem.stat must be a function")); |
StatThread* const statThread = new StatThread(jsEngine, converted[1], |
- converted[0]->AsString()); |
+ 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::JsConstValueList converted = jsEngine->ConvertArguments(arguments); |
+ AdblockPlus::JsValueList 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()); |
+ std::string resolved = jsEngine->GetFileSystem()->Resolve(converted[0].AsString()); |
return Utils::ToV8String(isolate, resolved); |
} |
} |
JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) |