Skip to content

Commit 616df18

Browse files
authored
Don't handle impossible errors in HostResolveImportedModule
Several of the cases that were handled as errors are actually impossible to hit. Instead of throwing errors in these impossible situations, we can just assert that they are impossible. This also cleans up "resolve a module specifier" and the module map to be clear that they operate on URL records, not on absolute URL strings. Note that the remaining error case, of a null result in the module map, may go away, depending on how we fix #2629 and #2630. It currently occurs because of our strategy of calling ModuleDeclarationInstantiation() even when we know it will fail, in order to propagate errors, but that strategy is seeming increasingly unwise in the face of those bugs.
1 parent 3a3405a commit 616df18

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

source

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87197,7 +87197,7 @@ interface <dfn>NavigatorOnLine</dfn> {
8719787197
a module specifier</span> given <var>module script</var> and <var>requested</var>.</p></li>
8719887198

8719987199
<li>
87200-
<p>If the result is error:</p>
87200+
<p>If <var>url</var> is failure:</p>
8720187201

8720287202
<ol>
8720387203
<li><p>Let <var>error</var> be a new <code>TypeError</code> exception.</p></li>
@@ -88283,8 +88283,8 @@ document.querySelector("button").addEventListener("click", bound);
8828388283
scripts</span> versus <span data-x="module script">module scripts</span>, since both of them use
8828488284
the <code>script</code> element.</p>
8828588285

88286-
<p>A <dfn>module map</dfn> is a <span data-x="ordered map">map</span> of <span data-x="absolute
88287-
URL">absolute URLs</span> to values that are either a <span>module script</span>, null (used to
88286+
<p>A <dfn>module map</dfn> is a <span data-x="ordered map">map</span> of <span data-x="URL
88287+
record">URL records</span> to values that are either a <span>module script</span>, null (used to
8828888288
represent failed fetches), or a placeholder value "<code data-x="">fetching</code>". <span
8828988289
data-x="module map">Module maps</span> are used to ensure that imported JavaScript modules are
8829088290
only fetched, parsed, and evaluated once per <code>Document</code> or <a
@@ -88321,8 +88321,8 @@ import "https://example.com/foo/../module2.js";</pre>
8832188321
</div>
8832288322

8832388323
<p>To <dfn>resolve a module specifier</dfn> given a <span>module script</span> <var>script</var>
88324-
and a string <var>specifier</var>, perform the following steps. It will return either an
88325-
<span>absolute URL</span> or failure.</p>
88324+
and a string <var>specifier</var>, perform the following steps. It will return either a <span>URL
88325+
record</span> or failure.</p>
8832688326

8832788327
<ol>
8832888328
<li><p>Apply the <span>URL parser</span> to <var>specifier</var>. If the result is not failure,
@@ -88410,14 +88410,39 @@ import "https://example.com/foo/../module2.js";</pre>
8841088410
object</span>'s <span data-x="concept-settings-object-module-map">module map</span>.</p></li>
8841188411

8841288412
<li><p>Let <var>url</var> be the result of <span data-x="resolve a module specifier">resolving a
88413-
module specifier</span> given <var>referencing module script</var> and <var>specifier</var>. If
88414-
the result is failure, then throw a <code>TypeError</code> exception and abort these
88415-
steps.</p></li>
88413+
module specifier</span> given <var>referencing module script</var> and
88414+
<var>specifier</var>.</p></li>
8841688415

88417-
<li><p>Let <var>resolved module script</var> be <var>moduleMap</var>[<var>url</var>]. If no such
88418-
entry <span data-x="map exists">exists</span>, or if <var>resolved module script</var> is null or
88419-
"<code data-x="">fetching</code>", then throw a <code>TypeError</code> exception and abort these
88420-
steps.</p></li>
88416+
<li><p>Assert: <var>url</var> is never failure, because <span data-x="resolve a module
88417+
specifier">resolving a module specifier</span> must have been previously successful with these
88418+
same two arguments during the appropriate invocation of <span>fetch the descendants of and
88419+
instantiate a module script</span>.</p></li>
88420+
88421+
<li><p>Let <var>resolved module script</var> be <var>moduleMap</var>[<var>url</var>]. (This entry
88422+
must <span data-x="map exists">exist</span> for us to have gotten to this point.)</p></li>
88423+
88424+
<li>
88425+
<p>If <var>resolved module script</var> is null, then throw a <code>TypeError</code>
88426+
exception and abort these steps.</p>
88427+
88428+
<div class="example">
88429+
<p>This occurs when we have previously tried to <span data-x="fetch a single module
88430+
script">fetch</span> <var>url</var>, and failed, but are now rediscovering that fact in a new
88431+
module script graph. For example, given a file <code data-x="">module.js</code> whose contents
88432+
are</p>
88433+
88434+
<pre>import "./404.js";</pre>
88435+
88436+
<p>then we could get here as part of <span data-x="fetch a module script graph">fetching the
88437+
graph</span> for the second <code>script</code> element in the following HTML:</p>
88438+
88439+
<pre>&lt;script type="module" src="404.js">&lt;/script>
88440+
&lt;script type="module" src="module.js">&lt;/script></pre>
88441+
</div>
88442+
</li>
88443+
88444+
<li><p>Assert: <var>resolved module script</var> is a <span>module script</span> (i.e., is not
88445+
"<code data-x="">fetching</code>").</p></li>
8842188446

8842288447
<li><p>If <var>resolved module script</var>'s <span
8842388448
data-x="concept-module-script-state">state</span> is "<code data-x="">errored</code>", then throw

0 commit comments

Comments
 (0)