Skip to content

Commit

Permalink
Fixes and cleanups to "current document readiness"
Browse files Browse the repository at this point in the history
* Explicitly call out to "update the current document readiness" when we want the side effects to happen.

* Do not fire readystatechange if the value does not actually change.

* Update the insertion point before firing readystatechange.

* Make parser-less documents not be a special case, because most of them end up calling "stop parsing" before any script runs anyway.

* Move everything related to current document readiness into the "Reporting document loading status" section.

Most of these are not observable, because script cannot run during the times when these values are changing. The exception is that we now update the insertion point before firing readystatechange, whereas the previous not-very-precise phrasing seemed to imply that you'd update the insertion point afterward.

The new order matches implementations, as seen from the test at web-platform-tests/wpt#28799.
  • Loading branch information
domenic committed May 4, 2021
1 parent 85cb202 commit 35532a8
Showing 1 changed file with 77 additions and 59 deletions.
136 changes: 77 additions & 59 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -4239,10 +4239,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<p>This specification does not specify precisely how XSLT processing interacts with the <span>HTML
parser</span> infrastructure (for example, whether an XSLT processor acts as if it puts any
elements into a <span>stack of open elements</span>). However, XSLT processors must <span>stop
parsing</span> if they successfully complete, and must set the <span>current document
readiness</span> first to "<code data-x="">interactive</code>"<!-- this synchronously fires an
event --> and then to "<code data-x="">complete</code>"<!-- this also synchronously fires an event
--> if they are aborted.</p>
parsing</span> if they successfully complete, and must <span>update the current document
readiness</span> first to "<code data-x="">interactive</code>" and then to "<code
data-x="">complete</code>" if they are aborted.</p>

<hr>

Expand Down Expand Up @@ -9383,10 +9382,11 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
file system for local files. If the last modification date and time are not known, the attribute
must return the current date and time in the above format.</p>

<hr>

</div>


<h4>Reporting document loading status</h4>

<dl class="domintro">

<dt><var>document</var> . <code subdfn data-x="dom-document-readyState">readyState</code></dt>
Expand All @@ -9408,26 +9408,58 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {

<div w-nodev>

<p>Each document has a <dfn>current document readiness</dfn>. When a <code>Document</code> object
is created, it must have its <span>current document readiness</span> set to the string "<code
data-x="">loading</code>" if the document is associated with an <span>HTML parser</span>, an
<span>XML parser</span>, or an XSLT processor, and to the string "<code data-x="">complete</code>"
otherwise. Various algorithms during page loading affect this value. When the value is set, the
user agent must <span>set the current document readiness</span> for the <code>Document</code> with
the given value.</p>
<p>Each <code>Document</code> has a <dfn>current document readiness</dfn>, a string, initially
"<code data-x="">complete</code>".</p>

<p>A <code>Document</code> is said to have an <dfn>active parser</dfn> if it is associated with an
<span>HTML parser</span> or an <span>XML parser</span> that has not yet been <span data-x="stop
parsing">stopped</span> or <span data-x="abort a parser">aborted</span>.</p>
<p class="note">For <code>Document</code> objects created via the <span
data-x="create-the-document-object">create and initialize a <code>Document</code> object</span>
algorithm, this will be immediately reset to "<code data-x="">loading</code>" before any script
can observe the value of <code data-x="dom-document-readyState">document.readyState</code>. This
default applies to other cases such as <span data-x="is initial about:blank">initial
<code>about:blank</code></span> <code>Document</code>s or <code>Document</code>s without a
<span data-x="concept-document-bc">browsing context</span>.</p>

<p>The <dfn attribute for="Document"><code
data-x="dom-document-readyState">readyState</code></dfn> IDL attribute must, on getting, return
the <span>current document readiness</span>.</p>
data-x="dom-document-readyState">readyState</code></dfn> getter steps are to return
<span>this</span>'s <span>current document readiness</span>.</p>

</div>
<p>To <dfn>update the current document readiness</dfn> for <code>Document</code>
<var>document</var> to <var>readinessValue</var>:</p>

<ol>
<li><p>If <var>document</var>'s <span>current document readiness</span> equals
<var>readinessValue</var>, then return.</p></li>

<h4>Reporting document loading status</h4>
<li>
<p>If <var>document</var> is associated with an <span>HTML parser</span>, then:</p>

<ol>
<li><p>Let <var>now</var> be the <span>current high resolution time</span> given
<var>document</var>'s <span>relevant global object</span>.</p></li>

<li><p>If <var>readinessValue</var> is "<code data-x="">complete</code>", and
<var>document</var>'s <span>load timing info</span>'s <span>DOM complete time</span> is 0, then
set <var>document</var>'s <span>load timing info</span>'s <span>DOM complete time</span> to
<var>now</var>.</p></li>

<li><p>Otherwise, if <var>readinessValue</var> is "<code data-x="">interactive</code>", and
<var>document</var>'s <span>load timing info</span>'s <span>DOM interactive time</span> is 0,
then set <var>document</var>'s <span>load timing info</span>'s <span>DOM interactive
time</span> to <var>now</var>.</p></li>
</ol>
</li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-readystatechange">readystatechange</code> at <var>document</var>.</p></li>
</ol>

<hr>

<p>A <code>Document</code> is said to have an <dfn>active parser</dfn> if it is associated with an
<span>HTML parser</span> or an <span>XML parser</span> that has not yet been <span data-x="stop
parsing">stopped</span> or <span data-x="abort a parser">aborted</span>.</p>

<hr>

<p>A <code>Document</code> has a <span>document load timing info</span> <dfn export
for="Document">load timing info</dfn>.</p>
Expand Down Expand Up @@ -9459,32 +9491,7 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
<dd><code>DOMHighResTimeStamp</code> values</dd>
</dl>

<p>To <dfn>set the current document readiness</dfn> for <code>Document</code> <var>document</var>
given <var>readinessValue</var>:</p>

<ol>
<li>
<p>If <var>document</var> is associated with an <span>HTML parser</span>, then:</p>

<ol>
<li><p>Let <var>now</var> be the <span>current high resolution time</span> given
<var>document</var>'s <span>relevant global object</span>.</p></li>

<li><p>If <var>readinessValue</var> is "<code data-x="">complete</code>", and
<var>document</var>'s <span>load timing info</span>'s <span>DOM complete time</span> is 0, then
set <var>document</var>'s <span>load timing info</span>'s <span>DOM complete time</span> to
<var>now</var>.</p></li>

<li><p>Otherwise, if <var>readinessValue</var> is "<code data-x="">interactive</code>", and
<var>document</var>'s <span>load timing info</span>'s <span>DOM interactive time</span> is 0,
then set <var>document</var>'s <span>load timing info</span>'s <span>DOM interactive
time</span> to <var>now</var>.</p></li>
</ol>
</li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-readystatechange">readystatechange</code> at <var>document</var>.</p></li>
</ol>
</div>


<h4><dfn>DOM tree accessors</dfn></h4>
Expand Down Expand Up @@ -86363,6 +86370,9 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
<li id="set-the-document's-address"><p>Set <var>document</var>'s <span
data-x="concept-document-url">URL</span> to <var>creationURL</var>.</p></li>

<li><p>Set <var>document</var>'s <span>current document readiness</span> to "<code
data-x="">loading</code>".</p></li>

<li><p>Set <var>document</var>'s <span data-x="concept-document-referrer-policy">referrer
policy</span> to the result of <span data-x="parse-referrer-policy-header">parsing the
`<code>Referrer-Policy</code>` header</span> of <var>navigationParams</var>'s <span
Expand Down Expand Up @@ -94026,11 +94036,18 @@ document.body.appendChild(frame)</code></pre>
end-of-file token). The encoding <span data-x="concept-encoding-confidence">confidence</span> is
<i>irrelevant</i>.</p></li>

