Index: src/GlobalJsObject.cpp |
diff --git a/src/GlobalJsObject.cpp b/src/GlobalJsObject.cpp |
index ab10d4df43df0be6095da3e61ac6035d4878f136..4a9ce4f7acbe807e0d6184cf99bf021ad0a9b981 100644 |
--- a/src/GlobalJsObject.cpp |
+++ b/src/GlobalJsObject.cpp |
@@ -36,33 +36,21 @@ namespace |
class TimeoutThread : public Thread |
{ |
public: |
- TimeoutThread(JsValueList& arguments) |
+ TimeoutThread(const JsEngine::TimerTask& timerTask) |
: Thread(true) |
+ , timerTask(timerTask) |
Oleksandr
2017/03/24 12:15:25
Nit: I think our coding style would put a comma on
sergei
2017/03/24 12:34:39
Done.
|
{ |
- if (arguments.size() < 2) |
- throw std::runtime_error("setTimeout requires at least 2 parameters"); |
- |
- if (!arguments[0]->IsFunction()) |
- throw std::runtime_error( |
- "First argument to setTimeout must be a function"); |
- |
- function = arguments[0]; |
- delay = arguments[1]->AsInt(); |
- for (size_t i = 2; i < arguments.size(); i++) |
- functionArguments.push_back(arguments[i]); |
} |
void Run() |
{ |
- Sleep(delay); |
- |
- function->Call(functionArguments); |
+ Sleep(timerTask.ii_taskInfo->delay); |
+ if (auto jsEngine = timerTask.weakJsEngine.lock()) |
+ jsEngine->CallTimerTask(timerTask.ii_taskInfo); |
} |
private: |
- JsValuePtr function; |
- int delay; |
- JsValueList functionArguments; |
+ JsEngine::TimerTask timerTask; |
}; |
v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) |
@@ -70,10 +58,8 @@ namespace |
TimeoutThread* timeoutThread; |
try |
{ |
- AdblockPlus::JsValueList converted = |
- AdblockPlus::JsEngine::FromArguments(arguments) |
- ->ConvertArguments(arguments); |
- timeoutThread = new TimeoutThread(converted); |
+ auto jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); |
+ timeoutThread = new TimeoutThread(jsEngine->CreateTimerTask(arguments)); |
} |
catch (const std::exception& e) |
{ |