Skip to content

Commit

Permalink
document.open() simplifications, part 2
Browse files Browse the repository at this point in the history
The current behavior of adding a new entry to the session history is
removed, with the "replace" parameter behavior made the only option. To
fix whatwg#3885, we now reuse history.replaceState()'s history model, which
keeps the document's URL and the history entry URL in sync.

At the same time, we restrict the history state update (including
setting the document's URL) to be only run with fully active documents.
Firefox already bails out for non-fully active documents (including
those that are active documents), and it's not expected that there would
be much usage of the URL of non-fully active documents anyway.

This allows us to additionally remove the seldom implemented "replace"
parameter in document.open(), whose behavior is now the default
(aligning with with Chrome and Safari). The IDL is modified accordingly.

This PR also removes the "overridden reload" algorithm and related
concepts, which were previously only implemented in Firefox and Edge,
causing developer confusion evident in
https://bugzilla.mozilla.org/show_bug.cgi?id=556002.

Tests: web-platform-tests/wpt#12555
Tests: … (more coming soon)

Fixes whatwg#3564.
Fixes whatwg#3885.
  • Loading branch information
TimothyGu committed Aug 21, 2018
1 parent 8dfc827 commit 19b17d6
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -9167,7 +9167,7 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
readonly attribute <span>HTMLOrSVGScriptElement</span>? <span data-x="dom-document-currentScript">currentScript</span>; // classic scripts in a document tree only

// <span>dynamic markup insertion</span>
[<span>CEReactions</span>] <span>Document</span> <span data-x="dom-document-open">open</span>(optional DOMString type, optional DOMString replace = ""); // type is ignored
[<span>CEReactions</span>] <span>Document</span> <span data-x="dom-document-open">open</span>(optional DOMString type, optional DOMString replace); // both type and replace are ignored
<span>WindowProxy</span> <span data-x="dom-document-open-window">open</span>(USVString url, DOMString name, DOMString features);
[<span>CEReactions</span>] void <span data-x="dom-document-close">close</span>();
[<span>CEReactions</span>] void <span data-x="dom-document-write">write</span>(DOMString... text);
Expand Down Expand Up @@ -90914,8 +90914,7 @@ document.body.appendChild(frame)</code></pre>
unloaded</span>. Initially, the counter must be set to zero.</p> <!--
https://www.hixie.ch/tests/adhoc/dom/level0/document/open/unload/ -->

<p>The <dfn>document open steps</dfn>, given a <var>document</var> and <var>replaceInput</var>,
are as follows:</p>
<p>The <dfn>document open steps</dfn>, given a <var>document</var>, are as follows:</p>

<ol>
<li><p>If <var>document</var> is an <span data-x="XML documents">XML document</span>, then throw
Expand Down Expand Up @@ -90957,20 +90956,6 @@ document.body.appendChild(frame)</code></pre>
handler while the <code>Document</code> is being unloaded.</p>
</li>

<li><p>Let <var>replace</var> be false.

<li>
<p>If <var>replaceInput</var> is an <span>ASCII case-insensitive</span> match for "<code
data-x="">replace</code>", then set <var>replace</var> to true.</p>

<p>Otherwise, if <var>document</var>'s <span>browsing context</span>'s <span>session
history</span> contains only one <code>Document</code> object, and that was the
<code>about:blank</code> <code>Document</code> created when <var>document</var>'s <span>browsing
context</span> was <span data-x="creating a new browsing context">created</span>, and that
<code>Document</code> object has never had the <span>unload a document</span> algorithm invoked
on it, then set <var>replace</var> to true.</p>
</li>

<li><p><span data-x="abort a document">Abort</span> <var>document</var>.</p></li>

<li><p>For each <span>shadow-including inclusive descendant</span> <var>node</var> of
Expand All @@ -90982,9 +90967,10 @@ document.body.appendChild(frame)</code></pre>
<li><p><span data-x="concept-node-replace-all">Replace all</span> with null within
<var>document</var>, without firing any mutation events.</p></li>

<li><p>Change <var>document</var>'s <span data-x="concept-document-url">URL</span> to the
<span data-x="concept-document-url">URL</span> of the <span>responsible document</span> specified
by the <span>entry settings object</span>.</p></li>
<li><p>If <var>document</var> is <span>fully active</span>, then run the <span>history state
update steps</span> with <var>document</var> and the <span
data-x="concept-document-url">URL</span> of the <span>responsible document</span> specified by
the <span>entry settings object</span>.</p></li>

<!-- <span>the document's referrer</span> stays the same -->

Expand Down Expand Up @@ -91018,14 +91004,6 @@ document.body.appendChild(frame)</code></pre>
<li><p>Remove any earlier entries whose <code>Document</code> object is
<var>document</var>.</p></li>

<li><p>If <var>replace</var> is false, then add a new entry, just before the last entry,
and associate with the new entry the text that was parsed by the previous parser associated with
<var>document</var>, as well as the state of <var>document</var> at the start of these steps.
This allows the user to step backwards in the session history to see the page before it was blown
away by the <code data-x="dom-document-open">document.open(<var>type</var>,
<var>replace</var>)</code> call. This new entry does not have a <code>Document</code> object, so
a new one will be created if the session history is traversed to that entry.</p></li>

<li><p>Finally, set the <span>insertion point</span> to point at just before the end of the
<span>input stream</span> (which at this point will be empty).</p></li>

Expand All @@ -91034,7 +91012,7 @@ document.body.appendChild(frame)</code></pre>

<p>The <dfn data-x="dom-document-open"><code>open(<var>type</var>,
<var>replace</var>)</code></dfn> method must return the result of running the <span>document open
steps</span> with this <code>Document</code> object and <var>replace</var>.
steps</span> with this <code>Document</code> object.

<p class="note">The <var>type</var> argument is ignored. Also, the <code
data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code> method does
Expand Down Expand Up @@ -91184,9 +91162,9 @@ document.body.appendChild(frame)</code></pre>
0 or <var>document</var>'s <span>ignore-destructive-writes counter</span> is greater than 0,
then return.</p></li>

<li><p>Run the <span>document open steps</span> with <var>document</var> and the empty string.
If the user <span>refused to allow the document to be unloaded</span>, then return. Otherwise,
the <span>insertion point</span> will point at just before the end of the (empty) <span>input
<li><p>Run the <span>document open steps</span> with <var>document</var>. If the user
<span>refused to allow the document to be unloaded</span>, then return. Otherwise, the
<span>insertion point</span> will point at just before the end of the (empty) <span>input
stream</span>.</p></li>
</ol>
</li>
Expand Down

0 comments on commit 19b17d6

Please sign in to comment.