Skip to content

Commit

Permalink
Replace invalid import attributes assertion
Browse files Browse the repository at this point in the history
When creating a module script, there is no guarantee yet that the
module's dependencies only have valid import attribute keys. Instead
of asserting that only `type` is used, this commit introduces proper
validation throwing a SyntaxError.
  • Loading branch information
nicolo-ribaudo committed Aug 11, 2023
1 parent 0593c91 commit dda740d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-finalization-registry-objects"><code>FinalizationRegistry</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-regexp-regular-expression-objects"><code>RegExp</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-sharedarraybuffer-objects"><code>SharedArrayBuffer</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-syntaxerror"><code>SyntaxError</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-typeerror"><code>TypeError</code></dfn> class</li>
<li>The <dfn data-x="js-RangeError" data-x-href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror"><code>RangeError</code></dfn> class</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-weak-ref-objects"><code>WeakRef</code></dfn> class</li>
Expand Down Expand Up @@ -103790,6 +103791,27 @@ document.querySelector("button").addEventListener("click", bound);
<var>requested</var> of <var>result</var>.[[RequestedModules]]:</p>

<ol>
<li>
<p>If <var>requested</var>.[[Attributes]] contains a <span>Record</span> <var>entry</var>
such that <var>entry</var>.[[Key]] is not "<code data-x="">type</code>", then:</p>

<ol>
<li><p>Let <var>error</var> be a new <code>SyntaxError</code> exception.</p></li>

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

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

<p class="note">The JavaScript specification re-performs this validation when lodaing
<var>script</var>'s dependencies. It is duplicated here to skip unnecessary work given that,
in case of an invalid attribute key, loading the module graph would fail so we can
exit early and skip unnecessary work. Additionally, this makes the errors reported for invalid
static imports consistent with dynamic imports, for which invalid attributes are reported
before calling into HTML and thus before validating the imported specifier.</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>script</var> and
<var>requested</var>.[[Specifier]], catching any exceptions.</p></li>
Expand Down

0 comments on commit dda740d

Please sign in to comment.