Skip to content

Commit

Permalink
Rename HTMLScriptRunner to HTMLParserScriptRunner and add comments.
Browse files Browse the repository at this point in the history
This class is only responsible for scripts inserted and executed due to
HTMLDocumentParser, so it's renamed to reflect this (and hopefully make its
relationship to ScriptRunner and ScriptLoader clearer).

execute is renamed to processScriptElement, because it contains the logic
for processing a script end tag (from the spec), which does not necessarily
execute the script synchronously.

isPendingScriptReady is renamed to isParserBlockingScriptReady, since that
is the particular pending script it means, as opposed to
m_scriptsToExecuteAfterParsing.

There is still some more minor inconsistency in the use of the term
"parser-blocking script" as opposed to the spec's "parsing-blocking script",
but this would require changes to more connected classes to fix.

executeParsingBlockingScript is inlined into executeParsingBlockingScripts,
since both methods are small but have confusingly similar names.

ASSERT is changed to DCHECK because check-webkit-style insists.

This should cause no functional changes.

Review-Url: https://codereview.chromium.org/2559803002
Cr-Commit-Position: refs/heads/master@{#437363}
  • Loading branch information
jeremyroman authored and Commit bot committed Dec 8, 2016
1 parent ea856e3 commit 799df4e
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 117 deletions.
6 changes: 3 additions & 3 deletions third_party/WebKit/Source/core/html/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ blink_core_sources("html") {
"parser/HTMLParserReentryPermit.h",
"parser/HTMLParserScheduler.cpp",
"parser/HTMLParserScheduler.h",
"parser/HTMLParserScriptRunner.cpp",
"parser/HTMLParserScriptRunner.h",
"parser/HTMLParserScriptRunnerHost.h",
"parser/HTMLParserThread.cpp",
"parser/HTMLParserThread.h",
"parser/HTMLPreloadScanner.cpp",
"parser/HTMLPreloadScanner.h",
"parser/HTMLResourcePreloader.cpp",
"parser/HTMLResourcePreloader.h",
"parser/HTMLScriptRunner.cpp",
"parser/HTMLScriptRunner.h",
"parser/HTMLScriptRunnerHost.h",
"parser/HTMLSourceTracker.cpp",
"parser/HTMLSourceTracker.h",
"parser/HTMLSrcsetParser.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
#include "core/html/parser/AtomicHTMLToken.h"
#include "core/html/parser/BackgroundHTMLParser.h"
#include "core/html/parser/HTMLParserScheduler.h"
#include "core/html/parser/HTMLParserScriptRunner.h"
#include "core/html/parser/HTMLParserThread.h"
#include "core/html/parser/HTMLResourcePreloader.h"
#include "core/html/parser/HTMLScriptRunner.h"
#include "core/html/parser/HTMLTreeBuilder.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/InspectorTraceEvents.h"
Expand Down Expand Up @@ -97,7 +97,8 @@ static HTMLTokenizer::State tokenizerStateForContextElement(
HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document,
ParserSynchronizationPolicy syncPolicy)
: HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) {
m_scriptRunner = HTMLScriptRunner::create(reentryPermit(), &document, this);
m_scriptRunner =
HTMLParserScriptRunner::create(reentryPermit(), &document, this);
m_treeBuilder =
HTMLTreeBuilder::create(this, document, AllowScriptingContent, m_options);
}
Expand Down Expand Up @@ -174,7 +175,7 @@ DEFINE_TRACE(HTMLDocumentParser) {
visitor->trace(m_scriptRunner);
visitor->trace(m_preloader);
ScriptableDocumentParser::trace(visitor);
HTMLScriptRunnerHost::trace(visitor);
HTMLParserScriptRunnerHost::trace(visitor);
}

void HTMLDocumentParser::detach() {
Expand Down Expand Up @@ -283,7 +284,7 @@ void HTMLDocumentParser::runScriptsForPausedTreeBuilder() {
m_treeBuilder->takeScriptToProcess(scriptStartPosition);
// We will not have a scriptRunner when parsing a DocumentFragment.
if (m_scriptRunner)
m_scriptRunner->execute(scriptElement, scriptStartPosition);
m_scriptRunner->processScriptElement(scriptElement, scriptStartPosition);
}

bool HTMLDocumentParser::canTakeNextToken() {
Expand Down
14 changes: 8 additions & 6 deletions third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include "core/html/parser/HTMLInputStream.h"
#include "core/html/parser/HTMLParserOptions.h"
#include "core/html/parser/HTMLParserReentryPermit.h"
#include "core/html/parser/HTMLParserScriptRunnerHost.h"
#include "core/html/parser/HTMLPreloadScanner.h"
#include "core/html/parser/HTMLScriptRunnerHost.h"
#include "core/html/parser/HTMLSourceTracker.h"
#include "core/html/parser/HTMLToken.h"
#include "core/html/parser/HTMLTokenizer.h"
Expand All @@ -60,16 +60,16 @@ class DocumentFragment;
class Element;
class HTMLDocument;
class HTMLParserScheduler;
class HTMLParserScriptRunner;
class HTMLPreloadScanner;
class HTMLResourcePreloader;
class HTMLScriptRunner;
class HTMLTreeBuilder;
class SegmentedString;
class TokenizedChunkQueue;
class DocumentWriteEvaluator;

class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser,
private HTMLScriptRunnerHost {
private HTMLParserScriptRunnerHost {
USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser);
USING_PRE_FINALIZER(HTMLDocumentParser, dispose);

Expand All @@ -95,7 +95,9 @@ class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser,
ParserContentPolicy = AllowScriptingContent);

// Exposed for testing.
HTMLScriptRunnerHost* asHTMLScriptRunnerHostForTesting() { return this; }
HTMLParserScriptRunnerHost* asHTMLParserScriptRunnerHostForTesting() {
return this;
}

HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); }

Expand Down Expand Up @@ -172,7 +174,7 @@ class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser,
void executeScriptsWaitingForResources() final;
void documentElementAvailable() override;

// HTMLScriptRunnerHost
// HTMLParserScriptRunnerHost
void notifyScriptLoaded(Resource*) final;
HTMLInputStream& inputStream() final { return m_input; }
bool hasPreloadScanner() const final {
Expand Down Expand Up @@ -249,7 +251,7 @@ class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser,

std::unique_ptr<HTMLToken> m_token;
std::unique_ptr<HTMLTokenizer> m_tokenizer;
Member<HTMLScriptRunner> m_scriptRunner;
Member<HTMLParserScriptRunner> m_scriptRunner;
Member<HTMLTreeBuilder> m_treeBuilder;

std::unique_ptr<HTMLPreloadScanner> m_preloadScanner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ TEST_F(HTMLDocumentParserTest, AppendPrefetch) {
const char bytes[] = "<ht";
parser->appendBytes(bytes, sizeof(bytes));
// The bytes are forwarded to the preload scanner, not to the tokenizer.
HTMLScriptRunnerHost* scriptRunnerHost =
parser->asHTMLScriptRunnerHostForTesting();
HTMLParserScriptRunnerHost* scriptRunnerHost =
parser->asHTMLParserScriptRunnerHostForTesting();
EXPECT_TRUE(scriptRunnerHost->hasPreloadScanner());
EXPECT_EQ(HTMLTokenizer::DataState, parser->tokenizer()->getState());
}
Expand All @@ -76,8 +76,8 @@ TEST_F(HTMLDocumentParserTest, AppendNoPrefetch) {
const char bytes[] = "<ht";
parser->appendBytes(bytes, sizeof(bytes));
// The bytes are forwarded to the tokenizer.
HTMLScriptRunnerHost* scriptRunnerHost =
parser->asHTMLScriptRunnerHostForTesting();
HTMLParserScriptRunnerHost* scriptRunnerHost =
parser->asHTMLParserScriptRunnerHostForTesting();
EXPECT_FALSE(scriptRunnerHost->hasPreloadScanner());
EXPECT_EQ(HTMLTokenizer::TagNameState, parser->tokenizer()->getState());
}
Expand Down
Loading

0 comments on commit 799df4e

Please sign in to comment.