Skip to content

Commit

Permalink
Be clearer about documents in script execution
Browse files Browse the repository at this point in the history
The only normative change here is to delay the load event of the script's preparation-time document, instead of its node document (which could change while the fetching is in progress). Closes #5160.

Otherwise, this consists of cleanups to use more precise language for certain documents, thus closing #7589, and of the pending parsing-blocking script concept to use more imperative language.
  • Loading branch information
domenic authored Apr 26, 2022
1 parent c795467 commit 60a9ea1
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -60100,7 +60100,7 @@ o............A....e
data-x="concept-script">script</span> in the case of success or to null in the case of failure,
the fetching algorithms will note that <dfn>the script is ready</dfn>, which can trigger other
actions. <!-- similar text in various places --> The user agent must <span>delay the load
event</span> of the element's <span>node document</span> until <span>the script is
event</span> of the element's <span>preparation-time document</span> until <span>the script is
ready</span>.</p>

<hr>
Expand Down Expand Up @@ -60467,8 +60467,7 @@ o............A....e

<dd>
<p>Add the element to the end of the <dfn>list of scripts that will execute when the document
has finished parsing</dfn> associated with the <code>Document</code> of the parser that
created the element.</p>
has finished parsing</dfn> associated with the element's <span>parser document</span>.</p>

<p>When <span>the script is ready</span>, set the element's <span>"ready to be
parser-executed"</span> flag. The parser will handle executing the script.</p>
Expand All @@ -60481,9 +60480,8 @@ o............A....e
data-x="attr-script-async">async</code> attribute</dt>

<dd>
<p>The element is the <span>pending parsing-blocking script</span> of the
<code>Document</code> of the parser that created the element. (There can only be one such
script per <code>Document</code> at a time.)</p>
<p>Set the element's <span>parser document</span>'s <span>pending parsing-blocking
script</span> to the element.</p>

<p><span>Block rendering</span> on the element.</p>

Expand Down Expand Up @@ -60553,8 +60551,8 @@ o............A....e
a style sheet that is blocking scripts</span></dt>

<dd>
<p>The element is the <span>pending parsing-blocking script</span> of its <span>parser
document</span>. (There can only be one such script per <code>Document</code> at a time.)</p>
<p>Set the element's <span>parser document</span>'s <span>pending parsing-blocking
script</span> to the element.</p>

<p>Set the element's <span>"ready to be parser-executed"</span> flag. The parser will handle
executing the script.</p>
Expand All @@ -60569,8 +60567,8 @@ o............A....e
</li>
</ol>

<p>The <dfn>pending parsing-blocking script</dfn> of a <code>Document</code> is used by the
<code>Document</code>'s parser(s).</p>
<p>Each <code>Document</code> has a <dfn>pending parsing-blocking script</dfn>, which is either a
<code>script</code> element or null (initially null).</p>

<p class="note">If a <code>script</code> element that blocks a parser gets moved to another
<code>Document</code> before it would normally have stopped blocking that parser, it nonetheless
Expand Down Expand Up @@ -98084,21 +98082,21 @@ document.body.appendChild(frame)</code></pre>
steps:</p>

<ol>
<li><p>If the <code>Document</code> object is an <span data-x="XML documents">XML
document</span>, then throw an <span>"<code>InvalidStateError</code>"</span>
<code>DOMException</code>.</p></li>
<li><p>If <span>this</span> is an <span data-x="XML documents">XML document</span>, then throw
an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>If the <code>Document</code> object's <span>throw-on-dynamic-markup-insertion
counter</span> is greater than zero, then throw an <span>"<code>InvalidStateError</code>"</span>
<li><p>If <span>this</span>'s <span>throw-on-dynamic-markup-insertion counter</span> is greater
than zero, then throw an <span>"<code>InvalidStateError</code>"</span>
<code>DOMException</code>.</p></li>

<li><p>If there is no <span>script-created parser</span> associated with the document, then
<li><p>If there is no <span>script-created parser</span> associated with <span>this</span>, then
return.</p></li>

<li><p>Insert an <span>explicit "EOF" character</span> at the end of the parser's <span>input
stream</span>.</p></li>

<li><p>If there is a <span>pending parsing-blocking script</span>, then return.</p></li>
<li><p>If <span>this</span>'s <span>pending parsing-blocking script</span> is not null, then
return.</p></li>

<li><p>Run the tokenizer, processing resulting tokens as they are emitted, and stopping when the
tokenizer reaches the <span>explicit "EOF" character</span> or <span data-x="spin the event
Expand Down Expand Up @@ -98185,11 +98183,11 @@ document.body.appendChild(frame)</code></pre>
point</span>.</p></li>

<li>
<p>If there is no <span>pending parsing-blocking script</span>, have the <span>HTML
parser</span> process <var>input</var>, one code point at a time, processing resulting tokens as
they are emitted, and stopping when the tokenizer reaches the insertion point or when the
processing of the tokenizer is aborted by the tree construction stage (this can happen if a
<code>script</code> end tag token is emitted by the tokenizer).
<p>If <var>document</var>'s <span>pending parsing-blocking script</span> is null, then have the
<span>HTML parser</span> process <var>input</var>, one code point at a time, processing
resulting tokens as they are emitted, and stopping when the tokenizer reaches the insertion
point or when the processing of the tokenizer is aborted by the tree construction stage (this
can happen if a <code>script</code> end tag token is emitted by the tokenizer).

<p class="note">If the <code data-x="dom-document-write">document.write()</code> method was
called from script executing inline (i.e. executing because the parser parsed a set of
Expand Down Expand Up @@ -114308,8 +114306,8 @@ document.body.appendChild(text);
point</var>. (In other words, restore the <span>insertion point</span> to its previous value.
This value might be the "undefined" value.)</p>

<p id="scriptTagParserResumes">At this stage, if there is a <span>pending parsing-blocking
script</span>, then:</p>
<p id="scriptTagParserResumes">At this stage, if the <span>pending parsing-blocking
script</span> is not null, then:</p>

<dl class="switch">

Expand All @@ -114329,11 +114327,13 @@ document.body.appendChild(text);
<dt>Otherwise:</dt>

<dd>
<p>Run these steps:</p>
<p>While the <span>pending parsing-blocking script</span> is not null:</p>

<ol>
<li><p>Let <var>the script</var> be the <span>pending parsing-blocking
script</span>. There is no longer a <span>pending parsing-blocking script</span>.</p></li>
script</span>.</p></li>

<li><p>Set the <span>pending parsing-blocking script</span> to null.</p></li>

<li><p><span>Start the speculative HTML parser</span> for this instance of the HTML
parser.</p></li>
Expand Down Expand Up @@ -114380,9 +114380,6 @@ document.body.appendChild(text);
the <span>parser pause flag</span> to false.</p>

<li><p>Let the <span>insertion point</span> be undefined again.</p></li>

<li><p>If there is once again a <span>pending parsing-blocking script</span>, then repeat
these steps from step 1.</p></li>
</ol>
</dd>
</dl>
Expand Down Expand Up @@ -117289,7 +117286,7 @@ console.assert(container.firstChild instanceof SuperP);
<li><p><span data-x="execute the script block">Execute</span> the <span>pending parsing-blocking
script</span>.</p></li>

<li><p>There is no longer a <span>pending parsing-blocking script</span>.</p></li>
<li><p>Set the <span>pending parsing-blocking script</span> to null.</p></li>
</ol>

<p class="note">Since the <code data-x="dom-document-write">document.write()</code> API is not
Expand Down

0 comments on commit 60a9ea1

Please sign in to comment.