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

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp

Issue 2723793002: De-Element ScriptLoader (Closed)
Patch Set: Address comments Created 3 years, 10 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
Index: third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp b/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp
index 7909e8d1155b93df5f0d9a466483ea6966b049af..d50abd9c8632468b4c06c6bb70bee6d78a52b418 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp
@@ -55,19 +55,19 @@ namespace {
// TODO(bmcquade): move this to a shared location if we find ourselves wanting
// to trace similar data elsewhere in the codebase.
-std::unique_ptr<TracedValue> getTraceArgsForScriptElement(
- Element* element,
+std::unique_ptr<TracedValue> getTraceArgsForScriptLoaderClient(
+ ScriptLoaderClient* client,
const TextPosition& textPosition) {
std::unique_ptr<TracedValue> value = TracedValue::create();
- ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element);
+ ScriptLoader* scriptLoader = client->loader();
if (scriptLoader && scriptLoader->resource())
value->setString("url", scriptLoader->resource()->url().getString());
- if (element->ownerDocument() && element->ownerDocument()->frame()) {
+ if (client->document().frame()) {
value->setString(
"frame",
String::format("0x%" PRIx64,
static_cast<uint64_t>(reinterpret_cast<intptr_t>(
- element->ownerDocument()->frame()))));
+ client->document().frame()))));
}
if (textPosition.m_line.zeroBasedInt() > 0 ||
textPosition.m_column.zeroBasedInt() > 0) {
@@ -77,15 +77,15 @@ std::unique_ptr<TracedValue> getTraceArgsForScriptElement(
return value;
}
-bool doExecuteScript(Element* scriptElement,
+bool doExecuteScript(ScriptLoaderClient* client,
const ScriptSourceCode& sourceCode,
const TextPosition& textPosition) {
- ScriptLoader* scriptLoader = toScriptLoaderIfPossible(scriptElement);
+ ScriptLoader* scriptLoader = client->loader();
DCHECK(scriptLoader);
TRACE_EVENT_WITH_FLOW1(
- "blink", "HTMLParserScriptRunner ExecuteScript", scriptElement,
+ "blink", "HTMLParserScriptRunner ExecuteScript", client,
TRACE_EVENT_FLAG_FLOW_IN, "data",
- getTraceArgsForScriptElement(scriptElement, textPosition));
+ getTraceArgsForScriptLoaderClient(client, textPosition));
return scriptLoader->executeScript(sourceCode);
}
@@ -108,27 +108,27 @@ void traceParserBlockingScript(const PendingScript* pendingScript,
// both when these yields occur, as well as how long the parser had
// to yield. The connecting flow events are traced once the parser becomes
// unblocked when the script actually executes, in doExecuteScript.
- Element* element = pendingScript->element();
- if (!element)
+ ScriptLoaderClient* client = pendingScript->scriptLoaderClient();
+ if (!client)
return;
TextPosition scriptStartPosition = pendingScript->startingPosition();
if (!pendingScript->isReady()) {
if (waitingForResources) {
TRACE_EVENT_WITH_FLOW1(
- "blink", "YieldParserForScriptLoadAndBlockingResources", element,
+ "blink", "YieldParserForScriptLoadAndBlockingResources", client,
TRACE_EVENT_FLAG_FLOW_OUT, "data",
- getTraceArgsForScriptElement(element, scriptStartPosition));
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
} else {
TRACE_EVENT_WITH_FLOW1(
- "blink", "YieldParserForScriptLoad", element,
+ "blink", "YieldParserForScriptLoad", client,
TRACE_EVENT_FLAG_FLOW_OUT, "data",
- getTraceArgsForScriptElement(element, scriptStartPosition));
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
}
} else if (waitingForResources) {
TRACE_EVENT_WITH_FLOW1(
- "blink", "YieldParserForScriptBlockingResources", element,
+ "blink", "YieldParserForScriptBlockingResources", client,
TRACE_EVENT_FLAG_FLOW_OUT, "data",
- getTraceArgsForScriptElement(element, scriptStartPosition));
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
}
}
@@ -225,7 +225,7 @@ void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
TextPosition scriptStartPosition = pendingScript->startingPosition();
double scriptParserBlockingTime =
pendingScript->parserBlockingLoadStartTime();
- Element* element = pendingScript->element();
+ ScriptLoaderClient* client = pendingScript->scriptLoaderClient();
// 1. "Let the script be the pending parsing-blocking script.
// There is no longer a pending parsing-blocking script."
@@ -237,7 +237,7 @@ void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
m_parserBlockingScript = nullptr;
}
- if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) {
+ if (ScriptLoader* scriptLoader = client->loader()) {
// 7. "Increment the parser's script nesting level by one (it should be
// zero before this step, so this sets it to one)."
HTMLParserReentryPermit::ScriptNestingLevelIncrementer
@@ -250,9 +250,9 @@ void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
// 8. "Execute the script."
if (errorOccurred) {
TRACE_EVENT_WITH_FLOW1(
- "blink", "HTMLParserScriptRunner ExecuteScriptFailed", element,
+ "blink", "HTMLParserScriptRunner ExecuteScriptFailed", client,
TRACE_EVENT_FLAG_FLOW_IN, "data",
- getTraceArgsForScriptElement(element, scriptStartPosition));
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
scriptLoader->dispatchErrorEvent();
} else {
DCHECK(isExecutingScript());
@@ -262,10 +262,10 @@ void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
monotonicallyIncreasingTime() - scriptParserBlockingTime,
scriptLoader->wasCreatedDuringDocumentWrite());
}
- if (!doExecuteScript(element, sourceCode, scriptStartPosition)) {
+ if (!doExecuteScript(client, sourceCode, scriptStartPosition)) {
scriptLoader->dispatchErrorEvent();
} else {
- element->dispatchEvent(Event::create(EventTypeNames::load));
+ client->dispatchLoadEvent();
}
}
@@ -279,13 +279,13 @@ void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
DCHECK(!isExecutingScript());
}
-void fetchBlockedDocWriteScript(Element* script,
+void fetchBlockedDocWriteScript(ScriptLoaderClient* client,
bool isParserInserted,
const TextPosition& scriptStartPosition) {
- DCHECK(script);
+ DCHECK(client);
ScriptLoader* scriptLoader =
- ScriptLoader::create(script, isParserInserted, false, false);
+ ScriptLoader::create(client, isParserInserted, false, false);
DCHECK(scriptLoader);
scriptLoader->setFetchDocWrittenScriptDeferIdle();
scriptLoader->prepareScript(scriptStartPosition);
@@ -327,9 +327,9 @@ void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript(
if (parserBlockingScript() != pendingScript)
return;
- Element* element = parserBlockingScript()->element();
+ ScriptLoaderClient* client = parserBlockingScript()->scriptLoaderClient();
- ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element);
+ ScriptLoader* scriptLoader = client->loader();
if (!scriptLoader || !scriptLoader->disallowedFetchForDocWrittenScript())
return;
@@ -350,7 +350,7 @@ void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript(
// Remove this resource entry from memory cache as the new request
// should not join onto this existing entry.
memoryCache()->remove(pendingScript->resource());
- fetchBlockedDocWriteScript(element, isParserInserted, startingPosition);
+ fetchBlockedDocWriteScript(client, isParserInserted, startingPosition);
}
void HTMLParserScriptRunner::pendingScriptFinished(
@@ -397,9 +397,7 @@ void HTMLParserScriptRunner::processScriptElement(
Element* scriptElement,
const TextPosition& scriptStartPosition) {
DCHECK(scriptElement);
- TRACE_EVENT1(
- "blink", "HTMLParserScriptRunner::execute", "data",
- getTraceArgsForScriptElement(scriptElement, scriptStartPosition));
+
// FIXME: If scripting is disabled, always just return.
bool hadPreloadScanner = m_host->hasPreloadScanner();
@@ -596,12 +594,14 @@ void HTMLParserScriptRunner::requestDeferredScript(Element* element) {
PendingScript* HTMLParserScriptRunner::requestPendingScript(
Element* element) const {
- ScriptResource* resource = toScriptLoaderIfPossible(element)->resource();
+ ScriptLoaderClient* client =
+ ScriptLoaderClient::fromElementIfPossible(element);
+ ScriptResource* resource = client->loader()->resource();
// Here |resource| should be non-null. If it were nullptr,
// ScriptLoader::fetchScript() should have returned false and
// thus the control shouldn't have reached here.
CHECK(resource);
- return PendingScript::create(element, resource);
+ return PendingScript::create(client, resource);
}
// The initial steps for 'An end tag whose tag name is "script"'
@@ -612,16 +612,15 @@ void HTMLParserScriptRunner::processScriptElementInternal(
DCHECK(m_document);
DCHECK(!hasParserBlockingScript());
{
- ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script);
-
- // This contains both a DCHECK and a null check since we should not
- // be getting into the case of a null script element, but seem to be from
- // time to time. The assertion is left in to help find those cases and
- // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>.
+ ScriptLoaderClient* client =
+ ScriptLoaderClient::fromElementIfPossible(script);
+ DCHECK(client);
+ ScriptLoader* scriptLoader = client->loader();
DCHECK(scriptLoader);
- if (!scriptLoader)
- return;
+ TRACE_EVENT1(
kouhei (in TOK) 2017/03/15 03:31:40 Maybe add a fixme to align ::execute to method nam
Nate Chapin 2017/03/16 20:15:10 Done.
+ "blink", "HTMLParserScriptRunner::execute", "data",
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
DCHECK(scriptLoader->isParserInserted());
if (!isExecutingScript())
@@ -660,7 +659,7 @@ void HTMLParserScriptRunner::processScriptElementInternal(
// (There can only be one such script per Document at a time.)"
CHECK(!m_parserBlockingScript);
m_parserBlockingScript =
- PendingScript::create(script, scriptStartPosition);
+ PendingScript::create(client, scriptStartPosition);
} else {
// 6th Clause of Step 23.
// "Immediately execute the script block,
@@ -673,7 +672,7 @@ void HTMLParserScriptRunner::processScriptElementInternal(
ScriptSourceCode sourceCode(script->textContent(),
documentURLForScriptExecution(m_document),
scriptStartPosition);
- doExecuteScript(script, sourceCode, scriptStartPosition);
+ doExecuteScript(client, sourceCode, scriptStartPosition);
}
} else {
// 2nd Clause of Step 23.

Powered by Google App Engine
This is Rietveld 408576698