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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 15 matching lines...) Expand all Loading... |
26 #include "GlobalJsObject.h" | 26 #include "GlobalJsObject.h" |
27 #include "ConsoleJsObject.h" | 27 #include "ConsoleJsObject.h" |
28 #include "WebRequestJsObject.h" | 28 #include "WebRequestJsObject.h" |
29 #include "Thread.h" | 29 #include "Thread.h" |
30 #include "Utils.h" | 30 #include "Utils.h" |
31 | 31 |
32 using namespace AdblockPlus; | 32 using namespace AdblockPlus; |
33 | 33 |
34 namespace | 34 namespace |
35 { | 35 { |
36 class TimeoutThread : public Thread | |
37 { | |
38 public: | |
39 TimeoutThread(const JsEngine::TimerTask& timerTask) | |
40 : Thread(true), timerTask(timerTask) | |
41 { | |
42 } | |
43 | |
44 void Run() | |
45 { | |
46 Sleep(timerTask.taskInfoIterator->delay); | |
47 if (auto jsEngine = timerTask.weakJsEngine.lock()) | |
48 jsEngine->CallTimerTask(timerTask.taskInfoIterator); | |
49 } | |
50 | |
51 private: | |
52 JsEngine::TimerTask timerTask; | |
53 }; | |
54 | |
55 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) | 36 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) |
56 { | 37 { |
57 TimeoutThread* timeoutThread; | |
58 try | 38 try |
59 { | 39 { |
60 auto jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); | 40 AdblockPlus::JsEngine::ScheduleTimer(arguments); |
61 timeoutThread = new TimeoutThread(jsEngine->CreateTimerTask(arguments)); | |
62 } | 41 } |
63 catch (const std::exception& e) | 42 catch (const std::exception& e) |
64 { | 43 { |
65 v8::Isolate* isolate = arguments.GetIsolate(); | 44 v8::Isolate* isolate = arguments.GetIsolate(); |
66 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); | 45 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); |
67 } | 46 } |
68 timeoutThread->Start(); | |
69 | 47 |
70 // We should actually return the timer ID here, which could be | 48 // We should actually return the timer ID here, which could be |
71 // used via clearTimeout(). But since we don't seem to need | 49 // used via clearTimeout(). But since we don't seem to need |
72 // clearTimeout(), we can save that for later. | 50 // clearTimeout(), we can save that for later. |
73 return v8::Undefined(); | 51 return v8::Undefined(); |
74 } | 52 } |
75 | 53 |
76 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) | 54 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) |
77 { | 55 { |
78 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 56 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); |
(...skipping 19 matching lines...) Expand all Loading... |
98 obj->SetProperty("_fileSystem", | 76 obj->SetProperty("_fileSystem", |
99 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); | 77 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); |
100 obj->SetProperty("_webRequest", | 78 obj->SetProperty("_webRequest", |
101 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); | 79 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); |
102 obj->SetProperty("console", | 80 obj->SetProperty("console", |
103 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); | 81 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); |
104 obj->SetProperty("_appInfo", | 82 obj->SetProperty("_appInfo", |
105 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); | 83 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); |
106 return obj; | 84 return obj; |
107 } | 85 } |
OLD | NEW |