RESOLVED FIXED Bug 40047
document.write is not synchronous when using the HTML5 parser
https://bugs.webkit.org/show_bug.cgi?id=40047
Summary document.write is not synchronous when using the HTML5 parser
Eric Seidel (no email)
Reported 2010-06-02 00:03:07 PDT
REGRESSION(60409): document.write is not synchronous when using the HTML5 parser It's unclear from the spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#document.write() But it seems to me that document.write() should wait until all parsing is "done" for the write before returning. In the old parser this was not an issue, as it was not as aggressive about yielding. The new HTML5 parser yields when waiting for script loads or for stylesheet loads. http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#running-a-script talks about queuing tasks on the task queue, but it doesn't really talk about the parser yielding. The old parser never seems to wait for <script src=""> tags during parsing (in violation of HTML5) nor does it block inline <script> tags ever (which HTML5 says it should for style-sheets), so I think that's how it produces a synchronous document.write behavior.
Attachments
Patch (3.29 KB, patch)
2010-06-02 01:09 PDT, Eric Seidel (no email)
no flags
Patch for landing (3.22 KB, patch)
2010-06-02 01:25 PDT, Eric Seidel (no email)
no flags
Patch for landing (3.28 KB, patch)
2010-06-02 14:07 PDT, Eric Seidel (no email)
no flags
Eric Seidel (no email)
Comment 1 2010-06-02 00:05:53 PDT
http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-incdata Talks about: Spin the event loop until there is no style sheet blocking scripts and the script's "ready to be parser-executed" flag is set. Which may be what we need to do when the parser is supposed to be synchronous (like for document.write).
Eric Seidel (no email)
Comment 2 2010-06-02 00:30:38 PDT
I've tested and confirmed: The old parser does not block document.write() for <script src> loads, however it won't actually process any contents of the write (or future writes) after the <script src> until that script has loaded. I think the easiest way out of this is to remove the blocking of inline <script> tags on stylesheet loads. To do so, we'd probably have to spin the event loop inside the parser like recommend by the HTML5 spec. I don't really want to write that code (I am not even sure it's possible to spin the event loop from WebCore). I think that's something we can deal with after we turn the HTML5 parser on as the default parser.
Eric Seidel (no email)
Comment 3 2010-06-02 01:09:38 PDT
Adam Barth
Comment 4 2010-06-02 01:21:07 PDT
Comment on attachment 57632 [details] Patch WebCore/html/HTML5ScriptRunner.cpp:244 + // m_parsingBlockingScript.element = script; Commented out code! :(
Eric Seidel (no email)
Comment 5 2010-06-02 01:25:36 PDT
Created attachment 57633 [details] Patch for landing
WebKit Commit Bot
Comment 6 2010-06-02 03:58:43 PDT
Comment on attachment 57633 [details] Patch for landing Rejecting patch 57633 from commit-queue. Failed to run "[u'/Users/eseidel/Projects/CommitQueue/WebKitTools/Scripts/svn-apply', u'--force']" exit_code: 1 Parsed 2 diffs from patch file(s). patching file WebCore/ChangeLog Hunk #1 succeeded at 1 with fuzz 3. patching file WebCore/html/HTML5ScriptRunner.cpp Hunk #2 FAILED at 238. 1 out of 2 hunks FAILED -- saving rejects to file WebCore/html/HTML5ScriptRunner.cpp.rej Full output: http://webkit-commit-queue.appspot.com/results/2812104
Henri Sivonen
Comment 7 2010-06-02 04:54:01 PDT
(In reply to comment #2) > I think the easiest way out of this is to remove the blocking of inline <script> tags on stylesheet loads. It seems to me that it would be sufficient to make document.written inline scripts not wait on network loads of any kind. By inspection, it seems to me that Gecko isn't spec-compliant here. I intend to file a spec bug.
Alexey Proskuryakov
Comment 8 2010-06-02 13:51:41 PDT
Since this isn't an issue in any production (or nightly) configuration, I've removed the REGRESSION prefix. Please let me know if this is a problem for your workflow.
Eric Seidel (no email)
Comment 9 2010-06-02 14:07:18 PDT
Created attachment 57701 [details] Patch for landing
WebKit Commit Bot
Comment 10 2010-06-02 22:25:24 PDT
Comment on attachment 57701 [details] Patch for landing Clearing flags on attachment: 57701 Committed r60606: <http://trac.webkit.org/changeset/60606>
WebKit Commit Bot
Comment 11 2010-06-02 22:25:32 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.