Commit 9ec9d9b4 authored by kouhei's avatar kouhei Committed by Commit bot

Simplify: remove PendingScript::releaseElementAndClear

Simplify PendingScript disposal path by removing method releaseElementAndClear.
Callers should use dispose() directly instead of repeating stopWatchingForLoad + releaseElementAndClear calls.

BUG=None

Review-Url: https://codereview.chromium.org/2536553002
Cr-Commit-Position: refs/heads/master@{#434897}
parent 2aebde7c
......@@ -196,8 +196,7 @@ TEST_F(ScriptStreamingTest, CancellingStreaming) {
// Simulate cancelling the network load (e.g., because the user navigated
// away).
EXPECT_FALSE(client->finished());
getPendingScript()->stopWatchingForLoad();
getPendingScript()->releaseElementAndClear();
getPendingScript()->dispose();
m_pendingScript = nullptr; // This will destroy m_resource.
m_resource = nullptr;
......
......@@ -52,10 +52,18 @@ PendingScript::PendingScript(Element* element, ScriptResource* resource)
PendingScript::~PendingScript() {}
void PendingScript::dispose() {
if (!m_client)
return;
stopWatchingForLoad();
releaseElementAndClear();
DCHECK(!m_client);
DCHECK(!m_watchingForLoad);
setScriptResource(nullptr);
m_startingPosition = TextPosition::belowRangePosition();
m_integrityFailure = false;
m_parserBlockingLoadStartTime = 0;
if (m_streamer)
m_streamer->cancel();
m_streamer = nullptr;
m_element = nullptr;
}
void PendingScript::watchForLoad(ScriptResourceClient* client) {
......@@ -91,18 +99,6 @@ void PendingScript::setElement(Element* element) {
m_element = element;
}
Element* PendingScript::releaseElementAndClear() {
setScriptResource(0);
m_watchingForLoad = false;
m_startingPosition = TextPosition::belowRangePosition();
m_integrityFailure = false;
m_parserBlockingLoadStartTime = 0;
if (m_streamer)
m_streamer->cancel();
m_streamer.release();
return m_element.release();
}
void PendingScript::setScriptResource(ScriptResource* resource) {
setResource(resource);
}
......
......@@ -76,7 +76,6 @@ class CORE_EXPORT PendingScript final
Element* element() const { return m_element.get(); }
void setElement(Element*);
Element* releaseElementAndClear();
void setScriptResource(ScriptResource*);
......
......@@ -561,8 +561,7 @@ void ScriptLoader::execute() {
DCHECK(m_pendingScript->resource());
bool errorOccurred = false;
ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred);
Element* element = m_pendingScript->releaseElementAndClear();
ALLOW_UNUSED_LOCAL(element);
m_pendingScript->dispose();
if (errorOccurred) {
dispatchErrorEvent();
} else if (!m_resource->wasCanceled()) {
......
......@@ -169,13 +169,11 @@ void HTMLScriptRunner::detach() {
if (!m_document)
return;
m_parserBlockingScript->stopWatchingForLoad();
m_parserBlockingScript->releaseElementAndClear();
m_parserBlockingScript->dispose();
while (!m_scriptsToExecuteAfterParsing.isEmpty()) {
PendingScript* pendingScript = m_scriptsToExecuteAfterParsing.takeFirst();
pendingScript->stopWatchingForLoad();
pendingScript->releaseElementAndClear();
pendingScript->dispose();
}
m_document = nullptr;
// m_reentryPermit is not cleared here, because the script runner
......@@ -210,6 +208,8 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(
// Stop watching loads before executeScript to prevent recursion if the script
// reloads itself.
// TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the
// if block.
pendingScript->stopWatchingForLoad();
if (!isExecutingScript()) {
......@@ -227,7 +227,9 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(
double scriptParserBlockingTime =
pendingScript->parserBlockingLoadStartTime();
// Clear the pending script before possible re-entrancy from executeScript()
Element* element = pendingScript->releaseElementAndClear();
Element* element = pendingScript->element();
pendingScript->dispose();
if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) {
HTMLParserReentryPermit::ScriptNestingLevelIncrementer
nestingLevelIncrementer =
......@@ -261,14 +263,12 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(
void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) {
if (m_parserBlockingScript->resource() == resource) {
m_parserBlockingScript->stopWatchingForLoad();
m_parserBlockingScript->releaseElementAndClear();
m_parserBlockingScript->dispose();
return;
}
for (auto& script : m_scriptsToExecuteAfterParsing) {
if (script->resource() == resource) {
script->stopWatchingForLoad();
script->releaseElementAndClear();
script->dispose();
return;
}
}
......@@ -515,7 +515,7 @@ void HTMLScriptRunner::runScript(Element* script,
m_parserBlockingScript->setStartingPosition(scriptStartPosition);
} else {
DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u);
m_parserBlockingScript->releaseElementAndClear();
m_parserBlockingScript->dispose();
ScriptSourceCode sourceCode(script->textContent(),
documentURLForScriptExecution(m_document),
scriptStartPosition);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment