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

Unified Diff: src/GlobalJsObject.cpp

Issue 4949583905947648: Issue 1280 - Update v8, the second part (Closed)
Patch Set: Created Oct. 27, 2014, 10:01 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
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/GlobalJsObject.cpp
===================================================================
--- a/src/GlobalJsObject.cpp
+++ b/src/GlobalJsObject.cpp
@@ -27,6 +27,7 @@
#include "ConsoleJsObject.h"
#include "WebRequestJsObject.h"
#include "Thread.h"
+#include "Utils.h"
using namespace AdblockPlus;
@@ -63,54 +64,49 @@
JsValueList functionArguments;
};
- v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
+ void SetTimeoutCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
- TimeoutThread* timeoutThread;
+ auto isolate = info.GetIsolate();
try
{
- AdblockPlus::JsValueList converted =
- AdblockPlus::JsEngine::FromArguments(arguments)
- ->ConvertArguments(arguments);
- timeoutThread = new TimeoutThread(converted);
+ auto converted = AdblockPlus::JsEngine::FromArguments(info)->ConvertArguments(info);
+ TimeoutThread* timeoutThread = new TimeoutThread(converted);
+ timeoutThread->Start();
}
catch (const std::exception& e)
{
- return v8::ThrowException(v8::String::New(e.what()));
+ isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, e.what()));
}
- timeoutThread->Start();
// We should actually return the timer ID here, which could be
// used via clearTimeout(). But since we don't seem to need
// clearTimeout(), we can save that for later.
- return v8::Undefined();
}
- v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments)
+ void TriggerEventCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
- AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
- AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
+ auto isolate = v8::Isolate::GetCurrent();
+ AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(info);
+ AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info);
if (converted.size() < 1)
- return v8::ThrowException(v8::String::New("_triggerEvent expects at least one parameter"));
+ {
+ isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate,
+ "_triggerEvent expects at least one parameter"));
+ return;
+ }
std::string eventName = converted.front()->AsString();
converted.erase(converted.begin());
jsEngine->TriggerEvent(eventName, converted);
- return v8::Undefined();
}
}
-JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo,
- JsValuePtr obj)
+void GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, JsValue& obj)
{
- obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
- obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback));
- obj->SetProperty("_fileSystem",
- FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject()));
- obj->SetProperty("_webRequest",
- WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject()));
- obj->SetProperty("console",
- ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
- obj->SetProperty("_appInfo",
- AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
- return obj;
+ obj.SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
+ obj.SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback));
+ obj.SetProperty("_fileSystem", FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject()));
+ obj.SetProperty("_webRequest", WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject()));
+ obj.SetProperty("console", ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
+ obj.SetProperty("_appInfo", AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
}
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld