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

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

Issue 669503003: Revert of Refactor Script(Loader|Runner): don't access Resources all over the place... (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « 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 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();
}
}
« no previous file with comments | « Source/core/dom/ScriptRunner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698