| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (arguments.Length() < 2) | 124 if (arguments.Length() < 2) |
| 125 throw std::runtime_error("setTimeout requires at least 2 parameters"); | 125 throw std::runtime_error("setTimeout requires at least 2 parameters"); |
| 126 | 126 |
| 127 if (!arguments[0]->IsFunction()) | 127 if (!arguments[0]->IsFunction()) |
| 128 throw std::runtime_error("First argument to setTimeout must be a function"); | 128 throw std::runtime_error("First argument to setTimeout must be a function"); |
| 129 | 129 |
| 130 auto jsValueArguments = jsEngine->ConvertArguments(arguments); | 130 auto jsValueArguments = jsEngine->ConvertArguments(arguments); |
| 131 auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments); | 131 auto timerParamsID = jsEngine->StoreJsValues(jsValueArguments); |
| 132 | 132 |
| 133 std::weak_ptr<JsEngine> weakJsEngine = jsEngine; | 133 std::weak_ptr<JsEngine> weakJsEngine = jsEngine; |
| 134 jsEngine->platform.GetTimer().SetTimer(std::chrono::milliseconds(arguments[1]-
>IntegerValue()), [weakJsEngine, timerParamsID] | 134 jsEngine->platform.WithTimer( |
| 135 { | 135 [arguments, weakJsEngine, timerParamsID](ITimer& timer) |
| 136 if (auto jsEngine = weakJsEngine.lock()) | 136 { |
| 137 jsEngine->CallTimerTask(timerParamsID); | 137 timer.SetTimer( |
| 138 }); | 138 std::chrono::milliseconds( |
| 139 arguments[1]->IntegerValue()), [weakJsEngine, timerParamsID] |
| 140 { |
| 141 if (auto jsEngine = weakJsEngine.lock()) |
| 142 jsEngine->CallTimerTask(timerParamsID); |
| 143 }); |
| 144 }); |
| 139 } | 145 } |
| 140 | 146 |
| 141 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) | 147 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) |
| 142 { | 148 { |
| 143 auto timerParams = TakeJsValues(timerParamsID); | 149 auto timerParams = TakeJsValues(timerParamsID); |
| 144 JsValue callback = std::move(timerParams[0]); | 150 JsValue callback = std::move(timerParams[0]); |
| 145 | 151 |
| 146 timerParams.erase(timerParams.begin()); // remove callback placeholder | 152 timerParams.erase(timerParams.begin()); // remove callback placeholder |
| 147 timerParams.erase(timerParams.begin()); // remove timeout param | 153 timerParams.erase(timerParams.begin()); // remove timeout param |
| 148 callback.Call(timerParams); | 154 callback.Call(timerParams); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 list.push_back(JsValue(shared_from_this(), arguments[i])); | 329 list.push_back(JsValue(shared_from_this(), arguments[i])); |
| 324 return list; | 330 return list; |
| 325 } | 331 } |
| 326 | 332 |
| 327 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 333 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 328 const AdblockPlus::JsValue& value) | 334 const AdblockPlus::JsValue& value) |
| 329 { | 335 { |
| 330 auto global = GetGlobalObject(); | 336 auto global = GetGlobalObject(); |
| 331 global.SetProperty(name, value); | 337 global.SetProperty(name, value); |
| 332 } | 338 } |
| OLD | NEW |