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

Unified Diff: src/GlobalJsObject.cpp

Issue 29393573: Issue 4692 - Dont' keep a strong reference from timer thread (Closed)
Patch Set: address comments Created March 24, 2017, 12:28 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | src/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/GlobalJsObject.cpp
diff --git a/src/GlobalJsObject.cpp b/src/GlobalJsObject.cpp
index ab10d4df43df0be6095da3e61ac6035d4878f136..119b966ed5bc36a470628755b63a9837388adeba 100644
--- a/src/GlobalJsObject.cpp
+++ b/src/GlobalJsObject.cpp
@@ -36,33 +36,20 @@ namespace
class TimeoutThread : public Thread
{
public:
- TimeoutThread(JsValueList& arguments)
- : Thread(true)
+ TimeoutThread(const JsEngine::TimerTask& timerTask)
+ : Thread(true), timerTask(timerTask)
{
- 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.taskInfoIterator->delay);
+ if (auto jsEngine = timerTask.weakJsEngine.lock())
+ jsEngine->CallTimerTask(timerTask.taskInfoIterator);
}
private:
- JsValuePtr function;
- int delay;
- JsValueList functionArguments;
+ JsEngine::TimerTask timerTask;
};
v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
@@ -70,10 +57,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)
{
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld