Skip to content

Commit 29c6fee

Browse files
TimothyGumustaqahmed
authored andcommitted
document.open() simplifications, part 1
In particular, removes the realm creation, document unloading, and tasks removal steps. Based on the work by Anne van Kesteren in whatwg#3651, but without the parts concerning the session history. Changes to that area will come later (see whatwg#3818). These changes allow us to remove several auxiliary concepts that only existed to support document.open(): - The recycle parameter to the "unload a Document" algorithm - The window parameter to the "set the active document" algorithm Tests: web-platform-tests/wpt#10773 Tests: web-platform-tests/wpt#10778 Tests: web-platform-tests/wpt#10815 Tests: web-platform-tests/wpt#10818 Fixes whatwg#1698. Fixes whatwg#3286. Fixes whatwg#3306. Closes whatwg#3665.
1 parent f400971 commit 29c6fee

File tree

1 file changed

+12
-79
lines changed

1 file changed

+12
-79
lines changed

source

+12-79
Original file line numberDiff line numberDiff line change
@@ -76882,14 +76882,11 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
7688276882

7688376883
<p class="note">In general, there is a 1-to-1 mapping from the <code>Window</code> object to the
7688476884
<code>Document</code> object, as long as the <code>Document</code> object has a <span
76885-
data-x="concept-document-bc">browsing context</span>. There are two exceptions. First, a
76885+
data-x="concept-document-bc">browsing context</span>. There is one exceptions. A
7688676886
<code>Window</code> can be reused for the presentation of a second <code>Document</code> in the
7688776887
same <span>browsing context</span>, such that the mapping is then 1-to-2. This occurs when a
7688876888
<span>browsing context</span> is <span data-x="navigate">navigated</span> from the initial
7688976889
<code>about:blank</code> <code>Document</code> to another, with <span>replacement enabled</span>.
76890-
Second, a <code>Document</code> can end up being reused for several <code>Window</code> objects
76891-
when the <code data-x="dom-document-open">document.open(<var>type</var>,
76892-
<var>replace</var>)</code> method is used, such that the mapping is then many-to-1.</p>
7689376890

7689476891
<p class="note">A <code>Document</code> does not necessarily have a <span
7689576892
data-x="concept-document-bc">browsing context</span> associated with it. In particular, data
@@ -76902,12 +76899,12 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
7690276899
discarded">discarded</span>.</p>
7690376900

7690476901
<p>To <dfn>set the active document</dfn> of a <span>browsing context</span>
76905-
<var>browsingContext</var> to a <code>Document</code> object <var>document</var>, optionally with
76906-
a <code>Window</code> object <var>window</var>, run these steps:</p>
76902+
<var>browsingContext</var> to a <code>Document</code> object <var>document</var>, run these
76903+
steps:</p>
7690776904

7690876905
<ol>
7690976906
<li>
76910-
<p>If <var>window</var> is not given, let <var>window</var> be <var>document</var>'s <span
76907+
<p>Let <var>window</var> be <var>document</var>'s <span
7691176908
data-x="concept-relevant-global">relevant global object</span>.</p>
7691276909

7691376910
<p class="&#x0058;&#x0058;&#x0058;">Per this standard <var>document</var> can be created before
@@ -78819,7 +78816,7 @@ callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span
7881978816
If the user <span>refused to allow the document to be unloaded</span>, then return.</p></li>
7882078817

7882178818
<li><p><span data-x="unload a document">Unload</span> <var>browsingContext</var>'s <span>active
78822-
document</span> with the <var>recycle</var> parameter set to false.</p></li>
78819+
document</span>.</p></li>
7882378820

