Skip to content

Commit

Permalink
fixup: ResumeParsingAfterPause's PumpTokenizer behaviour
Browse files Browse the repository at this point in the history
Several possibilities entering this function:
1) We're parsing with kForceSynchronousParsing (no background parser,
   tokenizer_ defined)
2) We're parsing with kAllowAsynchronousParsing without a background
   parser started (no tokenizer_)
3) We're parsing with kAllowAsynchronousParsing _with_ a background
   parser started (no tokenizer_)
4) We're parsing with kAllowDeferredParsing (with tokenizer_)

The previous code called PumpTokenizerIfPossible _only_ if tokenizer_,
wasn't defined, so the implication is that this operation should be
done synchronously and only if the background parser isn't being used.
The new code either pumped the tokenizer immediately, or deferred
the pump. This CL restores the previous behaviour.

Bug: 901056, 1087032, 1087325, 1087753
Change-Id: I7ed8ee0eea91eb7786e07a82b399f40f0c651dbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2235836
Commit-Queue: Richard Townsend <richard.townsend@arm.com>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777296}
  • Loading branch information
richard-townsend-arm authored and Commit Bot committed Jun 11, 2020
1 parent 71d1d12 commit cee0a2e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions third_party/blink/renderer/core/html/parser/html_document_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,16 @@ bool HTMLDocumentParser::IsWaitingForScripts() const {
}

void HTMLDocumentParser::ResumeParsingAfterPause() {
// This function runs after a parser-blocking script has completed. There are
// four possible cases:
// 1) Parsing with kForceSynchronousParsing, where there is no background
// parser and a tokenizer_'s defined.
// 2) Parsing with kAllowAsynchronousParsing, without a background parser. In
// this case, the document is usually being completed or parsing has
// otherwise stopped.
// 3) Parsing with kAllowAsynchronousParsing with a background parser. In this
// case, need to add any pending speculations to the document.
// 4) Parsing with kAllowDeferredParsing, with a tokenizer_.
TRACE_EVENT1("blink", "HTMLDocumentParser::ResumeParsingAfterPause", "parser",
(void*)this);
DCHECK(!IsExecutingScript());
Expand All @@ -1299,7 +1309,7 @@ void HTMLDocumentParser::ResumeParsingAfterPause() {
if (IsStopped() || IsPaused())
return;

if (have_background_parser_) {
if (have_background_parser_) { // Case 3)
// If we paused in the middle of processing a token chunk,
// deal with that before starting to pump.
if (last_chunk_before_pause_) {
Expand All @@ -1312,28 +1322,21 @@ void HTMLDocumentParser::ResumeParsingAfterPause() {
PumpPendingSpeculations();
}
return;
} else if (!tokenizer_) {
// Attempted fix for test_installer failures. Appears that
// HTMLDocumentParser::ExecuteScriptsWaitingForResources is queued from a
// callback tasks, which calls this, possibly after Detach.
DCHECK(!token_);
token_ = std::make_unique<HTMLToken>();
tokenizer_ = std::make_unique<HTMLTokenizer>(options_);
}

insertion_preload_scanner_.reset();
task_runner_state_->SetEndIfDelayed(true);
if (task_runner_state_->GetMode() !=
ParserSynchronizationPolicy::kAllowDeferredParsing) {
if (tokenizer_) {
// Case 1) or 4): kForceSynchronousParsing, kAllowDeferredParsing.
// kForceSynchronousParsing must pump the tokenizer synchronously.
// kDeferredParsing could (theoretically) defer the tokenizer pump.
// TODO(Richard.Townsend@arm.com) investigate this.
task_runner_state_->SetEndIfDelayed(true);
task_runner_state_->SetShouldComplete(true);
PumpTokenizerIfPossible();
} else {
DCHECK(RuntimeEnabledFeatures::ForceSynchronousHTMLParsingEnabled());
loading_task_runner_->PostTask(
FROM_HERE,
WTF::Bind(&HTMLDocumentParser::DeferredPumpTokenizerIfPossible,
WrapPersistent(this)));
task_runner_state_->SetState(
HTMLDocumentParserState::DeferredParserState::kScheduled);
// Case 2): kAllowAsynchronousParsing, no background parser available
// (indicating possible Document shutdown).
EndIfDelayed();
}
}

Expand Down

0 comments on commit cee0a2e

Please sign in to comment.