Skip to content

Commit

Permalink
Tweak "is unloading" in navigation
Browse files Browse the repository at this point in the history
This replaces vague text about "if the prompt to unload algorithm is being run" and the like for "unload" with an explicit check of the "unload counter". The "unload counter" is a rename of the "ignore-opens-during-unload counter", which was already used for similar explicit checks in document.open().

This results in the same check being done everywhere, which appears to match at least some implementations better. Previously, for example, "traverse the history by a delta" did not check for beforeunload, only unload.
  • Loading branch information
domenic authored May 10, 2021
1 parent 4d262ae commit e85177a
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -84029,8 +84029,8 @@ interface <dfn>History</dfn> {
<li><p>If <var>source browsing context</var> is not <span>allowed to navigate</span>
<var>specified browsing context</var>, then return.</p></li>

<li><p>If the <var>specified browsing context</var>'s <span>active document</span>'s
<span>unload a document</span> algorithm is currently running, return.</p></li>
<li><p>If the <var>specified browsing context</var>'s <span>active document</span>'s <span>unload
counter</span> is greater than 0, then return.</p></li>

<li>
<p><span>Queue a global task</span> on the <span>history traversal task source</span> given
Expand Down Expand Up @@ -85450,20 +85450,13 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
</ol>
</li>

<li><p>If there is a preexisting attempt to navigate <var>browsingContext</var>, and the
<span>source browsing context</span> is the same as <var>browsingContext</var>, and that attempt
is currently running the <span>unload a document</span> algorithm, then return without
affecting the preexisting attempt to navigate <var>browsingContext</var>.</p></li>
<li><p>If <var>browsingContext</var>'s <span>active document</span>'s <span>unload counter</span>
is greater than 0, then return.</p></li>
<!--
this stops pages from hijacking the back/forward button, among other things
https://www.hixie.ch/tests/adhoc/html/navigation/unload/
https://github.com/whatwg/html/issues/1213
-->

<li><p>If the <span>prompt to unload</span> algorithm is being run for the <span>active
document</span> of <var>browsingContext</var>, then return without affecting the
<span>prompt to unload</span> algorithm.</p></li>
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1946 to 1955 -->
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1946 to 1955 -->

<li id="navigate-fragid-step">
<p>If <var>historyHandling</var> is not "<code data-x="hh-reload">reload</code>",
Expand Down Expand Up @@ -87677,15 +87670,18 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<p><span data-x="event loop">Event loops</span> have a <dfn>termination nesting level</dfn>
counter, which must initially be 0.</p>

<p id="ignore-opens-during-unload-counter"><code>Document</code> objects have an <dfn>unload
counter</dfn>, which is used to ignore certain operations while the below algorithms run.
Initially, the counter must be set to zero.</p>

<p>To <dfn id="prompt-to-unload-a-document">prompt to unload</dfn>, given a <code>Document</code>
object <var>document</var> and optionally a <var>recursiveFlag</var>, run these steps:</p>

<ol>
<li><p>Increase the <span>event loop</span>'s <span>termination nesting level</span> by
1.</p></li>

<li><p>Increase the <var>document</var>'s <span>ignore-opens-during-unload counter</span> by
1.</p></li>
<li><p>Increase the <var>document</var>'s <span>unload counter</span> by 1.</p></li>

<li><p>Let <var>event</var> be the result of <span>creating an event</span> using
<code>BeforeUnloadEvent</code>.</p></li>
Expand Down Expand Up @@ -87753,8 +87749,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
</ol>
</li>

<li><p>Decrease the <var>document</var>'s <span>ignore-opens-during-unload counter</span> by
1.</p></li>
<li><p>Decrease the <var>document</var>'s <span>unload counter</span> by 1.</p></li>
</ol>

<p>To <dfn export data-x="unload a document" data-lt="unload a document">unload</dfn> a
Expand All @@ -87765,8 +87760,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<li><p>Increase the <span>event loop</span>'s <span>termination nesting level</span> by
one.</p></li>

<li><p>Increase <var>document</var>'s <span>ignore-opens-during-unload counter</span> by
one.</p></li>
<li><p>Increase <var>document</var>'s <span>unload counter</span> by 1.</p></li>

<li><p>If <var>document</var>'s <span>page showing</span> flag is false, then jump to the
step labeled <i>unload event</i> below (i.e. skip firing the <code
Expand Down Expand Up @@ -87841,8 +87835,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
</ol>
</li>

<li><p>Decrease <var>document</var>'s <span>ignore-opens-during-unload counter</span> by
one.</p></li>
<li><p>Decrease <var>document</var>'s <span>unload counter</span> by 1.</p></li>
</ol>

<p>This specification defines the following <dfn export>unloading document cleanup steps</dfn>.
Expand Down Expand Up @@ -87965,8 +87958,8 @@ interface <dfn>BeforeUnloadEvent</dfn> : <span>Event</span> {
data-x="concept-document-bc">browsing context</span>.</p></li>

<li><p>If there is an existing attempt to <span>navigate</span> <var>browsingContext</var> and
that attempt is not currently running the <span>unload a document</span> algorithm, then cancel
that <span data-x="navigate">navigation</span>.</p></li>
<var>document</var>'s <span>unload counter</span> is 0, then cancel that <span
data-x="navigate">navigation</span>.</p></li>

<li><p><span data-x="abort a document">Abort</span> <var>document</var>.</p></li>
</ol>
Expand Down Expand Up @@ -94000,11 +93993,6 @@ document.body.appendChild(frame)</code></pre>

<div w-nodev>

<p><code>Document</code> objects have an <dfn>ignore-opens-during-unload counter</dfn>, which is
used to prevent scripts from invoking the <code data-x="dom-document-open">document.open()</code>
method (directly or indirectly) while the document is <span data-x="unload a document">being
unloaded</span>. Initially, the counter must be set to zero.</p>

<p><code>Document</code> objects have an <dfn>active parser was aborted</dfn> boolean, which is
used to prevent scripts from invoking the <code data-x="dom-document-open">document.open()</code>
and <code data-x="dom-document-write">document.write()</code> methods (directly or indirectly)
Expand Down Expand Up @@ -94038,8 +94026,8 @@ document.body.appendChild(frame)</code></pre>
</li>

<li>
<p>Similarly, if <var>document</var>'s <span>ignore-opens-during-unload counter</span> is
greater than 0, then return <var>document</var>.</p>
<p>Similarly, if <var>document</var>'s <span>unload counter</span> is greater than 0, then
return <var>document</var>.</p>

<p class="note">This basically causes <code data-x="dom-document-open">document.open()</code> to
be ignored when it's called from a <code data-x="event-beforeunload">beforeunload</code>, <code
Expand Down Expand Up @@ -94278,9 +94266,9 @@ document.body.appendChild(frame)</code></pre>
<p>If the <span>insertion point</span> is undefined, then:

<ol>
<li><p>If <var>document</var>'s <span>ignore-opens-during-unload counter</span> is greater than
0 or <var>document</var>'s <span>ignore-destructive-writes counter</span> is greater than 0,
then return.</p></li>
<li><p>If <var>document</var>'s <span>unload counter</span> is greater than 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>.</p></li>
</ol>
Expand Down

0 comments on commit e85177a

Please sign in to comment.