<li><p>Set the <span>current document readiness</span> of <var>document</var> to "<code
data-x="">loading</code>".</p></li>
<li><p>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>

<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>
<li>
<p><span>Update the current document readiness</span> of <var>document</var> to "<code
data-x="">loading</code>".</p>

<p class="note">This causes a <code data-x="event-readystatechange">readystatechange</code>
event to fire, but the event is actually unobservable to author code, because of the previous
step which <span data-x="erase all event listeners and handlers">erased all event listeners and
handlers</span> that could observe it.</p>
</li>

<li><p>Return <var>document</var>.</p></li>
</ol>
Expand Down Expand Up @@ -112359,9 +112376,10 @@ document.body.appendChild(text);
<ol>
<!-- this happens as part of one of the tasks that runs the parser -->

<li><p>Set the <span>current document readiness</span> to "<code data-x="">interactive</code>"
<!-- this also immediately fires an event --> and the <span>insertion point</span> to
undefined.</p></li>
<li><p>Set the <span>insertion point</span> to undefined.</p></li>

<li><p><span>Update the current document readiness</span> to "<code
data-x="">interactive</code>".</p></li>

<li><p>Pop <em>all</em> the nodes off the <span>stack of open elements</span>.</p></li>

Expand Down Expand Up @@ -112424,8 +112442,8 @@ document.body.appendChild(text);
<code>Document</code>'s <span>relevant global object</span> to run the following substeps:</p>

<ol>
<li><p>Set the <span>current document readiness</span> to "<code data-x="">complete</code>"<!--
this also fires an event immediately during the task -->.</p></li>
<li><p><span>Update the current document readiness</span> to "<code
data-x="">complete</code>".</p></li>

<li>
<p><i>Load event</i>: If the <code>Document</code> object's <span
Expand Down Expand Up @@ -112485,13 +112503,13 @@ document.body.appendChild(text);
<li><p>Throw away any pending content in the <span>input stream</span>, and discard any future
content that would have been added to it.</p></li>

<li><p>Set the <span>current document readiness</span> to "<code data-x="">interactive</code>"<!--
this immediately fires an event -->.</p></li>
<li><p><span>Update the current document readiness</span> to "<code
data-x="">interactive</code>".</p></li>

<li><p>Pop <em>all</em> the nodes off the <span>stack of open elements</span>.</p></li>

<li><p>Set the <span>current document readiness</span> to "<code data-x="">complete</code>"<!--
this also immediately fires an event -->.</p></li>
<li><p><span>Update the current document readiness</span> to "<code
data-x="">complete</code>".</p></li>

<!-- anything else? this is things that happen when you call document.open() on a document that's
still being parsed, or when you navigate a document that's still parsing, or navigate the parent
Expand Down

0 comments on commit 35532a8

Please sign in to comment.