Skip to content

Commit

Permalink
Fetch modules directly for ShadowRealms
Browse files Browse the repository at this point in the history
This avoids issues with ShadowRealms importing modules that the principal realm hasn't cached (yet).
  • Loading branch information
Ms2ger committed Nov 20, 2023
1 parent 1690f00 commit b4c7b99
Showing 1 changed file with 9 additions and 114 deletions.
123 changes: 9 additions & 114 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -103388,13 +103388,7 @@ new PaymentRequest(…); // Allowed to use
<dt><p>A <dfn data-x="synthetic-realm-settings-object-module-map" for="synthetic realm settings
object">module map</dfn></p></dt>

<dd>
<p>A <span>module map</span> that is used when importing JavaScript modules.</p>

<p class="note">Synthetic realm settings objects' module map entries are copies of successfully
fetched modules found in the principal realm's module map, so this map never contains entries
which are null or "<code data-x="">fetching</code>".</p>
</dd>
<dd><p>A <span>module map</span> that is used when importing JavaScript modules.</p></dd>
</dl>

<p><span data-x="synthetic realm">Synthetic realms</span> are created with <span data-x="global
Expand Down Expand Up @@ -104998,23 +104992,6 @@ document.querySelector("button").addEventListener("click", bound);
data-x="map exists">exists</span>, run <var>onComplete</var> given
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)], and return.</p></li>

<li>
<p>If <var>moduleMapRealm</var> is a <span>synthetic realm</span>, then:</p>

<ol>
<li><p>Let <var>script</var> be the result of
<span data-x="clone a module">cloning a module</span>
given <var>url</var>, <var>moduleType</var> and <var>moduleMapRealm</var>.</p></li>

<li><p><span data-x="map set">Set</span> <var>moduleMap</var>[(<var>url</var>,
<var>moduleType</var>)] to <var>script</var>.</p></li>

<li><p>Run <var>onComplete</var> given <var>script</var>.</p></li>

<li><p>Return.</p></li>
</ol>
</li>

<li><p><span data-x="map set">Set</span> <var>moduleMap</var>[(<var>url</var>,
<var>moduleType</var>)] to "<code data-x="">fetching</code>".</p></li>

Expand Down Expand Up @@ -105123,85 +105100,6 @@ document.querySelector("button").addEventListener("click", bound);
</li>
</ol>

<p>To <dfn>clone a module</dfn> given a <var>URL</var>, <var>moduleType</var>, and
<var>moduleMapRealm</var>, perform the following steps.</p>

<ol>
<li><p>Assert: <var>moduleMapRealm</var> is a <span>synthetic realm</span>.</p></li>

<li><p>Let <var>parentModuleMap</var> be <var>moduleMapRealm</var>'s
<span data-x="concept-principal-realm-of-realm">principal realm</span>'s <span
data-x="concept-realm-settings-object">settings object</span>'s <span
data-x="concept-settings-object-module-map">module map</span>.</p></li>

<li><p><span>Assert</span>: <var>parentModuleMap</var>[(<var>url</var>, <var>moduleType</var>)]
<span data-x="map exists">exists</span>.</p></li>

<li><p>Let <var>parentModule</var> be <var>parentModuleMap</var>[(<var>url</var>,
<var>moduleType</var>)].</p></li>

<li><p>Let <var>childModule</var> be a new <span>module script</span> that this algorithm will
subsequently initialize.</p></li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-realm">realm</span> to
<var>moduleMapRealm</var>.</p></li>

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

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-script-fetch-options">fetch
options</span> to <var>parentModule</var>'s <span
data-x="concept-script-script-fetch-options">fetch options</span>.</p></li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span> to <var>parentModule</var>'s <span data-x="concept-script-error-to-rethrow">error
to rethrow</span>.</p> <span class="XXX">Should this be cloned? Can this be an arbitrary
value?</span></li>

<li><p>Let <var>parentRecord</var> be <var>parentModule</var>'s <span
data-x="concept-script-record">record</span>.</p></li>

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

<ol>
<li><p>Let <var>parentParseError</var> be <var>parentModule</var>'s <span
data-x="concept-script-parse-error">parse error</span>.</p></li>
<li><p><span>Assert</span>: <var>parentParseError</var> is a <code>SyntaxError</code>
instance.</p></li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-parse-error">parse
error</span> to a new <code>SyntaxError</code> in <var>moduleMapRealm</var> with the same
message as <var>parentParseError</var>.</p></li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-record">record</span> to
null.</p></li>

