| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 function->Call(functionArguments); | 58 function->Call(functionArguments); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 JsValuePtr function; | 62 JsValuePtr function; |
| 63 int delay; | 63 int delay; |
| 64 JsValueList functionArguments; | 64 JsValueList functionArguments; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) | 67 void SetTimeoutCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) |
| 68 { | 68 { |
| 69 TimeoutThread* timeoutThread; | 69 TimeoutThread* timeoutThread; |
| 70 try | 70 try |
| 71 { | 71 { |
| 72 AdblockPlus::JsValueList converted = | 72 AdblockPlus::JsValueList converted = |
| 73 AdblockPlus::JsEngine::FromArguments(arguments) | 73 AdblockPlus::JsEngine::FromArguments(arguments) |
| 74 ->ConvertArguments(arguments); | 74 ->ConvertArguments(arguments); |
| 75 timeoutThread = new TimeoutThread(converted); | 75 timeoutThread = new TimeoutThread(converted); |
| 76 } | 76 } |
| 77 catch (const std::exception& e) | 77 catch (const std::exception& e) |
| 78 { | 78 { |
| 79 v8::Isolate* isolate = arguments.GetIsolate(); | 79 v8::Isolate* isolate = arguments.GetIsolate(); |
| 80 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); | 80 return Utils::ThrowException(isolate, e.what()); |
| 81 } | 81 } |
| 82 timeoutThread->Start(); | 82 timeoutThread->Start(); |
| 83 | 83 |
| 84 // We should actually return the timer ID here, which could be | 84 // We should actually return the timer ID here, which could be |
| 85 // used via clearTimeout(). But since we don't seem to need | 85 // used via clearTimeout(). But since we don't seem to need |
| 86 // clearTimeout(), we can save that for later. | 86 // clearTimeout(), we can save that for later. |
| 87 return v8::Undefined(); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) | 89 void TriggerEventCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments
) |
| 91 { | 90 { |
| 92 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 91 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); |
| 93 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 92 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); |
| 94 if (converted.size() < 1) | 93 if (converted.size() < 1) |
| 95 { | 94 { |
| 96 v8::Isolate* isolate = arguments.GetIsolate(); | 95 v8::Isolate* isolate = arguments.GetIsolate(); |
| 97 return v8::ThrowException(Utils::ToV8String(isolate, | 96 return Utils::ThrowException(isolate, "_triggerEvent expects at least one
parameter"); |
| 98 "_triggerEvent expects at least one parameter")); | |
| 99 } | 97 } |
| 100 std::string eventName = converted.front()->AsString(); | 98 std::string eventName = converted.front()->AsString(); |
| 101 converted.erase(converted.begin()); | 99 converted.erase(converted.begin()); |
| 102 jsEngine->TriggerEvent(eventName, converted); | 100 jsEngine->TriggerEvent(eventName, converted); |
| 103 return v8::Undefined(); | |
| 104 } | 101 } |
| 105 } | 102 } |
| 106 | 103 |
| 107 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, | 104 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, |
| 108 JsValuePtr obj) | 105 JsValuePtr obj) |
| 109 { | 106 { |
| 110 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); | 107 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); |
| 111 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback
)); | 108 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback
)); |
| 112 obj->SetProperty("_fileSystem", | 109 obj->SetProperty("_fileSystem", |
| 113 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); | 110 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 114 obj->SetProperty("_webRequest", | 111 obj->SetProperty("_webRequest", |
| 115 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); | 112 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 116 obj->SetProperty("console", | 113 obj->SetProperty("console", |
| 117 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); | 114 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 118 obj->SetProperty("_appInfo", | 115 obj->SetProperty("_appInfo", |
| 119 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); | 116 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); |
| 120 return obj; | 117 return obj; |
| 121 } | 118 } |
| OLD | NEW |