document.write of scripts that also document.write sometimes writes async
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jul 2012 23:48:14 +0000 (23:48 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jul 2012 23:48:14 +0000 (23:48 +0000)
commitd154c8eb93a81a211850c575c20b86c55185013c
treeca278699384c643d1868902b2f9caaec924bc44d
parentda91fb4bfa627687e4d27dc0d8fa9653ebbe9bef
document.write of scripts that also document.write sometimes writes async
https://bugs.webkit.org/show_bug.cgi?id=89102

Reviewed by Adam Barth.

Source/WebCore:

When a script tag is first encountered, the TreeBuilder holds the element and returns
out to the outer HTMLDocumentParser parse loop.  The HTMLDocumentParser then takes
the script element and passes it to the HTMLScriptRunner for execution. However, if the
script is an "external script" the HTMLScriptRunner may have to wait for that parser
blocking script to load, and may store the script in its own m_parserBlockingScript member.

While the HTMLScriptRunner has this not-yet-loaded-script the parser is also blocked.
Because the "paused" state of the parser was held as a separate bool on the TreeBuilder
we'd have to be careful to update it to reflect the current state of this pending script
on the HTMLScriptRunner.

This patch removes this separate "paused" bool and makes the HTMLDocumentParser responsible
for the "paused" state of the parser through the isWaitingForScripts() function which
knows how to check both the TreeBuilder and the ScriptRunner for possible parser-blocking scripts.

I suspect this change may actually fix a bunch of edge cases where we were not
checking for the HTMLScriptRunner's parser blocking script and thus incorrectly ending
the parser, or not starting the pre-load scanner, etc.

As part of this change I also renamed m_haveParsingBlockingScript in HTMLScriptRunner to match
the naming style used elsewhere in the parser, as well as removed all the "bool" return values
for these parse/execute functions as they are no longer useful (or correct). The correct way
is always to check HTMLDocumentParser::isWaitingForScripts().

Test: fast/parser/cached-script-document-write.html

* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::pumpTokenizerIfPossible):
(WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder):
(WebCore::HTMLDocumentParser::canTakeNextToken):
(WebCore::HTMLDocumentParser::isWaitingForScripts):
(WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):
(WebCore::HTMLDocumentParser::notifyFinished):
(WebCore::HTMLDocumentParser::executeScriptsWaitingForStylesheets):
* html/parser/HTMLScriptRunner.cpp:
(WebCore::HTMLScriptRunner::~HTMLScriptRunner):
(WebCore::HTMLScriptRunner::executeParsingBlockingScript):
(WebCore::HTMLScriptRunner::execute):
(WebCore::HTMLScriptRunner::hasParserBlockingScript):
(WebCore::HTMLScriptRunner::executeParsingBlockingScripts):
(WebCore::HTMLScriptRunner::executeScriptsWaitingForLoad):
(WebCore::HTMLScriptRunner::executeScriptsWaitingForParsing):
(WebCore::HTMLScriptRunner::requestParsingBlockingScript):
(WebCore::HTMLScriptRunner::runScript):
* html/parser/HTMLScriptRunner.h:
(HTMLScriptRunner):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::takeScriptToProcess):
(WebCore::HTMLTreeBuilder::processEndTag):
(WebCore::HTMLTreeBuilder::processTokenInForeignContent):
* html/parser/HTMLTreeBuilder.h:
(HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::hasParserBlockingScript):

LayoutTests:

* fast/parser/cached-script-document-write-expected.txt: Added.
* fast/parser/cached-script-document-write.html: Added.
* fast/parser/resources/cached-script-document-write.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122168 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/parser/cached-script-document-write-expected.txt [new file with mode: 0644]
LayoutTests/fast/parser/cached-script-document-write.html [new file with mode: 0644]
LayoutTests/fast/parser/resources/cached-script-document-write.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLDocumentParser.cpp
Source/WebCore/html/parser/HTMLDocumentParser.h
Source/WebCore/html/parser/HTMLScriptRunner.cpp
Source/WebCore/html/parser/HTMLScriptRunner.h
Source/WebCore/html/parser/HTMLTreeBuilder.cpp
Source/WebCore/html/parser/HTMLTreeBuilder.h