<li><p>Return <var>childModule</var>.</p></li>
</ol>
</li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span> to null.</p></li>

<li><p class="XXX">Can <var>parentModule</var> be a CSS or JSON module?</p></li>

<li><p>Set <var>childModule</var>'s <span data-x="concept-script-record">record</span> to
a new <span>Source Text Module Record</span> { [[Realm]]: <var>moduleMapRealm</var>,
[[Environment]]: undefined, [[Namespace]]: undefined, [[Status]]: unlinked, [[EvaluationError]]:
undefined, [[HostDefined]]: <var>childModule</var>, [[ECMAScriptCode]]:
<var>parentRecord</var>.[[ECMAScriptCode]], [[Context]]: empty, [[ImportMeta]]: empty,
[[RequestedModules]]: <var>parentRecord</var>.[[RequestedModules]],
[[ImportEntries]]: <var>parentRecord</var>.[[ImportEntries]],
[[LocalExportEntries]]: <var>parentRecord</var>.[[LocalImportEntries]],
[[IndirectExportEntries]]: <var>parentRecord</var>.[[IndirectImportEntries]],
[[StarExportEntries]]: <var>parentRecord</var>.[[StarImportEntries]], [[DFSIndex]]: undefined,
[[DFSAncestorIndex]]: undefined }. <span class="XXX">Is 'unlinked' correct?</span></p></li>

<li><p>Return <var>childModule</var>.</p></li>
</ol>


<p>To <dfn>fetch a single imported module script</dfn>, given a <span>URL</span> <var>url</var>,
an <span>environment settings object</span> <var>fetchClient</var>, a <span
data-x="concept-request-destination">destination</span> <var>destination</var>, a <span>script
Expand Down Expand Up @@ -107422,8 +107320,7 @@ import "https://example.com/foo/../module2.mjs";</code></pre>

<li>
<p>If <var>moduleMapRealm</var>'s <span data-x="concept-principal-realm-of-realm">principal
realm</span>'s <span class="XXX">(can we check <var>moduleMapRealm</var> directly?)</span>
<span data-x="concept-realm-global">global object</span> implements
realm</span>'s <span data-x="concept-realm-global">global object</span> implements
<code>WorkletGlobalScope</code> or <code>ServiceWorkerGlobalScope</code>
and <var>loadState</var> is undefined, then:</p>

Expand Down Expand Up @@ -107468,8 +107365,8 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
data-x="concept-script-base-url">base URL</span>.</p></li>

<li>
<p>Set <var>moduleMapRealm</var> to <var>referencing script</var>'s <span
data-x="concept-script-realm">realm</span></p>
<p>Set <var>moduleMapRealm</var> to <var>referencingScript</var>'s <span
data-x="concept-script-realm">realm</span>.</p>

<p class="note">In the case of a dynamic import nested within a module loaded through the
<code>ShadowRealm.prototype.importValue</code> API, the realm of the script is set to the
Expand All @@ -107492,12 +107389,7 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
</div>
</li>

<li><p>Let <var>settingsObject</var> be <var>moduleMapRealm</var>'s
<span data-x="concept-principal-realm-of-realm">principal realm</span>'s
<span data-x="concept-realm-settings-object">settings object</span>.</p></li>

<li><p><span>Disallow further import maps</span> given <var>settingsObject</var>'s
<span data-x="environment settings object's realm">realm</span>.</p></li>
<li><p><span>Disallow further import maps</span> given <var>moduleMapRealm</var>.</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>referencingScript</var> and
Expand All @@ -107520,7 +107412,10 @@ import "https://example.com/foo/../module2.mjs";</code></pre>

<li><p>Let <var>destination</var> be <code data-x="">"script"</code>.</p></li>

<li><p>Let <var>fetchClient</var> be <var>settingsObject</var>.</p></li>
<li><p>Let <var>fetchClient</var> be <var>moduleMapRealm</var>'s
<span data-x="concept-principal-realm-of-realm">principal realm</span>'s
<span data-x="concept-realm-settings-object">settings object</span>.</p></li>


<li>
<p>If <var>loadState</var> is not undefined, then:</p>
Expand Down

0 comments on commit b4c7b99

Please sign in to comment.