| Index: Source/core/dom/ScriptRunner.cpp
|
| diff --git a/Source/core/dom/ScriptRunner.cpp b/Source/core/dom/ScriptRunner.cpp
|
| index 75d29b3bc94ed9af13efcc9a8167c52df00ec2dd..88ed1e1c360659213e8affaf7f2ffebd37670c3f 100644
|
| --- a/Source/core/dom/ScriptRunner.cpp
|
| +++ b/Source/core/dom/ScriptRunner.cpp
|
| @@ -30,14 +30,12 @@
|
| #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_executeScriptsTaskFactory(WTF::bind(&ScriptRunner::executeScripts, this))
|
| + , m_timer(this, &ScriptRunner::timerFired)
|
| {
|
| ASSERT(document);
|
| }
|
| @@ -79,13 +77,13 @@
|
|
|
| void ScriptRunner::suspend()
|
| {
|
| - m_executeScriptsTaskFactory.cancel();
|
| + m_timer.stop();
|
| }
|
|
|
| void ScriptRunner::resume()
|
| {
|
| if (hasPendingScripts())
|
| - postTaskIfOneIsNotAlreadyInFlight();
|
| + m_timer.startOneShot(0, FROM_HERE);
|
| }
|
|
|
| void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType executionType)
|
| @@ -101,7 +99,7 @@
|
| ASSERT(!m_scriptsToExecuteInOrder.isEmpty());
|
| break;
|
| }
|
| - postTaskIfOneIsNotAlreadyInFlight();
|
| + m_timer.startOneShot(0, FROM_HERE);
|
| }
|
|
|
| void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionType executionType)
|
| @@ -155,52 +153,26 @@
|
| }
|
| }
|
|
|
| -void ScriptRunner::executeScripts()
|
| +void ScriptRunner::timerFired(Timer<ScriptRunner>* timer)
|
| {
|
| + ASSERT_UNUSED(timer, timer == &m_timer);
|
| +
|
| RefPtrWillBeRawPtr<Document> protect(m_document.get());
|
|
|
| - // New scripts are always appended to m_scriptsToExecuteSoon and m_scriptsToExecuteInOrder (never prepended)
|
| - // so as long as we keep track of the current totals, we can ensure the order of execution if new scripts
|
| - // are added while executing the current ones.
|
| - // NOTE a yield followed by a notifyScriptReady(... ASYNC_EXECUTION) will result in that script executing
|
| - // before any pre-existing ScriptsToExecuteInOrder.
|
| - size_t numScriptsToExecuteSoon = m_scriptsToExecuteSoon.size();
|
| - size_t numScriptsToExecuteInOrder = m_scriptsToExecuteInOrder.size();
|
| - for (size_t i = 0; i < numScriptsToExecuteSoon; i++) {
|
| - ASSERT(!m_scriptsToExecuteSoon.isEmpty());
|
| - m_scriptsToExecuteSoon.takeFirst()->execute();
|
| + WillBeHeapVector<RawPtrWillBeMember<ScriptLoader> > scriptLoaders;
|
| + scriptLoaders.swap(m_scriptsToExecuteSoon);
|
| +
|
| + 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);
|
| +
|
| + size_t size = scriptLoaders.size();
|
| + for (size_t i = 0; i < size; ++i) {
|
| + scriptLoaders[i]->execute();
|
| m_document->decrementLoadEventDelayCount();
|
| - if (yieldForHighPriorityWork())
|
| - return;
|
| }
|
| -
|
| - for (size_t i = 0; i < numScriptsToExecuteInOrder; i++) {
|
| - ASSERT(!m_scriptsToExecuteInOrder.isEmpty());
|
| - if (!m_scriptsToExecuteInOrder.first()->isReady())
|
| - break;
|
| - m_scriptsToExecuteInOrder.takeFirst()->execute();
|
| - m_document->decrementLoadEventDelayCount();
|
| - if (yieldForHighPriorityWork())
|
| - return;
|
| - }
|
| -}
|
| -
|
| -bool ScriptRunner::yieldForHighPriorityWork()
|
| -{
|
| - if (!Scheduler::shared()->shouldYieldForHighPriorityWork())
|
| - return false;
|
| -
|
| - postTaskIfOneIsNotAlreadyInFlight();
|
| - return true;
|
| -}
|
| -
|
| -void ScriptRunner::postTaskIfOneIsNotAlreadyInFlight()
|
| -{
|
| - if (m_executeScriptsTaskFactory.isPending())
|
| - return;
|
| -
|
| - // FIXME: Rename task() so that it's obvious it cancels any pending task.
|
| - Scheduler::shared()->postLoadingTask(FROM_HERE, m_executeScriptsTaskFactory.task());
|
| }
|
|
|
| void ScriptRunner::trace(Visitor* visitor)
|
|
|