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

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

Issue 669603002: Reland: 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: test update 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') | Source/core/html/parser/HTMLScriptRunner.cpp » ('j') | 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 bc1a7a5d9171c6e0f22256a015f296582d954907..272570454c494a5e432eaade0c200aff5f23707a 100644
--- a/Source/core/dom/ScriptRunner.cpp
+++ b/Source/core/dom/ScriptRunner.cpp
@@ -28,9 +28,7 @@
#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,31 +42,33 @@ ScriptRunner::ScriptRunner(Document* document)
ScriptRunner::~ScriptRunner()
{
+ // Make sure that ScriptLoaders don't keep their PendingScripts alive.
+ for (size_t i = 0; i < m_scriptsToExecuteInOrder.size(); ++i)
+ m_scriptsToExecuteInOrder[i]->detach();
+ for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i)
+ m_scriptsToExecuteSoon[i]->detach();
+ for (HashSet<ScriptLoader*>::iterator it = m_pendingAsyncScripts.begin(); it != m_pendingAsyncScripts.end(); ++it)
+ (*it)->detach();
}
-void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader, const PendingScript& pendingScript)
+void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader)
{
m_document->incrementLoadEventDelayCount();
- m_pendingAsyncScripts.add(scriptLoader, pendingScript);
+ m_pendingAsyncScripts.add(scriptLoader);
}
-void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourcePtr<ScriptResource> resource, ExecutionType executionType)
+void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ExecutionType executionType)
{
ASSERT(scriptLoader);
- ASSERT(resource.get());
-
- Element* element = scriptLoader->element();
- ASSERT(element);
- ASSERT(element->inDocument());
switch (executionType) {
case ASYNC_EXECUTION:
- addPendingAsyncScript(scriptLoader, PendingScript(element, resource.get()));
+ addPendingAsyncScript(scriptLoader);
break;
case IN_ORDER_EXECUTION:
m_document->incrementLoadEventDelayCount();
- m_scriptsToExecuteInOrder.append(PendingScript(element, resource.get()));
+ m_scriptsToExecuteInOrder.append(scriptLoader);
break;
}
}
@@ -89,7 +89,8 @@ void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
switch (executionType) {
case ASYNC_EXECUTION:
ASSERT(m_pendingAsyncScripts.contains(scriptLoader));
- m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptLoader));
+ m_scriptsToExecuteSoon.append(scriptLoader);
+ m_pendingAsyncScripts.remove(scriptLoader);
break;
case IN_ORDER_EXECUTION:
@@ -105,6 +106,7 @@ void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
case ASYNC_EXECUTION:
ASSERT(m_pendingAsyncScripts.contains(scriptLoader));
m_pendingAsyncScripts.remove(scriptLoader);
+ scriptLoader->detach();
m_document->decrementLoadEventDelayCount();
break;
@@ -117,7 +119,8 @@ void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader* scriptLoader)
{
if (m_pendingAsyncScripts.contains(scriptLoader)) {
- newRunner->addPendingAsyncScript(scriptLoader, m_pendingAsyncScripts.take(scriptLoader));
+ newRunner->addPendingAsyncScript(scriptLoader);
+ m_pendingAsyncScripts.remove(scriptLoader);
m_document->decrementLoadEventDelayCount();
}
}
@@ -128,20 +131,18 @@ void ScriptRunner::timerFired(Timer<ScriptRunner>* timer)
RefPtrWillBeRawPtr<Document> protect(m_document.get());
- Vector<PendingScript> scripts;
- scripts.swap(m_scriptsToExecuteSoon);
+ Vector<ScriptLoader*> scriptLoaders;
+ scriptLoaders.swap(m_scriptsToExecuteSoon);
size_t numInOrderScriptsToExecute = 0;
- for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numInOrderScriptsToExecute)
- scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]);
+ 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 = scripts.size();
+ size_t size = scriptLoaders.size();
for (size_t i = 0; i < size; ++i) {
- ScriptResource* resource = scripts[i].resource();
- RefPtrWillBeRawPtr<Element> element = scripts[i].releaseElementAndClear();
- toScriptLoaderIfPossible(element.get())->execute(resource);
+ scriptLoaders[i]->execute();
m_document->decrementLoadEventDelayCount();
}
}
« no previous file with comments | « Source/core/dom/ScriptRunner.h ('k') | Source/core/html/parser/HTMLScriptRunner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698