Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) |
68 { | 68 { |
69 TimeoutThread* timeoutThread; | 69 TimeoutThread* timeoutThread; |
70 | |
Felix Dahlke
2015/02/06 04:17:27
Unrelated change.
| |
71 try | 70 try |
72 { | 71 { |
73 AdblockPlus::JsValueList converted = | 72 AdblockPlus::JsValueList converted = |
74 AdblockPlus::JsEngine::FromArguments(arguments) | 73 AdblockPlus::JsEngine::FromArguments(arguments) |
75 ->ConvertArguments(arguments); | 74 ->ConvertArguments(arguments); |
76 timeoutThread = new TimeoutThread(converted); | 75 timeoutThread = new TimeoutThread(converted); |
77 } | 76 } |
78 catch (const std::exception& e) | 77 catch (const std::exception& e) |
79 { | 78 { |
80 v8::Isolate* isolate = arguments.GetIsolate(); | 79 v8::Isolate* isolate = arguments.GetIsolate(); |
81 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); | 80 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); |
82 } | 81 } |
83 timeoutThread->Start(); | 82 timeoutThread->Start(); |
84 | 83 |
85 // We should actually return the timer ID here, which could be | 84 // We should actually return the timer ID here, which could be |
86 // used via clearTimeout(). But since we don't seem to need | 85 // used via clearTimeout(). But since we don't seem to need |
87 // clearTimeout(), we can save that for later. | 86 // clearTimeout(), we can save that for later. |
88 return v8::Undefined(); | 87 return v8::Undefined(); |
89 } | 88 } |
90 | 89 |
91 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) | 90 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) |
92 { | 91 { |
93 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); | 92 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); |
94 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 93 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); |
95 | |
Felix Dahlke
2015/02/06 04:17:27
Also unrelated.
| |
96 if (converted.size() < 1) | 94 if (converted.size() < 1) |
97 { | 95 { |
98 v8::Isolate* isolate = arguments.GetIsolate(); | 96 v8::Isolate* isolate = arguments.GetIsolate(); |
99 return v8::ThrowException(Utils::ToV8String(isolate, | 97 return v8::ThrowException(Utils::ToV8String(isolate, |
100 "_triggerEvent expects at least one parameter")); | 98 "_triggerEvent expects at least one parameter")); |
101 } | 99 } |
102 std::string eventName = converted.front()->AsString(); | 100 std::string eventName = converted.front()->AsString(); |
103 converted.erase(converted.begin()); | 101 converted.erase(converted.begin()); |
104 jsEngine->TriggerEvent(eventName, converted); | 102 jsEngine->TriggerEvent(eventName, converted); |
105 return v8::Undefined(); | 103 return v8::Undefined(); |
106 } | 104 } |
107 } | 105 } |
108 | 106 |
109 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, | 107 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, |
110 JsValuePtr obj) | 108 JsValuePtr obj) |
111 { | 109 { |
112 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); | 110 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); |
113 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); | 111 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); |
114 obj->SetProperty("_fileSystem", | 112 obj->SetProperty("_fileSystem", |
115 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); | 113 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); |
116 obj->SetProperty("_webRequest", | 114 obj->SetProperty("_webRequest", |
117 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); | 115 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); |
118 obj->SetProperty("console", | 116 obj->SetProperty("console", |
119 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); | 117 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); |
120 obj->SetProperty("_appInfo", | 118 obj->SetProperty("_appInfo", |
121 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); | 119 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); |
122 return obj; | 120 return obj; |
123 } | 121 } |
LEFT | RIGHT |