Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: Source/core/dom/ScriptRunner.cpp

Issue 866273005: Teach ScriptRunner how to yield and post on loading task queue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Dont run scripts that are not ready Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/core/dom/ScriptRunner.h ('K') | « Source/core/dom/ScriptRunner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ScriptRunner.cpp
diff --git a/Source/core/dom/ScriptRunner.cpp b/Source/core/dom/ScriptRunner.cpp
index 44543abd54da0b4edd9e54bbfd7b30a2b3f8d947..9711fb83a18c40811cb6438fd69ea9d8c03a8cc7 100644
--- a/Source/core/dom/ScriptRunner.cpp
+++ b/Source/core/dom/ScriptRunner.cpp
@@ -30,12 +30,14 @@
#include "core/dom/Element.h"
#include "core/dom/ScriptLoader.h"
#include "platform/heap/Handle.h"
+#include "platform/scheduler/Scheduler.h"
+#include "wtf/Functional.h"
namespace blink {
ScriptRunner::ScriptRunner(Document* document)
: m_document(document)
- , m_timer(this, &ScriptRunner::timerFired)
+ , m_executeScriptsTaskFactory(WTF::bind(&ScriptRunner::executeScripts, this))
{
ASSERT(document);
}
@@ -77,13 +79,13 @@ void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution
void ScriptRunner::suspend()
{
- m_timer.stop();
+ m_executeScriptsTaskFactory.cancel();
}
void ScriptRunner::resume()
{
if (hasPendingScripts())
- m_timer.startOneShot(0, FROM_HERE);
+ Scheduler::shared()->postLoadingTask(FROM_HERE, m_executeScriptsTaskFactory.task());
Sami 2015/02/10 18:40:01 Should we check whether we already have a callback
alex clarke (OOO till 29th) 2015/02/18 18:28:20 Both m_timer.startOneShot(0, FROM_HERE); and Sc
}
void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType executionType)
@@ -99,7 +101,7 @@ void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
ASSERT(!m_scriptsToExecuteInOrder.isEmpty());
break;
}
- m_timer.startOneShot(0, FROM_HERE);
+ Scheduler::shared()->postLoadingTask(FROM_HERE, m_executeScriptsTaskFactory.task());
Sami 2015/02/10 18:40:01 Ditto.
alex clarke (OOO till 29th) 2015/02/18 18:28:20 Acknowledged.
}
void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionType executionType)
@@ -127,24 +129,28 @@ void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader*
}
}
-void ScriptRunner::timerFired(Timer<ScriptRunner>* timer)
+void ScriptRunner::executeScripts()
{
- ASSERT_UNUSED(timer, timer == &m_timer);
-
RefPtrWillBeRawPtr<Document> protect(m_document.get());
- WillBeHeapVector<RawPtrWillBeMember<ScriptLoader> > scriptLoaders;
- scriptLoaders.swap(m_scriptsToExecuteSoon);
Sami 2015/02/10 18:40:01 Should we still take a snapshot of the pending scr
alex clarke (OOO till 29th) 2015/02/18 18:28:20 Good spot, that is a problem.
-
- size_t numInOrderScriptsToExecute = 0;
- for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]->isReady(); ++numInOrderScriptsToExecute)
- scriptLoaders.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]);
- if (numInOrderScriptsToExecute)
- m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute);
+ while (!m_scriptsToExecuteSoon.isEmpty()) {
+ if (Scheduler::shared()->shouldYieldForHighPriorityWork()) {
+ Scheduler::shared()->postLoadingTask(FROM_HERE, m_executeScriptsTaskFactory.task());
+ return;
+ }
+ m_scriptsToExecuteSoon.takeFirst()->execute();
+ m_document->decrementLoadEventDelayCount();
+ }
- size_t size = scriptLoaders.size();
- for (size_t i = 0; i < size; ++i) {
- scriptLoaders[i]->execute();
+ while (!m_scriptsToExecuteInOrder.isEmpty()) {
+ if (!m_scriptsToExecuteInOrder.first()->isReady()) {
+ break;
+ }
+ if (Scheduler::shared()->shouldYieldForHighPriorityWork()) {
+ Scheduler::shared()->postLoadingTask(FROM_HERE, m_executeScriptsTaskFactory.task());
+ return;
+ }
+ m_scriptsToExecuteInOrder.takeFirst()->execute();
m_document->decrementLoadEventDelayCount();
}
}
« Source/core/dom/ScriptRunner.h ('K') | « Source/core/dom/ScriptRunner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698