Index: Source/core/dom/ScriptRunner.cpp |
diff --git a/Source/core/dom/ScriptRunner.cpp b/Source/core/dom/ScriptRunner.cpp |
index 6246a00ab567907676b46ef6cd8d5bb6b65c0dfd..bc1a7a5d9171c6e0f22256a015f296582d954907 100644 |
--- a/Source/core/dom/ScriptRunner.cpp |
+++ b/Source/core/dom/ScriptRunner.cpp |
@@ -28,7 +28,9 @@ |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
+#include "core/dom/PendingScript.h" |
#include "core/dom/ScriptLoader.h" |
+#include "core/fetch/ScriptResource.h" |
#include "platform/heap/Handle.h" |
namespace blink { |
@@ -44,24 +46,29 @@ |
{ |
} |
-void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader) |
+void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader, const PendingScript& pendingScript) |
{ |
m_document->incrementLoadEventDelayCount(); |
- m_pendingAsyncScripts.add(scriptLoader); |
+ m_pendingAsyncScripts.add(scriptLoader, pendingScript); |
} |
-void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ExecutionType executionType) |
+void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourcePtr<ScriptResource> resource, ExecutionType executionType) |
{ |
ASSERT(scriptLoader); |
+ ASSERT(resource.get()); |
+ |
+ Element* element = scriptLoader->element(); |
+ ASSERT(element); |
+ ASSERT(element->inDocument()); |
switch (executionType) { |
case ASYNC_EXECUTION: |
- addPendingAsyncScript(scriptLoader); |
+ addPendingAsyncScript(scriptLoader, PendingScript(element, resource.get())); |
break; |
case IN_ORDER_EXECUTION: |
m_document->incrementLoadEventDelayCount(); |
- m_scriptsToExecuteInOrder.append(scriptLoader); |
+ m_scriptsToExecuteInOrder.append(PendingScript(element, resource.get())); |
break; |
} |
} |
@@ -82,8 +89,7 @@ |
switch (executionType) { |
case ASYNC_EXECUTION: |
ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
- m_scriptsToExecuteSoon.append(scriptLoader); |
- m_pendingAsyncScripts.remove(scriptLoader); |
+ m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptLoader)); |
break; |
case IN_ORDER_EXECUTION: |
@@ -111,8 +117,7 @@ |
void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader* scriptLoader) |
{ |
if (m_pendingAsyncScripts.contains(scriptLoader)) { |
- newRunner->addPendingAsyncScript(scriptLoader); |
- m_pendingAsyncScripts.remove(scriptLoader); |
+ newRunner->addPendingAsyncScript(scriptLoader, m_pendingAsyncScripts.take(scriptLoader)); |
m_document->decrementLoadEventDelayCount(); |
} |
} |
@@ -123,18 +128,20 @@ |
RefPtrWillBeRawPtr<Document> protect(m_document.get()); |
- Vector<ScriptLoader*> scriptLoaders; |
- scriptLoaders.swap(m_scriptsToExecuteSoon); |
+ Vector<PendingScript> scripts; |
+ scripts.swap(m_scriptsToExecuteSoon); |
size_t numInOrderScriptsToExecute = 0; |
- for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]->isReady(); ++numInOrderScriptsToExecute) |
- scriptLoaders.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); |
+ for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numInOrderScriptsToExecute) |
+ scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); |
if (numInOrderScriptsToExecute) |
m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); |
- size_t size = scriptLoaders.size(); |
+ size_t size = scripts.size(); |
for (size_t i = 0; i < size; ++i) { |
- scriptLoaders[i]->execute(); |
+ ScriptResource* resource = scripts[i].resource(); |
+ RefPtrWillBeRawPtr<Element> element = scripts[i].releaseElementAndClear(); |
+ toScriptLoaderIfPossible(element.get())->execute(resource); |
m_document->decrementLoadEventDelayCount(); |
} |
} |