document.open doesn't clear the document
Categories
(Core :: DOM: Core & HTML, defect, P5)
Tracking
()
People
(Reporter: ap, Assigned: bzbarsky)
References
()
Details
(Keywords: html5, testcase)
Attachments
(4 files)
Reporter | ||
Comment 1•19 years ago
|
||
Comment 2•19 years ago
|
||
Updated•19 years ago
|
Comment 3•19 years ago
|
||
Comment 4•17 years ago
|
||
Assignee | ||
Comment 6•16 years ago
|
||
Assignee | ||
Comment 7•16 years ago
|
||
Updated•15 years ago
|
Comment 8•6 years ago
|
||
Assignee | ||
Comment 9•6 years ago
|
||
Hmm. The behavior of Gecko after bug 1489308 does not match the behavior of Chrome on attachment 210306 [details]. As far as I can tell, Gecko is following the spec as currently written. What is Chrome doing? Timothy, do you know?
Comment 10•6 years ago
|
||
Some digging around shows that Blink clears the parser in document.close()
, allowing a subsequent synchronous document.open()
to work. This behavior was in fact inherited from a 2003 change in WebKit, and probably the cause of this longstanding bug.
I was not aware of this behavior difference (as I focused mostly on document.open()
itself), but it might worth filing an HTML bug about it. Boris, would implementing the behavior I just described in Gecko be feasible?
Assignee | ||
Comment 11•6 years ago
|
||
The issue is that not that document.open()
works after document.close()
. That part is interoperable across browsers. The issue is that in Blink it looks like this loop:
for (i = 0; i < 5; i++) {
document.open();
document.write("There should be only one line of text.<br>");
}
ends up resetting the DOM on each open()
call, even though there is a parser (the one the previous open()
call set up!), so the end result only has one line of text in the DOM, not 5 lines. This seems like squarely an issue of what document.open()
does in Blink, as far as I can tell.
Comment 12•6 years ago
|
||
Oh oops, let's try this once more.
The document open steps say:
- If document has an active parser whose script nesting level is greater than 0, then return document.
…
- Create a new HTML parser and associate it with document.
The definition of script nesting level says:
parsers have a script nesting level, which must be initially set to zero
In the for
-loop, after the document.open()
call, a new parser is created. However, when a parser is created, the script nesting level is (re)set to zero, only to be in/decremented when <script>
tags are seen in the parsed HTML text. So when the next document.open()
call executes, it would see an HTML parser that is not running script, and thus overwrite it.
Indeed, if I try to call document.open()
again in the document.write()
call in a <script>
tag, like
function mainFunc() {
document.open();
document.write("will not be visible<br>");
document.close();
for (i = 0; i < 5; i++) {
document.open();
document.write(`
There should be two lines of text.<br>
<script>
document.open();
document.write('extra');
</${''}script>
`);
}
}
Chrome ignores the extra document.open()
calls and print both “There should be two lines of text” and “extra”.
Assignee | ||
Comment 13•6 years ago
|
||
Ah, I see.
Henri, does our parser have this concept of "script nesting level" at all?
It sounds like there are no web platform tests for this script nesting level bit, unfortunately... :(
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #13)
Henri, does our parser have this concept of "script nesting level" at all?
I think https://searchfox.org/mozilla-central/rev/e7d9a8749303b39dadcc0e18ea0d60a570a68145/parser/html/nsHtml5Parser.h#280 is it, and the naming mismatch is thanks to the counter having been named according to previous spec concept. That is, I think I figured that a counter is needed when the spec didn't say it that way and once the spec agreed, it changed the terminology.
Assignee | ||
Comment 15•6 years ago
|
||
It sounds like there are no web platform tests for this script nesting level bit, unfortunately... :(
Yep, definitely no tests, in that fixing this bug does not lead to any changes in wpt results. Need to write some tests...
Assignee | ||
Comment 16•6 years ago
|
||
This also exposes an accessor for whether the parser has a nonzero script nesting level.
Assignee | ||
Comment 17•6 years ago
|
||
Comment 18•6 years ago
|
||
Comment 19•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/990c8a382cf3
https://hg.mozilla.org/mozilla-central/rev/264fe248bca5
Updated•6 years ago
|
Assignee | ||
Comment 20•6 years ago
|
||
I backed out part 2 to fix bug 1550524. I'll reland it, along with fixes for bug 1550524, after the next branchpoint.
Assignee | ||
Updated•6 years ago
|
Updated•6 years ago
|
Comment 23•5 years ago
|
||
Comment 24•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Description
•