Skip to content

Commit 7348615

Browse files
committed
Don't execute scripts that move between documents during fetching
Fixes #2469. Also clarifies surrounding conditions and cleans up the algorithm by pulling out a variable for the element's node document.
1 parent a5586f1 commit 7348615

File tree

1 file changed

+44
-50
lines changed

1 file changed

+44
-50
lines changed

source

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57958,6 +57958,7 @@ o............A....e
5795857958
elements.
5795957959
</p>
5796057960

57961+
<!-- Cleanup? But see https://github.com/whatwg/html/pull/964#issuecomment-204384209 -->
5796157962
<li><p>Let <var>settings object</var> be the element's <span>node document</span>'s
5796257963
<code>Window</code> object's <span>environment settings object</span>.</p></li>
5796357964

@@ -58221,11 +58222,12 @@ o............A....e
5822158222
<p class="note">If a <code>script</code> element that blocks a parser gets moved to another
5822258223
<code>Document</code> before it would normally have stopped blocking that parser, it nonetheless
5822358224
continues blocking that parser until the condition that causes it to be blocking the parser no
58224-
longer applies (e.g. if the script is a <span>pending parsing-blocking script</span> because there
58225-
was <span>a style sheet that is blocking scripts</span> when it was parsed, but then the script is
58226-
moved to another <code>Document</code> before the style sheet loads, the script still blocks the
58227-
parser until the style sheets are all loaded, at which time the script executes and the parser is
58228-
unblocked).</p>
58225+
longer applies. For example, consider a script that is a <span>pending parsing-blocking
58226+
script</span> because there was <span>a style sheet that is blocking scripts</span> when it was
58227+
parsed. If the script is moved to another <code>Document</code> before the style sheet loads, the
58228+
script still blocks the parser until the style sheets are all loaded, at which time the <span
58229+
data-x="execute the script block">execute a script block</span> algorithm runs immediately returns
58230+
without evaluating any script. At this point, the parser is finally unblocked.</p>
5822958231

5823058232
<!-- also (and this would be worth testing): the way the spec is written, if you do not have a
5823158233
style sheet that is blocking scripts, then you parse a <script src>, then while waiting for the
@@ -58237,46 +58239,52 @@ o............A....e
5823758239
block</dfn>, it must run the following steps.</p>
5823858240

5823958241
<ol>
58242+
<li><p>If <span data-x="concept-script-script">the script's script</span> is null, <span
58243+
data-x="concept-event-fire">fire an event</span> named <code data-x="event-error">error</code>
58244+
at the element, and return.</p></li>
5824058245

58241-
<li>
58246+
<li><p>Let <var>document</var> be the <code>script</code> element's <span>node
58247+
document</span>.</p></li>
5824258248

58243-
<p>If the element is flagged as <span>"parser-inserted"</span>, but the element's
58244-
<span>node document</span> is not the <code>Document</code> of the parser that created the element,
58245-
then return.</p>
58249+
<li>
58250+
<p>If <var>document</var>'s <span>relevant settings object</span> is not equal to <span
58251+
data-x="concept-script-script">the script's script</span>'s <span>settings object</span>, then
58252+
return.</p>
5824658253

58254+
<p class="note">This can occur if, while the script was being fetched inside the <span>prepare a
58255+
script</span> algorithm, the element was moved to a document in a different
58256+
<code>Window</code>.</p>
5824758257
</li>
5824858258

5824958259
<li>
58260+
<p>If <span data-x="concept-n-noscript">scripting is disabled</span> for the element, then
58261+
return.</p>
5825058262

58251-
<p>If <span data-x="concept-script-script">the script's script</span> is null, <span
58252-
data-x="concept-event-fire">fire an event</span> named <code data-x="event-error">error</code>
58253-
at the element, and return.</p>
58254-
58263+
<p class="note">This can occur if, while the script was being fetched inside the <span>prepare a
58264+
script</span> algorithm, the element was moved to a document without a <span
58265+
data-x="concept-document-bc">browsing context</span>.</p>
5825558266
</li>
5825658267

58257-
<!-- SCRIPT EXEC -->
58258-
5825958268
<li>
58269+
<p>If the element is flagged as <span>"parser-inserted"</span>, but <var>document</var> is
58270+
not the <code>Document</code> of the parser that created the element, then return.</p>
5826058271

58261-
<p>If the script is <span data-x="concept-script-external">from an external file</span>, or
58262-
<span data-x="concept-script-type">the script's type</span> is "<code data-x="">module</code>",
58263-
then increment the <span>ignore-destructive-writes counter</span> of the <code>script</code>
58264-
element's <span>node document</span>. Let <var>neutralized doc</var> be that
58265-
<code>Document</code>.</p>
58266-
58272+
<p class="note">This can occur if the element was <span
58273+
data-x="concept-node-adopt">adopted</span> into a new document during parsing, before the
58274+
<span>prepare a script</span> algorithm ran.</p>
5826758275
</li>
5826858276

58269-
<li>
58277+
<!-- SCRIPT EXEC -->
5827058278

58271-
<p>Let <var>old script element</var> be the value to which the <code>script</code>
58272-
element's <span>node document</span>'s <code
58273-
data-x="dom-document-currentScript">currentScript</code> object was most recently
58274-
set.</p>
58279+
<li><p>If the script is <span data-x="concept-script-external">from an external file</span>, or
58280+
<span data-x="concept-script-type">the script's type</span> is "<code data-x="">module</code>",
58281+
then increment the <span>ignore-destructive-writes counter</span> of
58282+
<var>document</var>.</p></li>
5827558283

58276-
</li>
58284+
<li><p>Let <var>old script element</var> be the value to which <var>document</var>'s <code
58285+
data-x="dom-document-currentScript">currentScript</code> object was most recently set.</p></li>
5827758286

5827858287
<li>
58279-
5828058288
<p>Switch on <span data-x="concept-script-type">the script's type</span>:</p>
5828158289

5828258290
<dl class="switch">
@@ -58285,7 +58293,7 @@ o............A....e
5828558293
<ol>
5828658294
<li>
5828758295
<p>If the <code>script</code> element's <span>root</span> is <em>not</em> a <span>shadow
58288-
root</span>, then set the <code>script</code> element's <span>node document</span>'s <code
58296+
root</span>, then set <var>document</var>'s <code
5828958297
data-x="dom-document-currentScript">currentScript</code> attribute to the
5829058298
<code>script</code> element. Otherwise, set it to null.</p>
5829158299

@@ -58311,31 +58319,17 @@ o............A....e
5831158319
</ol>
5831258320
</dd>
5831358321
</dl>
58314-
58315-
</li>
58316-
58317-
<li>
58318-
58319-
<p>Set the <code>script</code> element's <span>node document</span>'s <code
58320-
data-x="dom-document-currentScript">currentScript</code> attribute to <var>old script
58321-
element</var>.</p>
58322-
5832358322
</li>
5832458323

58325-
<li>
58326-
58327-
<p>Decrement the <span>ignore-destructive-writes counter</span> of <var>neutralized doc</var>, if it was incremented in the earlier step.</p>
58324+
<li><p>Set <var>document</var>'s <code data-x="dom-document-currentScript">currentScript</code>
58325+
attribute to <var>old script element</var>.</p></li>
5832858326

58329-
</li>
58330-
58331-
<li>
58332-
58333-
<p>If the script is <span data-x="concept-script-external">from an external file</span>, then
58334-
<span data-x="concept-event-fire">fire an event</span> named <code
58335-
data-x="event-load">load</code> at the <code>script</code> element.</p>
58336-
58337-
</li>
58327+
<li><p>Decrement the <span>ignore-destructive-writes counter</span> of <var>document</var>, if it
58328+
was incremented in the earlier step.</p></li>
5833858329

58330+
<li><p>If the script is <span data-x="concept-script-external">from an external file</span>, then
58331+
<span data-x="concept-event-fire">fire an event</span> named <code
58332+
data-x="event-load">load</code> at the <code>script</code> element.</p></li>
5833958333
</ol>
5834058334

5834158335
</div>

0 commit comments

Comments
 (0)