Skip to content

Commit b520372

Browse files
committed
Properly instantiate inline module scripts
This moves the latter half of the "internal module script graph fetching procedure" into "fetch the descendants of a module script", which is then renamed "fetch the descendants of and instantiate a module script". Then, the inline script code can properly call this new algorithm to take care of everything once it has an initial module script prepared from the inline script source. Fixes #2544.
1 parent 1157631 commit b520372

File tree

1 file changed

+142
-137
lines changed

1 file changed

+142
-137
lines changed

source

Lines changed: 142 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -58362,10 +58362,11 @@ o............A....e
5836258362
<li><p>If this returns null, set <span data-x="concept-script-script">the script's
5836358363
script</span> to null and abort these substeps; <span>the script is ready</span>.</p></li>
5836458364

58365-
<li><p><span data-x="fetch the descendants of a module script">Fetch the
58366-
descendants</span> of <var>script</var> (using an empty ancestor list). When this
58367-
asynchronously completes, set <span data-x="concept-script-script">the script's
58368-
script</span> to the result. At that time, <span>the script is ready</span>.</p></li>
58365+
<li><p><span data-x="fetch the descendants of and instantiate a module script">Fetch the
58366+
descendants of and instantiate</span> <var>script</var>, given the destination "<code
58367+
data-x="">script</code>". When this asynchronously completes, set <span
58368+
data-x="concept-script-script">the script's script</span> to the result. At that time,
58369+
<span>the script is ready</span>.</p></li>
5836958370
</ol>
5837058371
</dd>
5837158372
</dl>
@@ -87060,130 +87061,15 @@ interface <dfn>NavigatorOnLine</dfn> {
8706087061
<li><p>Assert: <var>result</var>'s <span data-x="concept-module-script-state">state</span> is
8706187062
"<code data-x="">uninstantiated</code>".</p></li>
8706287063

87063-
<li>
87064-
<p><span data-x="fetch the descendants of a module script">Fetch the
87065-
descendants</span> of <var>result</var> given <var>destination</var> and an ancestor list
87066-
obtained by appending <var>url</var> to <var>ancestor list</var>. Wait for <span data-x="fetch
87067-
the descendants of a module script">fetching the descendants of a module script</span> to
87068-
asynchronously complete with <var>descendants result</var> before proceeding to the next step.</p>
87069-
87070-
<p class="note">If the asynchronous completion result is null, meaning that fetching one of the
87071-
descendants failed, we still proceed through the next set of steps. A failure will shortly occur
87072-
during instantiation, which we then react to appropriately. The error signal is eventually
87073-
propagated to the caller of this algorithm in the last step.</p>
87074-
</li>
87075-
87076-
<li><p>Let <var>record</var> be <var>result</var>'s <span
87077-
data-x="concept-module-script-module-record">module record</span>.</p></li>
87078-
87079-
<li>
87080-
<p>Let <var>instantiationStatus</var> be <var>record</var>.<span
87081-
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span>().</p>
87082-
87083-
<p class="note">This step will recursively call <span
87084-
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span> all of the
87085-
module's uninstantiated dependencies.</p>
87086-
</li>
87064+
<li><p><span data-x="fetch the descendants of and instantiate a module script">Fetch the
87065+
descendants of and instantiate</span> <var>result</var> given <var>destination</var> and an
87066+
ancestor list obtained by appending <var>url</var> to <var>ancestor list</var>.</p></li>
8708787067

87088-
<li>
87089-
<p>For each <var>script</var> in <var>result</var>'s <span>uninstantiated inclusive descendant
87090-
module scripts</span>, perform the following steps:</p>
87091-
87092-
<ol>
87093-
<li><p>If <var>instantiationStatus</var> is an abrupt completion, then <span data-x="error a
87094-
module script">error</span> <var>script</var> with
87095-
<var>instantiationStatus</var>.[[Value]].</p></li>
87096-
87097-
<li><p>Otherwise, set <var>script</var>'s <span
87098-
data-x="concept-module-script-state">state</span> to "<code
87099-
data-x="">instantiated</code>".</p></li>
87100-
</ol>
87101-
</li>
87102-
87103-
<li>
87104-
<p>Asynchronously complete this algorithm with <var>descendants result</var>.</p>
87105-
87106-
<p class="note">It is intentional that we complete with <var>descendants result</var> here, and
87107-
not <var>result</var>, as this allows us to propagate error signals to the caller.</p>
87108-
</li>
87068+
<li><p>When the <span>fetch the descendants of and instantiate a module script</span> algorithm
87069+
asynchronously completes with <var>final result</var>, asynchronously complete this algorithm
87070+
with <var>final result</var>.</p></li>
8710987071
</ol>
8711087072

87111-
<p>In the above algorithm, a <span>module script</span> <var>script</var>'s <dfn>uninstantiated
87112-
inclusive descendant module scripts</dfn> is a <span>set</span> of <span
87113-
data-x="module script">module scripts</span> determined as follows:</p>
87114-
87115-
<ol>
87116-
<li><p>If <var>script</var>'s <span data-x="concept-module-script-module-record">module
87117-
record</span> is null, return the empty set.</p></li>
87118-
87119-
<li><p>Let <var>moduleMap</var> be <var>script</var>'s <span>settings object</span>'s
87120-
<span data-x="concept-settings-object-module-map">module map</span>.</p></li>
87121-
87122-
<li><p>Let <var>stack</var> be the <span>stack</span> « <var>script</var> ».</p></li>
87123-
87124-
<li><p>Let <var>inclusive descendants</var> be an empty <span>set</span>.</p></li>
87125-
87126-
<li>
87127-
<p>While <var>stack</var> <span data-x="list is empty">is not empty</span>:</p>
87128-
87129-
<ol>
87130-
<li><p>Let <var>current</var> the result of <span data-x="stack pop">popping</span> from
87131-
<var>stack</var>.</p></li>
87132-
87133-
<li><p>Assert: <var>current</var> is a <span>module script</span> (i.e., it is not "<code
87134-
data-x="">fetching</code>" or null).</p></li>
87135-
87136-
<li>
87137-
<p>If <var>inclusive descendants</var> and <var>stack</var> both do not <span
87138-
data-x="list contains">contain</span> <var>current</var>, then:</p>
87139-
87140-
<ol>
87141-
<li><p><span data-x="list append">Append</span> <var>current</var> to
87142-
<var>inclusive descendants</var>.</p></li>
87143-
87144-
<li><p>Let <var>child specifiers</var> be the value of <var>current</var>'s <span
87145-
data-x="concept-module-script-module-record">module record</span>'s [[RequestedModules]]
87146-
internal slot.</p></li>
87147-
87148-
<li><p>Let <var>child URLs</var> be the <span>list</span> obtained by calling
87149-
<span>resolve a module specifier</span> once for each item of <var>child specifiers</var>,
87150-
given <var>current</var> and that item. Omit any failures.</p></li>
87151-
87152-
<li><p>Let <var>child modules</var> be the <span>list</span> obtained by <span
87153-
data-x="map get">getting each value</span> in <var>moduleMap</var> whose key is given by an
87154-
item of <var>child URLs</var>.</p></li>
87155-
87156-
<li>
87157-
<p><span data-x="list iterate">For each</span> <var>s</var> of <var>child modules</var>:</p>
87158-
87159-
<ol>
87160-
<li><p>If <var>inclusive descendants</var> already <span data-x="list
87161-
contains">contains</span> <var>s</var>, <span>continue</span>.</p></li>
87162-
87163-
<li><p>If <var>s</var> is null, <span>continue</span>.</p></li>
87164-
87165-
<li><p>Assert: <var>s</var> is a <span>module script</span> (i.e., it is not
87166-
"<code data-x="">fetching</code>", since by this point all child modules must have been
87167-
fetched).</p></li>
87168-
87169-
<li><p><span data-x="stack push">Push</span> <var>s</var> onto <var>stack</var>.</p></li>
87170-
</ol>
87171-
</ol>
87172-
</li>
87173-
</ol>
87174-
</li>
87175-
87176-
<li><p>Return a <span>set</span> containing all items of <var>inclusive descendants</var> whose
87177-
<span data-x="concept-module-script-state">state</span> is "<code
87178-
data-x="">uninstantiated</code>".</p></li>
87179-
</ol>
87180-
87181-
<p class="note">The above algorithm gives a depth-first search of the module dependency graph. The
87182-
main interesting part is in how the "edges" of this graph are determined. The actual search
87183-
implementation is not important; any other technique for exploring the graph will suffice, given
87184-
that the output is a <span>set</span> only used for membership testing and whose order is thus not
87185-
important.</p>
87186-
8718787073
<p>To <dfn>fetch a single module script</dfn>, given a <var>url</var>, a <var>fetch client
8718887074
settings object</var>, a <var>destination</var>, a <var>cryptographic nonce</var>, a <var>parser
8718987075
state</var>, a <var>credentials mode</var>, a <var>module map settings object</var>, a
@@ -87279,12 +87165,21 @@ interface <dfn>NavigatorOnLine</dfn> {
8727987165
</li>
8728087166
</ol>
8728187167

87282-
<p>To <dfn>fetch the descendants of a module script</dfn> <var>module script</var>, given a
87283-
<var>destination</var> and an <var>ancestor list</var>, run these steps. The algorithm will
87284-
asynchronously complete with either null (on failure) or with <var>module script</var> (on
87285-
success).</p>
87168+
<p>To <dfn>fetch the descendants of and instantiate a module script</dfn> <var>module
87169+
script</var>, given a <var>destination</var> and an optional <var>ancestor list</var>, run these
87170+
steps. The algorithm will asynchronously complete with either null (on failure) or with
87171+
<var>module script</var> (on success).</p>
8728687172

8728787173
<ol>
87174+
<li><p>If <var>ancestor list</var> was not given, let it be the empty <span>list</span>.</p></li>
87175+
87176+
<li><p>If <var>module script</var>'s <span data-x="concept-module-script-state">state</span> is
87177+
"<code data-x="">instantiated</code>" or "<code data-x="">errored</code>", asynchronously
87178+
complete this algorithm with <var>module script</var>, and abort these steps.</p></li>
87179+
87180+
<li><p>Assert: <var>module script</var>'s <span data-x="concept-module-script-state">state</span>
87181+
is "<code data-x="">uninstantiated</code>".</p></li>
87182+
8728887183
<li><p>Let <var>record</var> be <var>module script</var>'s <span
8728987184
data-x="concept-module-script-module-record">module record</span>.</p></li>
8729087185

@@ -87321,6 +87216,8 @@ interface <dfn>NavigatorOnLine</dfn> {
8732187216
</ol>
8732287217
</li>
8732387218

87219+
<li><p>Let <var>descendants result</var> be null.</p></li>
87220+
8732487221
<li>
8732587222
<p><span data-x="list iterate">For each</span> <var>url</var> in <var>urls</var>, perform the
8732687223
<span>internal module script graph fetching procedure</span> given <var>url</var>, <var>module
@@ -87338,24 +87235,132 @@ interface <dfn>NavigatorOnLine</dfn> {
8733887235
be performed in parallel to each other.</p>
8733987236

8734087237
<p>If any invocation of the <span>internal module script graph fetching procedure</span>
87341-
asynchronously completes with null, optionally abort all other invocations, and then
87342-
asynchronously complete this algorithm with null.</p>
87238+
asynchronously completes with null, then optionally abort all other invocations, set
87239+
<var>descendants result</var> to null, and proceed to the next step. (The un-fetched descendant
87240+
will cause errors during instantiation.)</p>
8734387241

8734487242
<p>If any invocation of the <span>internal module script graph fetching procedure</span>
8734587243
asynchronously completes with a <span>module script</span> whose <span
87346-
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>",
87347-
optionally abort all other invocations, and then asynchronously complete this algorithm with
87348-
<var>module script</var>. (The errored descendant will cause errors later in the module-fetching
87349-
process, but for now we treat it as a premature "success".)</p>
87244+
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>", then
87245+
optionally abort all other invocations, set <var>descendants result</var> to <var>module
87246+
script</var>, and proceed to the next step. (The errored descendant will cause errors during
87247+
instantiation.)</p>
8735087248

8735187249
<p>Otherwise, wait for all of the <span>internal module script graph fetching procedure</span>
8735287250
invocations to asynchronously complete, with <span data-x="module script">module scripts</span>
8735387251
whose <span data-x="concept-module-script-state">states</span> are not "<code
87354-
data-x="">errored</code>". Then, asynchronously complete this algorithm with <var>module
87355-
script</var>.</p>
87252+
data-x="">errored</code>". Then, set <var>descendants result</var> to <var>module script</var>,
87253+
and proceed to the next step.</p>
87254+
</li>
87255+
87256+
<li>
87257+
<p>Let <var>instantiationStatus</var> be <var>record</var>.<span
87258+
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span>().</p>
87259+
87260+
<p class="note">This step will recursively call <span
87261+
data-x="js-ModuleDeclarationInstantiation">ModuleDeclarationInstantiation</span> all of the
87262+
module's uninstantiated dependencies.</p>
87263+
</li>
87264+
87265+
<li>
87266+
<p>For each <var>script</var> in <var>module script</var>'s <span>uninstantiated inclusive
87267+
descendant module scripts</span>, perform the following steps:</p>
87268+
87269+
<ol>
87270+
<li><p>If <var>instantiationStatus</var> is an abrupt completion, then <span data-x="error a
87271+
module script">error</span> <var>script</var> with
87272+
<var>instantiationStatus</var>.[[Value]].</p></li>
87273+
87274+
<li><p>Otherwise, set <var>script</var>'s <span
87275+
data-x="concept-module-script-state">state</span> to "<code
87276+
data-x="">instantiated</code>".</p></li>
87277+
</ol>
87278+
</li>
87279+
87280+
<li>
87281+
<p>Asynchronously complete this algorithm with <var>descendants result</var>.</p>
87282+
87283+
<p class="note">It is intentional that we complete with <var>descendants result</var> here, and
87284+
not <var>module script</var>, as this allows us to notify the caller of fetching errors.</p>
87285+
</li>
87286+
</ol>
87287+
87288+
<p>In the above algorithm, a <span>module script</span> <var>script</var>'s <dfn>uninstantiated
87289+
inclusive descendant module scripts</dfn> is a <span>set</span> of <span
87290+
data-x="module script">module scripts</span> determined as follows:</p>
87291+
87292+
<ol>
87293+
<li><p>If <var>script</var>'s <span data-x="concept-module-script-module-record">module
87294+
record</span> is null, return the empty set.</p></li>
87295+
87296+
<li><p>Let <var>moduleMap</var> be <var>script</var>'s <span>settings object</span>'s
87297+
<span data-x="concept-settings-object-module-map">module map</span>.</p></li>
87298+
87299+
<li><p>Let <var>stack</var> be the <span>stack</span> « <var>script</var> ».</p></li>
87300+
87301+
<li><p>Let <var>inclusive descendants</var> be an empty <span>set</span>.</p></li>
87302+
87303+
<li>
87304+
<p>While <var>stack</var> <span data-x="list is empty">is not empty</span>:</p>
87305+
87306+
<ol>
87307+
<li><p>Let <var>current</var> the result of <span data-x="stack pop">popping</span> from
87308+
<var>stack</var>.</p></li>
87309+
87310+
<li><p>Assert: <var>current</var> is a <span>module script</span> (i.e., it is not "<code
87311+
data-x="">fetching</code>" or null).</p></li>
87312+
87313+
<li>
87314+
<p>If <var>inclusive descendants</var> and <var>stack</var> both do not <span
87315+
data-x="list contains">contain</span> <var>current</var>, then:</p>
87316+
87317+
<ol>
87318+
<li><p><span data-x="list append">Append</span> <var>current</var> to
87319+
<var>inclusive descendants</var>.</p></li>
87320+
87321+
<li><p>Let <var>child specifiers</var> be the value of <var>current</var>'s <span
87322+
data-x="concept-module-script-module-record">module record</span>'s [[RequestedModules]]
87323+
internal slot.</p></li>
87324+
87325+
<li><p>Let <var>child URLs</var> be the <span>list</span> obtained by calling
87326+
<span>resolve a module specifier</span> once for each item of <var>child specifiers</var>,
87327+
given <var>current</var> and that item. Omit any failures.</p></li>
87328+
87329+
<li><p>Let <var>child modules</var> be the <span>list</span> obtained by <span
87330+
data-x="map get">getting each value</span> in <var>moduleMap</var> whose key is given by an
87331+
item of <var>child URLs</var>.</p></li>
87332+
87333+
<li>
87334+
<p><span data-x="list iterate">For each</span> <var>s</var> of <var>child modules</var>:</p>
87335+
87336+
<ol>
87337+
<li><p>If <var>inclusive descendants</var> already <span data-x="list
87338+
contains">contains</span> <var>s</var>, <span>continue</span>.</p></li>
87339+
87340+
<li><p>If <var>s</var> is null, <span>continue</span>.</p></li>
87341+
87342+
<li><p>Assert: <var>s</var> is a <span>module script</span> (i.e., it is not
87343+
"<code data-x="">fetching</code>", since by this point all child modules must have been
87344+
fetched).</p></li>
87345+
87346+
<li><p><span data-x="stack push">Push</span> <var>s</var> onto <var>stack</var>.</p></li>
87347+
</ol>
87348+
</ol>
87349+
</li>
87350+
</ol>
8735687351
</li>
87352+
87353+
<li><p>Return a <span>set</span> containing all items of <var>inclusive descendants</var> whose
87354+
<span data-x="concept-module-script-state">state</span> is "<code
87355+
data-x="">uninstantiated</code>".</p></li>
8735787356
</ol>
8735887357

87358+
<p class="note">The above algorithm gives a depth-first search of the module dependency graph. The
87359+
main interesting part is in how the "edges" of this graph are determined. The actual search
87360+
implementation is not important; any other technique for exploring the graph will suffice, given
87361+
that the output is a <span>set</span> only used for membership testing and whose order is thus not
87362+
important.</p>
87363+
8735987364
<h5 id="creating-scripts">Creating scripts</h5>
8736087365

8736187366
<p>To <dfn data-x="creating a classic script">create a classic script</dfn>, given some script

0 commit comments

Comments
 (0)