Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsEngine.cpp

Issue 29543810: Issue 5118 - Lock the platform interfaces before use (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Last details Created Sept. 13, 2017, 8:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/Platform.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/Platform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld