Skip to content

Commit b7d7ee5

Browse files
committed
Fix error cases of <script type=module>
There are several different ways things can go wrong with <script type=module>. In order from earliest to latest, for a single module script, they are: - Fetching failures - Parsing failures - Invalid module specifiers - Instantiation failures - Evaluation failures This tweaks the way that these errors interact, to ensure that fetching failures are treated one way, causing the <script>'s "error" event to fire, and the other failures are uniformly treated as errors running the script, causing the global's "error" event to fire. This also makes it clear that when fetching descendant module scripts, you can bail out early if one of them fails to fetch or has previously been discovered to be errored. Fixes #2567.
1 parent e704140 commit b7d7ee5

File tree

1 file changed

+84
-61
lines changed

1 file changed

+84
-61
lines changed

source

Lines changed: 84 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -86658,24 +86658,24 @@ interface <dfn>NavigatorOnLine</dfn> {
8665886658

8665986659
</dd>
8666086660

86661-
<dt>An <dfn data-x="concept-module-script-instantiation-state">instantiation state</dfn></dt>
86661+
<dt>A <dfn data-x="concept-module-script-state">state</dfn></dt>
8666286662

8666386663
<dd>
8666486664

8666586665
<p>One of "<code data-x="">uninstantiated</code>", "<code data-x="">errored</code>", or "<code
8666686666
data-x="">instantiated</code>", used to prevent reinvocation of <span
8666786667
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span> on modules that
86668-
failed to instantiate previously.</p>
86668+
failed to instantiate previously, and to ensure errors during parsing or instantiation are
86669+
remembered and propagated correctly.</p>
8666986670

8667086671
</dd>
8667186672

86672-
<dt>An <dfn data-x="concept-module-script-instantiation-error">instantiation error</dfn></dt>
86673+
<dt>An <dfn data-x="concept-module-script-error">error</dfn></dt>
8667386674

8667486675
<dd>
8667586676

8667686677
<p>A JavaScript value, which has meaning only if the <span
86677-
data-x="concept-module-script-instantiation-state">instantiation state</span> is "<code
86678-
data-x="">errored</code>".</p>
86678+
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>".</p>
8667986679

8668086680
</dd>
8668186681

@@ -87142,49 +87142,41 @@ interface <dfn>NavigatorOnLine</dfn> {
8714287142
<li><p>If <var>result</var> is null, asynchronously complete this algorithm with null and abort
8714387143
these steps.</p></li>
8714487144

87145+
<li><p>If <var>result</var>'s <span data-x="concept-module-script-state">state</span> is "<code
87146+
data-x="">instantiated</code>" or "<code data-x="">errored</code>", asynchronously complete this
87147+
algorithm with <var>result</var>, and abort these steps.</p></li>
87148+
87149+
<li><p>Assert: <var>result</var>'s <span data-x="concept-module-script-state">state</span> is
87150+
"<code data-x="">uninstantiated</code>".</p></li>
87151+
8714587152
<li>
87146-
<p>Otherwise, <var>result</var> is a <span>module script</span>. <span data-x="fetch the
87147-
descendants of a module script">Fetch the descendants</span> of <var>result</var> given
87148-
<var>destination</var> and an ancestor list obtained by appending <var>url</var> to <var>ancestor
87149-
list</var>. Wait for <span data-x="fetch the descendants of a module script">fetching the
87150-
descendants of a module script</span> to asynchronously complete with <var>descendants
87151-
result</var> before proceeding to the next step.</p>
87153+
<p><span data-x="fetch the descendants of a module script">Fetch the
87154+
descendants</span> of <var>result</var> given <var>destination</var> and an ancestor list
87155+
obtained by appending <var>url</var> to <var>ancestor list</var>. Wait for <span data-x="fetch
87156+
the descendants of a module script">fetching the descendants of a module script</span> to
87157+
asynchronously complete with <var>descendants result</var> before proceeding to the next step.</p>
8715287158

8715387159
<p class="note">If the asynchronous completion result is null, meaning that fetching one of the
8715487160
descendants failed, we still proceed through the next set of steps. A failure will shortly occur
8715587161
during instantiation, which we then react to appropriately. The error signal is eventually
8715687162
propagated to the caller of this algorithm in the last step.</p>
8715787163
</li>
8715887164

87159-
<li><p>Let <var>instantiationStatus</var> be null.</p></li>
87160-
87161-
<li><p>If <var>result</var>'s <span data-x="concept-module-script-instantiation-state">instantiation
87162-
state</span> is "<code data-x="">errored</code>", then set <var>instantiationStatus</var> to
87163-
Completion { [[Type]]: throw, [[Value]]: <var>result</var>'s <span
87164-
data-x="concept-module-script-instantiation-error">instantiation error</span>, [[Target]]:
87165-
empty }.</p></li>
87165+
<li><p>Let <var>record</var> be <var>result</var>'s <span
87166+
data-x="concept-module-script-module-record">module record</span>.</p></li>
8716687167

8716787168
<li>
87168-
<p>Otherwise:</p>
87169-
87170-
<ol>
87171-
<li><p>Let <var>record</var> be <var>result</var>'s <span
87172-
data-x="concept-module-script-module-record">module record</span>.</p></li>
87169+
<p>Let <var>instantiationStatus</var> be <var>record</var>.<span
87170+
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span>().</p>
8717387171

87174-
<li>
87175-
<p>Set <var>instantiationStatus</var> to <var>record</var>.<span
87176-
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span>().</p>
87177-
87178-
<p class="note">This step will recursively call <span
87179-
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span> all of the
87180-
module's uninstantiated dependencies.</p>
87181-
</li>
87182-
</ol>
87172+
<p class="note">This step will recursively call <span
87173+
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span> all of the
87174+
module's uninstantiated dependencies.</p>
8718387175
</li>
8718487176

8718587177
<li>
87186-
<p>For each <var>script</var> in <var>result</var>'s <span>uninstantiated inclusive descendant module
87187-
scripts</span>, perform the following steps:</p>
87178+
<p>For each <var>script</var> in <var>result</var>'s <span>uninstantiated inclusive descendant
87179+
module scripts</span>, perform the following steps:</p>
8718887180

8718987181
<ol>
8719087182
<li>
@@ -87197,18 +87189,16 @@ interface <dfn>NavigatorOnLine</dfn> {
8719787189
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-module-record">module
8719887190
record</span> to null.</p></li>
8719987191

87200-
<li><p>Set <var>script</var>'s <span
87201-
data-x="concept-module-script-instantiation-state">instantiation state</span> to "<code
87202-
data-x="">errored</code>".</p></li>
87192+
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-state">state</span> to
87193+
"<code data-x="">errored</code>".</p></li>
8720387194

87204-
<li><p>Set <var>script</var>'s <span
87205-
data-x="concept-module-script-instantiation-error">instantiation error</span> to
87195+
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-error">error</span> to
8720687196
<var>instantiationStatus</var>.[[Value]].</p></li>
8720787197
</ol>
8720887198
</li>
8720987199

8721087200
<li><p>Otherwise, set <var>script</var>'s <span
87211-
data-x="concept-module-script-instantiation-state">instantiation state</span> to "<code
87201+
data-x="concept-module-script-state">state</span> to "<code
8721287202
data-x="">instantiated</code>".</p></li>
8721387203
</ol>
8721487204
</li>
@@ -87226,6 +87216,9 @@ interface <dfn>NavigatorOnLine</dfn> {
8722687216
data-x="module script">module scripts</span> determined as follows:</p>
8722787217

8722887218
<ol>
87219+
<li><p>If <var>script</var>'s <span data-x="concept-module-script-module-record">module
87220+
record</span> is null, return the empty set.</p></li>
87221+
8722987222
<li><p>Let <var>moduleMap</var> be <var>script</var>'s <span>settings object</span>'s
8723087223
<span data-x="concept-settings-object-module-map">module map</span>.</p></li>
8723187224

@@ -87284,7 +87277,7 @@ interface <dfn>NavigatorOnLine</dfn> {
8728487277
</li>
8728587278

8728687279
<li><p>Return a <span>set</span> containing all items of <var>inclusive descendants</var> whose
87287-
<span data-x="concept-module-script-instantiation-state">instantiation state</span> is "<code
87280+
<span data-x="concept-module-script-state">state</span> is "<code
8728887281
data-x="">uninstantiated</code>".</p></li>
8728987282
</ol>
8729087283

@@ -87417,10 +87410,14 @@ interface <dfn>NavigatorOnLine</dfn> {
8741787410
<ol>
8741887411
<li><p>Let <var>error</var> be a new <code>TypeError</code> exception.</p></li>
8741987412

87420-
<li><p><span>Report the exception</span> <var>error</var> for <var>module
87421-
script</var>.</p></li>
87413+
<li><p>Set <var>module script</var>'s <span data-x="concept-module-script-state">state</span>
87414+
to "<code data-x="">errored</code>".</p></li>
87415+
87416+
<li><p>Set <var>module script</var>'s <span data-x="concept-module-script-error">error</span>
87417+
to <var>error</var>.</p></li>
8742287418

87423-
<li><p>Abort this algorithm, and asynchronously complete it with null.</p></li>
87419+
<li><p>Abort this algorithm, and asynchronously complete it with <var>module
87420+
script</var>.</p></li>
8742487421
</ol>
8742587422
</li>
8742687423

@@ -87443,10 +87440,25 @@ interface <dfn>NavigatorOnLine</dfn> {
8744387440
<span data-x="fetching-scripts-perform-fetch">perform the fetch</span> steps, pass those along
8744487441
while performing the <span>internal module script graph fetching procedure</span>.</p>
8744587442

87446-
<p>Wait for all of the <span>internal module script graph fetching procedure</span> invocations
87447-
to asynchronously complete. If any of them asynchronously complete with null, then
87448-
asynchronously complete this algorithm with null. Otherwise, asynchronously complete this
87449-
algorithm with <var>module script</var>.</p>
87443+
<p>These invocations of the <span>internal module script graph fetching procedure</span> should
87444+
be performed in parallel to each other.</p>
87445+
87446+
<p>If any invocation of the <span>internal module script graph fetching procedure</span>
87447+
asynchronously completes with null, optionally abort all other invocations, and then
87448+
asynchronously complete this algorithm with null.</p>
87449+
87450+
<p>If any invocation of the <span>internal module script graph fetching procedure</span>
87451+
asynchronously completes with a <span>module script</span> whose <span
87452+
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>",
87453+
optionally abort all other invocations, and then asynchronously complete this algorithm with
87454+
<var>module script</var>. (The errored descendant will cause errors later in the module-fetching
87455+
process, but for now we treat it as a premature "success".)</p>
87456+
87457+
<p>Otherwise, wait for all of the <span>internal module script graph fetching procedure</span>
87458+
invocations to asynchronously complete, with <span data-x="module script">module scripts</span>
87459+
whose <span data-x="concept-module-script-state">states</span> are not "<code
87460+
data-x="">errored</code>". Then, asynchronously complete this algorithm with <var>module
87461+
script</var>.</p>
8745087462
</li>
8745187463
</ol>
8745287464

@@ -87507,9 +87519,22 @@ interface <dfn>NavigatorOnLine</dfn> {
8750787519
<var>result</var>.[[HostDefined]] will be <var>script</var>.</p>
8750887520
</li>
8750987521

87510-
<li><p>If <var>result</var> is a <span>List</span> of errors, <span>report the exception</span>
87511-
given by the first element of <var>result</var> for <var>script</var>, return null, and abort
87512-
these steps.</p></li>
87522+
<li>
87523+
<p>If <var>result</var> is a <span>List</span> of errors, then:</p>
87524+
87525+
<ol>
87526+
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-state">state</span> to
87527+
"<code data-x="">errored</code>".</p></li>
87528+
87529+
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-error">error</span> to
87530+
<var>errors</var>[0].</p></li>
87531+
87532+
<li><p>Return <var>script</var>.</p></li>
87533+
</ol>
87534+
</li>
87535+
87536+
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-state">state</span> to "<code
87537+
data-x="">uninstantiated</code>".</p></li>
8751387538

8751487539
<li><p>Set <var>script</var>'s <span data-x="concept-module-script-module-record">module
8751587540
record</span> to <var>result</var>.</p></li>
@@ -87607,14 +87632,12 @@ interface <dfn>NavigatorOnLine</dfn> {
8760787632
<li><p><span>Check if we can run script</span> with <var>settings</var>. If this returns "do
8760887633
not run" then abort these steps.</p></li>
8760987634

87610-
<li><p>If <var>s</var>'s <span data-x="concept-module-script-instantiation-state">instantiation
87611-
state</span> is "<code data-x="">errored</code>", then <span>report the
87612-
exception</span> given by <var>s</var>'s <span
87613-
data-x="concept-module-script-instantiation-error">instantiation error</span> for <var>s</var>
87614-
and abort these steps.</p></li>
87635+
<li><p>If <var>s</var>'s <span data-x="concept-module-script-state">state</span> is "<code
87636+
data-x="">errored</code>", then <span>report the exception</span> given by <var>s</var>'s <span
87637+
data-x="concept-module-script-error">error</span> for <var>s</var> and abort these
87638+
steps.</p></li>
8761587639

87616-
<li><p>Assert: <var>s</var>'s <span
87617-
data-x="concept-module-script-instantiation-state">instantiation state</span> is "<code
87640+
<li><p>Assert: <var>s</var>'s <span data-x="concept-module-script-state">state</span> is "<code
8761887641
data-x="">instantiated</code>" (and thus its <span
8761987642
data-x="concept-module-script-module-record">module record</span> is not null).</p></li>
8762087643

@@ -88490,9 +88513,9 @@ import "https://example.com/foo/../module2.js";</pre>
8849088513
steps.</p></li>
8849188514

8849288515
<li><p>If <var>resolved module script</var>'s <span
88493-
data-x="concept-module-script-instantiation-state">instantiation state</span> is "<code
88494-
data-x="">errored</code>", then throw <var>resolved module script</var>'s <span
88495-
data-x="concept-module-script-instantiation-error">instantiation error</span>.</p></li>
88516+
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>", then throw
88517+
<var>resolved module script</var>'s <span
88518+
data-x="concept-module-script-error">error</span>.</p></li>
8849688519

8849788520
<li><p>Assert: <var>resolved module script</var>'s <span
8849888521
data-x="concept-module-script-module-record">module record</span> is not null.</p></li>

0 commit comments

Comments
 (0)