Commit 2491c29c authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Reduce ScriptElementBase::FromElementIfPossible() calls

By passing ScriptElementBase/ScriptLoader instead of Element.
This CL shouldn't change the behavior.

Bug: 686281
Change-Id: I903482390623d18bcff9b6358dc9ee12e1ef7495
Reviewed-on: https://chromium-review.googlesource.com/564144Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491433}
parent a65b00c9
...@@ -524,12 +524,13 @@ bool HTMLParserScriptRunner::ExecuteScriptsWaitingForParsing() { ...@@ -524,12 +524,13 @@ bool HTMLParserScriptRunner::ExecuteScriptsWaitingForParsing() {
} }
// 2nd Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script // 2nd Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script
void HTMLParserScriptRunner::RequestParsingBlockingScript(Element* element) { void HTMLParserScriptRunner::RequestParsingBlockingScript(
ScriptLoader* script_loader) {
// "The element is the pending parsing-blocking script of the Document of // "The element is the pending parsing-blocking script of the Document of
// the parser that created the element. // the parser that created the element.
// (There can only be one such script per Document at a time.)" // (There can only be one such script per Document at a time.)"
CHECK(!ParserBlockingScript()); CHECK(!ParserBlockingScript());
parser_blocking_script_ = RequestPendingScript(element); parser_blocking_script_ = script_loader->CreatePendingScript();
if (!ParserBlockingScript()) if (!ParserBlockingScript())
return; return;
...@@ -546,8 +547,9 @@ void HTMLParserScriptRunner::RequestParsingBlockingScript(Element* element) { ...@@ -546,8 +547,9 @@ void HTMLParserScriptRunner::RequestParsingBlockingScript(Element* element) {
} }
// 1st Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script // 1st Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script
void HTMLParserScriptRunner::RequestDeferredScript(Element* element) { void HTMLParserScriptRunner::RequestDeferredScript(
PendingScript* pending_script = RequestPendingScript(element); ScriptLoader* script_loader) {
PendingScript* pending_script = script_loader->CreatePendingScript();
if (!pending_script) if (!pending_script)
return; return;
...@@ -565,13 +567,6 @@ void HTMLParserScriptRunner::RequestDeferredScript(Element* element) { ...@@ -565,13 +567,6 @@ void HTMLParserScriptRunner::RequestDeferredScript(Element* element) {
TraceWrapperMember<PendingScript>(this, pending_script)); TraceWrapperMember<PendingScript>(this, pending_script));
} }
PendingScript* HTMLParserScriptRunner::RequestPendingScript(
Element* element) const {
ScriptElementBase* script_element =
ScriptElementBase::FromElementIfPossible(element);
return script_element->Loader()->CreatePendingScript();
}
// The initial steps for 'An end tag whose tag name is "script"' // The initial steps for 'An end tag whose tag name is "script"'
// https://html.spec.whatwg.org/#scriptEndTag // https://html.spec.whatwg.org/#scriptEndTag
void HTMLParserScriptRunner::ProcessScriptElementInternal( void HTMLParserScriptRunner::ProcessScriptElementInternal(
...@@ -616,7 +611,7 @@ void HTMLParserScriptRunner::ProcessScriptElementInternal( ...@@ -616,7 +611,7 @@ void HTMLParserScriptRunner::ProcessScriptElementInternal(
if (script_loader->WillExecuteWhenDocumentFinishedParsing()) { if (script_loader->WillExecuteWhenDocumentFinishedParsing()) {
// 1st Clause of Step 23. // 1st Clause of Step 23.
RequestDeferredScript(script); RequestDeferredScript(script_loader);
} else if (script_loader->ReadyToBeParserExecuted()) { } else if (script_loader->ReadyToBeParserExecuted()) {
// 5th Clause of Step 23. // 5th Clause of Step 23.
// "If ... it's an HTML parser // "If ... it's an HTML parser
...@@ -643,7 +638,7 @@ void HTMLParserScriptRunner::ProcessScriptElementInternal( ...@@ -643,7 +638,7 @@ void HTMLParserScriptRunner::ProcessScriptElementInternal(
} }
} else { } else {
// 2nd Clause of Step 23. // 2nd Clause of Step 23.
RequestParsingBlockingScript(script); RequestParsingBlockingScript(script_loader);
} }
// "Decrement the parser's script nesting level by one. // "Decrement the parser's script nesting level by one.
......
...@@ -42,6 +42,7 @@ namespace blink { ...@@ -42,6 +42,7 @@ namespace blink {
class Document; class Document;
class Element; class Element;
class HTMLParserScriptRunnerHost; class HTMLParserScriptRunnerHost;
class ScriptLoader;
// HTMLParserScriptRunner is responsible for for arranging the execution of // HTMLParserScriptRunner is responsible for for arranging the execution of
// script elements inserted by the parser, according to the rules for // script elements inserted by the parser, according to the rules for
...@@ -111,9 +112,8 @@ class HTMLParserScriptRunner final ...@@ -111,9 +112,8 @@ class HTMLParserScriptRunner final
ScriptStreamer::Type); ScriptStreamer::Type);
void ExecuteParsingBlockingScripts(); void ExecuteParsingBlockingScripts();
void RequestParsingBlockingScript(Element*); void RequestParsingBlockingScript(ScriptLoader*);
void RequestDeferredScript(Element*); void RequestDeferredScript(ScriptLoader*);
PendingScript* RequestPendingScript(Element*) const;
// Processes the provided script element, but does not execute any // Processes the provided script element, but does not execute any
// parsing-blocking scripts that may remain after execution. // parsing-blocking scripts that may remain after execution.
......
...@@ -440,11 +440,9 @@ void XMLDocumentParser::PendingScriptFinished( ...@@ -440,11 +440,9 @@ void XMLDocumentParser::PendingScriptFinished(
pending_script->StopWatchingForLoad(); pending_script->StopWatchingForLoad();
Element* e = script_element_; ScriptLoader* script_loader = script_element_->Loader();
script_element_ = nullptr; script_element_ = nullptr;
ScriptLoader* script_loader =
ScriptElementBase::FromElementIfPossible(e)->Loader();
DCHECK(script_loader); DCHECK(script_loader);
CHECK_EQ(script_loader->GetScriptType(), ScriptType::kClassic); CHECK_EQ(script_loader->GetScriptType(), ScriptType::kClassic);
...@@ -1131,7 +1129,7 @@ void XMLDocumentParser::EndElementNs() { ...@@ -1131,7 +1129,7 @@ void XMLDocumentParser::EndElementNs() {
// https://html.spec.whatwg.org/#prepare-a-script // https://html.spec.whatwg.org/#prepare-a-script
pending_script_ = script_loader->CreatePendingScript(); pending_script_ = script_loader->CreatePendingScript();
pending_script_->MarkParserBlockingLoadStartTime(); pending_script_->MarkParserBlockingLoadStartTime();
script_element_ = element; script_element_ = script_element_base;
pending_script_->WatchForLoad(this); pending_script_->WatchForLoad(this);
// pending_script_ will be null if script was already ready. // pending_script_ will be null if script was already ready.
if (pending_script_) if (pending_script_)
......
...@@ -49,6 +49,7 @@ class Document; ...@@ -49,6 +49,7 @@ class Document;
class DocumentFragment; class DocumentFragment;
class Element; class Element;
class LocalFrameView; class LocalFrameView;
class ScriptElementBase;
class Text; class Text;
class XMLParserContext : public RefCounted<XMLParserContext> { class XMLParserContext : public RefCounted<XMLParserContext> {
...@@ -209,7 +210,7 @@ class XMLDocumentParser final : public ScriptableDocumentParser, ...@@ -209,7 +210,7 @@ class XMLDocumentParser final : public ScriptableDocumentParser,
XMLErrors xml_errors_; XMLErrors xml_errors_;
Member<PendingScript> pending_script_; Member<PendingScript> pending_script_;
Member<Element> script_element_; Member<ScriptElementBase> script_element_;
TextPosition script_start_position_; TextPosition script_start_position_;
bool parsing_fragment_; bool parsing_fragment_;
......
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