| Index: src/JsEngine.cpp |
| =================================================================== |
| --- a/src/JsEngine.cpp |
| +++ b/src/JsEngine.cpp |
| @@ -126,21 +126,27 @@ |
| if (!arguments[0]->IsFunction()) |
| throw std::runtime_error("First argument to setTimeout must be a function"); |
| auto jsValueArguments = jsEngine->ConvertArguments(arguments); |
| auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments); |
| std::weak_ptr<JsEngine> weakJsEngine = jsEngine; |
| - jsEngine->platform.GetTimer().SetTimer(std::chrono::milliseconds(arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID] |
| - { |
| - if (auto jsEngine = weakJsEngine.lock()) |
| - jsEngine->CallTimerTask(timerParamsID); |
| - }); |
| + jsEngine->platform.WithTimer( |
| + [arguments, weakJsEngine, timerParamsID](ITimer& timer) |
| + { |
| + timer.SetTimer( |
| + std::chrono::milliseconds( |
| + arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID] |
| + { |
| + if (auto jsEngine = weakJsEngine.lock()) |
| + jsEngine->CallTimerTask(timerParamsID); |
| + }); |
| + }); |
| } |
| void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) |
| { |
| auto timerParams = TakeJsValues(timerParamsID); |
| JsValue callback = std::move(timerParams[0]); |
| timerParams.erase(timerParams.begin()); // remove callback placeholder |