Skip to content

Commit

Permalink
Handle module resolution when there is no active script
Browse files Browse the repository at this point in the history
Closes #3295.
  • Loading branch information
domenic committed Nov 19, 2018
1 parent b921d02 commit 5355e33
Showing 1 changed file with 70 additions and 21 deletions.
91 changes: 70 additions & 21 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -88480,20 +88480,48 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
implementation: <ref spec=JAVASCRIPT> <ref spec=JSIMPORT></p>

<ol>
<li><p>Let <var>referencing script</var> be
<var>referencingScriptOrModule</var>.[[HostDefined]].</p></li>
<li><p>Let <var>settings object</var> be the <span>current settings object</span>.</p></li>

<li><p>Let <var>moduleMap</var> be <var>referencing script</var>'s <span>settings object</span>'s
<span data-x="concept-settings-object-module-map">module map</span>.</p></li>
<li><p>Let <var>base URL</var> be <var>settings object</var>'s <span>API base
URL</span>.</p></li>

<li>
<p>If <var>referencingScriptOrModule</var> is not null, then:</p>

<ol>
<li><p>Let <var>referencing script</var> be
<var>referencingScriptOrModule</var>.[[HostDefined]].</p></li>

<li><p>Set <var>settings object</var> to <var>referencing script</var>'s <span>settings
object</span>.</p></li>

<li><p>Set <var>base URL</var> to <var>referencing script</var>'s <span
data-x="concept-script-base-url">base URL</span>.</p></li>
</ol>

<div class="example">
<p><var>referencingScriptOrModule</var> is not usually null. One case where it <em>can</em> be
null is if the user clicks the control in the following example:</p>

<pre><code class="html" data-x="">&lt;button onclick="import('./foo.mjs')">Click me&lt;/button></code></pre>

<p>In this case, at the time the <code>import()</code> expression runs,
<span>GetActiveScriptOrModule</span> will return null, which will be passed to this abstract
operation when <span data-x="js-HostResolveImportedModule">HostResolveImportedModule</span> is
called by <span>FinishDynamicImport</span>.</p>
</div>
</li>

<li><p>Let <var>moduleMap</var> be <var>settings object</var>'s <span
data-x="concept-settings-object-module-map">module map</span>.</p></li>

<li><p>Let <var>url</var> be the result of <span data-x="resolve a module specifier">resolving a
module specifier</span> given <var>referencing script</var>'s <span
data-x="concept-script-base-url">base URL</span> and <var>specifier</var>.</p></li>
module specifier</span> given <var>base URL</var> and <var>specifier</var>.</p></li>

<li><p>Assert: <var>url</var> is never failure, because <span data-x="resolve a module
specifier">resolving a module specifier</span> must have been <a
href="#validate-requested-module-specifiers">previously successful</a> with these
same two arguments.</p></li>
specifier">resolving a module specifier</span> must have been previously successful with these
same two arguments (either <a href="#validate-requested-module-specifiers">while creating the
corresponding module script</a>, or in <span>HostImportModuleDynamically</span>).</p></li>

<li><p>Let <var>resolved module script</var> be <var>moduleMap</var>[<var>url</var>]. (This entry
must <span data-x="map exists">exist</span> for us to have gotten to this point.)</p></li>
Expand All @@ -88516,16 +88544,42 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
User agents must use the following implementation: <ref spec=JSIMPORT></p>

<ol>
<li><p>Let <var>referencing script</var> be
<var>referencingScriptOrModule</var>.[[HostDefined]].</p></li>
<li><p>Let <var>settings object</var> be the <span>current settings object</span>.</p></li>

<li><p>Let <var>base URL</var> be <var>settings object</var>'s <span>API base
URL</span>.</p></li>

<li><p>Let <var>fetch options</var> be the <span>default classic script fetch
options</span>.</p></li>

<li>
<p>If <var>referencingScriptOrModule</var> is not null, then:</p>

<ol>
<li><p>Let <var>referencing script</var> be
<var>referencingScriptOrModule</var>.[[HostDefined]].</p>

<li><p>Set <var>settings object</var> to <var>referencing script</var>'s <span>settings
object</span>.</p></li>

<li><p>Set <var>base URL</var> to <var>referencing script</var>'s <span
data-x="concept-script-base-url">base URL</span>.</p></li>

<li><p>Set <var>fetch options</var> to the <span>descendant script fetch options</span> for
<var>referencing script</var>'s <span data-x="concept-script-script-fetch-options">fetch
options</span>.</p></li>
</ol>

<p class="note">As explained above for <span>HostResolveImportedModule</span>, in the common
case, <var>referencingScriptOrModule</var> is non-null.</p>
</li>

<li>
<p>Run the following steps <span>in parallel</span>:</p>

<ol>
<li><p>Let <var>url</var> be the result of <span data-x="resolve a module specifier">resolving a
module specifier</span> given <var>referencing script</var>'s <span
data-x="concept-script-base-url">base URL</span> and <var>specifier</var>.</p></li>
module specifier</span> given <var>base URL</var> and <var>specifier</var>.</p></li>

<li>
<p>If <var>url</var> is failure, then:</p>
Expand All @@ -88541,14 +88595,9 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
</ol>
</li>

<li><p>Let <var>options</var> be the <span>descendant script fetch options</span> for
<var>referencing script</var>'s <span data-x="concept-script-script-fetch-options">fetch
options</span>.</p></li>

<li><p><span>Fetch a module script graph</span> given <var>url</var>, <var>referencing
script</var>'s <span>settings object</span>, "<code data-x="">script</code>", and
<var>options</var>. Wait until the algorithm asynchronously completes with
<var>result</var>.</p></li>
<li><p><span>Fetch a module script graph</span> given <var>url</var>, <var>settings
object</var>, "<code data-x="">script</code>", and <var>fetch options</var>. Wait until the
algorithm asynchronously completes with <var>result</var>.</p></li>

<li>
<p>If <var>result</var> is null, then:</p>
Expand Down

0 comments on commit 5355e33

Please sign in to comment.