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

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

Issue 2723793002: De-Element ScriptLoader (Closed)
Patch Set: De-Element ScriptLoader 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 88afa39d916a2a36115136ef176f2b1000c90df6..7fe977da3b4336c0f83e4f1c715565507eec8b49 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()) {
hiroshige 2017/03/01 00:58:15 This changes the behavior: ownerDocument() -> docu
Nate Chapin 2017/03/01 21:34:59 Node::document() and Node::ownerDocument() are equ
hiroshige 2017/03/06 22:54:03 Acknowledged.
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,
Nate Chapin 2017/02/28 21:39:29 Here and below: these TRACE_EVENT changes are prob
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();
hiroshige 2017/03/01 00:58:15 Hmm. Conceptually I think we should call scriptLoa
Nate Chapin 2017/03/01 21:34:59 Yeah, I considered calling scriptLoader->dispatchL
}
}
@@ -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(
@@ -381,9 +381,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();
@@ -580,12 +578,14 @@ void HTMLParserScriptRunner::requestDeferredScript(Element* element) {
PendingScript* HTMLParserScriptRunner::requestPendingScript(
Element* element) const {
- ScriptResource* resource = toScriptLoaderIfPossible(element)->resource();
+ ScriptLoaderClient* client =
+ ScriptLoaderClient::fromElementIfPossible(element);
hiroshige 2017/03/01 00:58:15 Probably we can remove fromElementIfPossible() cal
Nate Chapin 2017/03/01 21:35:00 Possibly, but that requires changing PendingScript
hiroshige 2017/03/06 22:54:03 Acknowledged.
+ 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"'
@@ -596,7 +596,11 @@ void HTMLParserScriptRunner::processScriptElementInternal(
DCHECK(m_document);
DCHECK(!hasParserBlockingScript());
{
- ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script);
+ ScriptLoaderClient* client =
+ ScriptLoaderClient::fromElementIfPossible(script);
+ if (!client)
hiroshige 2017/03/01 00:58:15 Shouldn't |client| always non-null because we expe
Nate Chapin 2017/03/01 21:34:59 It should be, I was just copying the pattern of th
+ return;
+ ScriptLoader* scriptLoader = client->loader();
// 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
@@ -606,6 +610,9 @@ void HTMLParserScriptRunner::processScriptElementInternal(
if (!scriptLoader)
return;
+ TRACE_EVENT1(
+ "blink", "HTMLParserScriptRunner::execute", "data",
+ getTraceArgsForScriptLoaderClient(client, scriptStartPosition));
DCHECK(scriptLoader->isParserInserted());
if (!isExecutingScript())
@@ -644,7 +651,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,
@@ -657,7 +664,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