7882478821
<li><p>Remove <var>browsingContext</var> from the user interface (e.g., close or hide its tab in
7882578822
a tabbed browser).</p></li>
@@ -80582,8 +80579,7 @@ interface <dfn>History</dfn> {
8058280579
unloaded</span>, then return.</p></li>
8058380580

8058480581
<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of the
80585-
<var>specified browsing context</var> with the <var>recycle</var> parameter
80586-
set to false.</p></li>
80582+
<var>specified browsing context</var>.</p></li>
8058780583

8058880584
</ol>
8058980585

@@ -82565,7 +82561,7 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
8256582561
<li>
8256682562

8256782563
<p><span data-x="unload a document">Unload</span> the <code>Document</code> object of the
82568-
<span>current entry</span>, with the <var>recycle</var> parameter set to false.</p>
82564+
<span>current entry</span>.</p>
8256982565

8257082566
<p>If this instance of the <span data-x="navigate">navigation</span> algorithm is canceled while
8257182567
this step is running the <span>unload a document</span> algorithm, then the <span>unload a
@@ -83494,7 +83490,6 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8349483490
<p>Things that can cause the page to be unsalvageable include:</p>
8349583491

8349683492
<ul class="brief">
83497-
<li><code data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code>
8349883493
<li>Listening for <code data-x="event-beforeunload">beforeunload</code> events
8349983494
<li>Listening for <code data-x="event-unload">unload</code> events
8350083495
<li>Having <code>iframe</code>s that are not salvageable
@@ -83612,12 +83607,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8361283607
</ol>
8361383608

8361483609
<p>To <dfn data-export="" data-x="unload a document" data-lt="unload a document">unload</dfn> a
83615-
<code>Document</code> <var>document</var>, given a boolean <var>recycle</var> and optionally a
83616-
<var>recursiveFlag</var>:</p>
83617-
83618-
<p class="note">The <var>recycle</var> argument indicates whether the <code>Document</code> object
83619-
is going to be reused; it is set by the <code
83620-
data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code> method.</p>
83610+
<code>Document</code> <var>document</var>, optionally given a <var>recursiveFlag</var>:</p>
8362183611

8362283612
<ol>
8362383613
<li><p>Increase the <span>event loop</span>'s <span>termination nesting level</span> by
@@ -83674,8 +83664,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8367483664

8367583665
<ol>
8367683666
<li><p><span data-x="unload a document">Unload</span> the <span>active document</span> of
83677-
<var>browsingContext</var> with the <var>recycle</var> parameter set to false, and the
83678-
<var>recursiveFlag</var> set.</p></li>
83667+
<var>browsingContext</var> with the <var>recursiveFlag</var> set.</p></li>
8367983668

8368083669
<li><p>If the <i data-x="concept-document-salvageable">salvageable</i> state of the
8368183670
<span>active document</span> of <var>browsingContext</var> is false, then set the
@@ -83684,9 +83673,8 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8368483673
</ol>
8368583674
</li>
8368683675

83687-
<li><p>If both <var>document</var>'s <i
83688-
data-x="concept-document-salvageable">salvageable</i> state and <var>recycle</var> are false,
83689-
then <span data-x="discard a document">discard</span><var>document</var>.</p></li>
83676+
<li><p>If <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
83677+
is false, then <span data-x="discard a document">discard</span><var>document</var>.</p></li>
8369083678
</ol>
8369183679
</li>
8369283680

@@ -91018,20 +91006,9 @@ document.body.appendChild(frame)</code></pre>
9101891006
<code>about:blank</code> <code>Document</code> created when <var>document</var>'s <span>browsing
9101991007
context</span> was <span data-x="creating a new browsing context">created</span>, and that
9102091008
<code>Document</code> object has never had the <span>unload a document</span> algorithm invoked
91021-
on it (e.g., by a previous call to <code
91022-
data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code>), then set
91023-
<var>replace</var> to true.</p>
91009+
on it, then set <var>replace</var> to true.</p>
9102491010
</li>
9102591011

91026-
<li><p>Set <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
91027-
to false.</p></li>
91028-
91029-
<li><p><span>Prompt to unload</span> <var>document</var>. If the user <span>refused to allow the
91030-
document to be unloaded</span>, then return <var>document</var>.</p></li>
91031-
91032-
<li><p><span data-x="unload a document">Unload</span> <var>document</var>, with the
91033-
<var>recycle</var> parameter set to true.</p></li>
91034-
9103591012
<li><p><span data-x="abort a document">Abort</span> <var>document</var>.</p></li>
9103691013

9103791014
<li><p>For each <span>shadow-including inclusive descendant</span> <var>node</var> of
@@ -91040,54 +91017,13 @@ document.body.appendChild(frame)</code></pre>
9104091017

9104191018
<li><p><span>Erase all event listeners and handlers</span> given <var>window</var>.</p></li>
9104291019

91043-
<li><p>Remove any <span data-x="concept-task">tasks</span> associated with <var>document</var> in
91044-
any <span>task source</span>.</p></li>
91045-
<!-- removes callbacks that fired between this algorithm starting and the times and databases
91046-
being aborted in the "unload" step above -->
91047-
9104891020
<li><p><span data-x="concept-node-replace-all">Replace all</span> with null within
9104991021
<var>document</var>, without firing any mutation events.</p></li>
9105091022

91051-
<li>
91052-
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
91053-
realm</span> with the following customizations:</p>
91054-
91055-
<ul>
91056-
<li><p>For the global object, create a new <code>Window</code> object and set
91057-
<var>window</var> to it.</p></li>
91058-
91059-
<li><p>For the global <b>this</b> binding, use <var>document</var>'s <span>browsing
91060-
context</span>'s associated <code>WindowProxy</code>.</p></li>
91061-
</ul>
91062-
91063-
<p class="&#x0058;&#x0058;&#x0058;">This is not universally implemented and can perhaps be
91064-
removed; see <a href="https://github.com/whatwg/html/issues/1698">issue #1698</a>.</p>
91065-
</li>
91066-
91067-
<li><p><span>Set up a window environment settings object</span> with <var>realm execution
91068-
context</var>.</p></li>
91069-
91070-
<li><p><span>Set the active document</span> of <var>document</var>'s <span>browsing
91071-
context</span> to <var>document</var> with <var>window</var>.</p></li>
91072-
91073-
<li><p>Replace <var>document</var>'s singleton objects with new instances of those objects,
91074-
created in <var>window</var>'s <span data-x="concept-global-object-realm">Realm</span>. (This
91075-
includes in particular the <code>History</code>, <code>ApplicationCache</code>, and
91076-
<code>Navigator</code>, objects, the various <code>BarProp</code> objects, the two
91077-
<code>Storage</code> objects, the various <code>HTMLCollection</code> objects, and objects
91078-
defined by other specifications, like <code>Selection</code>. It also includes all the Web IDL
91079-
prototypes in the JavaScript binding, including <var>document</var>'s prototype.)</p></li>
91080-
91081-
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20%7B%20f%20%3D%20document.getElementsByTagName('iframe')%5B0%5D%3B%20d%20%3D%20f.contentWindow.document%3B%20%7D%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cscript%3Evar%20x%20%3D%20new%20XMLHttpRequest()%3Bx.open(%26quot%3BGET%26quot%3B%2C%20%26quot%3BGET%26quot%3B)%3Bx.onreadystatechange%3Dfunction()%20%7B%20alert(x.readyState)%3B%20%7D%3Bx.send(null)%3B%3C%2Fscript%3E')%3Bd.close()%3B%20setTimeout(function()%20%7B%20d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%20%7D%2C%200)%3B%22%20value%3D%22xhr%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.onclick%20%3D%20function()%20%7B%20w('click')%20%7D%22%20value%3D%22add%20click%20handler%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setTimeout(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%202000)%3C%2Fscript%3E%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E -->
91082-
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0D%0A...%3Ciframe%3E%3C%2Fiframe%3E%0D%0A%3Cscript%3E%0D%0Aonload%20%3D%20function%20()%20%7B%0D%0A%20frames%5B0%5D.test%20%3D%201%0D%0A%20w(frames%5B0%5D.test)%3B%0D%0A%20var%20a%20%3D%20frames%5B0%5D.document.location.assign%3B%0D%0A%20w(a)%3B%0D%0A%20w(frames%5B0%5D.document.location.assign%20%3D%3D%3D%20a)%3B%0D%0A%20frames%5B0%5D.document.open()%3B%0D%0A%20frames%5B0%5D.document.write('%3Cscript%3Edocument.write(test)%3C%5C%2Fscript%3E')%3B%0D%0A%20frames%5B0%5D.document.close()%3B%0D%0A%20w(frames%5B0%5D.test)%3B%0D%0A%20w(frames%5B0%5D.document.location.assign%20%3D%3D%3D%20a)%3B%0D%0A%7D%0D%0A%3C%2Fscript%3E -->
91083-
9108491023
<li><p>If <var>document</var> is <span>ready for post-load tasks</span>, then set
9108591024
<var>document</var>'s <span>reload override flag</span> and set <var>document</var>'s
9108691025
<span>reload override buffer</span> to the empty string.</p></li>
9108791026

91088-
<li><p>Set <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
91089-
back to true.</p></li>
91090-
9109191027
<li><p>Change <var>document</var>'s <span data-x="concept-document-url">URL</span> to the
9109291028
<span data-x="concept-document-url">URL</span> of the <span>responsible document</span> specified
9109391029
by the <span>entry settings object</span>.</p></li>
@@ -91132,9 +91068,6 @@ document.body.appendChild(frame)</code></pre>
9113291068
<var>replace</var>)</code> call. This new entry does not have a <code>Document</code> object, so
9113391069
a new one will be created if the session history is traversed to that entry.</p></li>
9113491070

91135-
<li><p>Set <var>document</var>'s <span>fired unload</span> flag to false. (It could have been set
91136-
to true during the <span data-x="unload a document">unload</span> step above.)</p></li>
91137-
9113891071
<li><p>Finally, set the <span>insertion point</span> to point at just before the end of the
9113991072
<span>input stream</span> (which at this point will be empty).</p></li>
9114091073

0 commit comments

Comments
 (0)