From 914e7d5cba1718a6ef1f4937cb076bf46a74c7f0 Mon Sep 17 00:00:00 2001
From: Daniel Clark [LegacyFactoryFunction]
[LegacyLenientThis]
Setting the attribute to an ASCII case-insensitive match for the string
- "module
" means that the script is a module script, to be
- interpreted according to the JavaScript Module top-level
- production. Module scripts are not affected by the defer
- attribute, but are affected by the async
attribute
- (regardless of the state of the src
attribute).
module
" means that the script is a module script. If it has
+ a JavaScript MIME type, or if the script is embedded inline, then it will be
+ interpreted as a JavaScript module script according to the JavaScript Module top-level production; if it has a JSON MIME
+ type, then it will be interpreted as a JSON module script. Module scripts
+ are not affected by the defer
attribute, but are
+ affected by the async
attribute (regardless of the state
+ of the src
attribute).
Setting the attribute to any other value means that the script is a data
block, which is not processed. None of the script
attributes (except HTMLScriptElement : HTMLElement {
scripts. By using a valid MIME type string now, you ensure that your data block will not
ever be reinterpreted as a different script type, even in future user agents.
Classic scripts and module
- scripts can be embedded inline, or be imported from an external file using the Classic scripts and JavaScript module scripts can be embedded inline, or be imported from an external
+ file using the
src
attribute, which if specified gives the URL
of the external script resource to use. If src
is specified,
- it must be a valid non-empty URL potentially surrounded by spaces. The contents of
- inline script
elements, or the external script resource, must conform with the
- requirements of the JavaScript specification's Script or Module productions, for classic
- scripts and module scripts respectively.
The contents of inline script
elements, or the external script resource, must
+ conform with the requirements of the JavaScript specification's Script or Module productions, for classic scripts and JavaScript module scripts respectively.
The contents of the external script resource for JSON module + scripts must conform to the requirements of the JSON specification .
When used to include data blocks, the data must be embedded
inline, the format of the data must be given using the type
@@ -57310,7 +57320,7 @@ o............A....e
The following sample shows how a script
element can be used to include an
- external module script.
+ external JavaScript module script.
<script type="module" src="app.mjs"></script>
@@ -57321,37 +57331,37 @@ o............A....e
Additionally, if code from another script
element in the same Window
imports the module from app.mjs
(e.g. via import
- "./app.mjs";
), then the same module script created by the
+ "./app.mjs";), then the same JavaScript module script created by the
former script
element will be imported.
This example shows how to include a module script for modern user agents, and a - classic script for older user agents:
+This example shows how to include a JavaScript module script for modern user + agents, and a classic script for older user agents:
<script type="module" src="app.mjs"></script>
<script nomodule defer src="classic-app-bundle.js"></script>
- In modern user agents that support module scripts, the
- script
element with the nomodule
attribute
- will be ignored, and the script
element with a type
of "module
" will be fetched and
- evaluated (as a module script). Conversely, older user agents will ignore the
+
In modern user agents that support JavaScript module
+ scripts, the script
element with the nomodule
attribute will be ignored, and the
script
element with a type
of "module
", as that is an unknown script type for them — but they will have no
- problem fetching and evaluating the other script
element (as a classic
- script), since they do not implement the nomodule
attribute.
script
element with a
+ type
of "module
", as that is an
+ unknown script type for them — but they will have no problem fetching and evaluating the other
+ script
element (as a classic script), since they do not implement the
+ nomodule
attribute.
The following sample shows how a script
element can be used to write an inline
- module script that performs a number of substitutions on the document's text, in
- order to make for a more interesting reading experience (e.g. on a news site): JavaScript module script that performs a number of substitutions on the document's
+ text, in order to make for a more interesting reading experience (e.g. on a news site):
<script type="module">
@@ -57383,12 +57393,30 @@ o............A....e
walkAllTextNodeDescendants(document.body, substitute);
</script>
- Some notable features gained by using a module script include the ability to import functions
- from other JavaScript modules, strict mode by default, and how top-level declarations do not
- introduce new properties onto the global object. Also note that no matter where
- this script
element appears in the document, it will not be evaluated until both
- document parsing has complete and its dependency (dom-utils.mjs
) has been
- fetched and evaluated.
Some notable features gained by using a JavaScript module script include the ability to import
+ functions from other JavaScript modules, strict mode by default, and how top-level declarations
+ do not introduce new properties onto the global object. Also note that no matter
+ where this script
element appears in the document, it will not be evaluated until
+ both document parsing has complete and its dependency (dom-utils.mjs
) has
+ been fetched and evaluated.
The following sample shows how to you can import a JSON module script from inside + a JavaScript module script:
+ +<script type="module">
+import peopleInSpace from "http://api.open-notify.org/astros.json";
+
+const list = document.querySelector("#people-in-space");
+for (const { craft, name } of peopleInSpace.people) {
+ const li = document.createElement("li");
+ li.textContent = `${name} / ${craft}`;
+ list.append(li);
+}
+</script>
A script is one of two possible A script is one of three possible structs. All scripts have:
Either a Script Record, for classic - scripts; a Source Text Module Record, for module scripts; or null. In the former two cases, it represents a parsed script; - null represents a failure parsing.
One of the following:
+ +a script record, for classic + scripts;
a Source Text Module Record, for JavaScript module scripts;
a Synthetic Module Record, for JSON + module scripts; or
null, representing a parsing failure.
Module scripts can be classified into two types:
+ +A module script is a JavaScript module script if + its record is a Source Text Module + Record.
A module script is a JSON module script if its record is a Synthetic Module Record, and it + was created via the create a JSON module + script algorithm. JSON module scripts represent a parsed JSON document.
+ + +As JSON documents do not import dependent modules, and do not throw exceptions + on evaluation, the fetch options and + base URL of a JSON module script are + always null.
+The active script is determined by the following algorithm:
Let script be the result of creating a module script using - source text, settings object, base URL, and +
Let script be the result of creating a JavaScript module script + using source text, settings object, base URL, and options.
If script is null, asynchronously complete this algorithm with null, and abort @@ -87047,8 +87116,8 @@ interface ApplicationCache : EventTarget {
Let options be the descendant script fetch options for module script's fetch options.
Assert: options is not null, as module script is a module - script.
Assert: options is not null, as module script is a JavaScript + module script.
For each url in urls, perform the @@ -87169,25 +87238,53 @@ interface ApplicationCache : EventTarget {
response's status is not an ok status
The result of extracting a MIME type from - response's header list is not a - JavaScript MIME type
+Let type be the result of extracting a + MIME type from response's header + list.
-For historical reasons, fetching a - classic script does not include MIME type checking. In contrast, module scripts will - fail to load if they are not of a correct MIME type.
-For historical reasons, fetching a + classic script does not include MIME type checking. In contrast, module scripts' + interpretation is driven by their MIME type, and they will fail to load if they are not of + a supported MIME type.
-Let source text be the result of UTF-8 - decoding response's body.
Let module script be null.
+ +If the resource does not have a MIME type which HTML knows how to handle + as a module, then module script will remain null, which is interpreted as + failure.
+If type is a JavaScript MIME type, then:
+ +Let source text be the result of UTF-8 + decoding response's body.
Set module script to the result of creating a JavaScript module + script given source text, module map settings object, + response's url, and + options.
If type is a JSON MIME type, then:
-Let module script be the result of creating a module script given - source text, module map settings object, response's url, and options.
Let source text be the result of UTF-8 + decoding response's body.
Set module script to the result of creating a JSON module + script given source text and module map settings object.
Set moduleMap[url] to module @@ -87217,36 +87314,43 @@ interface ApplicationCache : EventTarget { then return moduleScript's parse error.
Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.
If moduleScript's record is a + Cyclic Module Record:
-Let childURLs be the list obtained by calling - resolve a module specifier once for each item of childSpecifiers, given - moduleScript's base URL and that item. - (None of these will ever fail, as otherwise moduleScript would have been marked as - itself having a parse error.)
Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.
Let childModules be the list obtained by getting each value in moduleMap whose key is given by an - item of childURLs.
Let childURLs be the list obtained by calling + resolve a module specifier once for each item of childSpecifiers, given + moduleScript's base URL and that item. + (None of these will ever fail, as otherwise moduleScript would have been marked as + itself having a parse error.)
For each childModule of - childModules:
+Let childModules be the list obtained by getting each value in moduleMap whose key is given by an + item of childURLs.
Assert: childModule is a module script (i.e., it is not "fetching
" or null); by now all module
- scripts in the graph rooted at moduleScript will have successfully been
- fetched.
For each childModule of + childModules:
+ +Assert: childModule is a module script (i.e., it is not "fetching
" or null); by now all module
+ scripts in the graph rooted at moduleScript will have successfully been
+ fetched.
If discoveredSet already contains - childModule, continue.
If discoveredSet already contains + childModule, continue.
Let childParseError be the result of finding the first parse - error given childModule and discoveredSet.
Let childParseError be the result of finding the first parse + error given childModule and discoveredSet.
If childParseError is not null, return childParseError.
If childParseError is not null, return childParseError.
Return script.
To create a module script, given a - string source, an environment settings object - settings, a URL baseURL, and some script fetch - options options:
+To create a JavaScript module script, + given a string source, an environment settings + object settings, a URL baseURL, and some script + fetch options options:
If scripting is disabled for @@ -87387,6 +87491,53 @@ interface ApplicationCache : EventTarget {
Return script.
To create a JSON module script, given a + string source and an environment settings object settings:
+ +Let script be a new module script that this algorithm will + subsequently initialize.
Set script's settings object to settings.
Set script's base URL and + fetch options to null.
Set script's parse error and + error to rethrow to null.
Let json be ? Call(%JSONParse%, undefined, + « source »).
+ +If this throws an exception, set script's parse error to that exception, and return + script.
+Set script's record to the result + of creating a synthetic + module record with a default export of json with settings.
Return script.
To create a synthetic module record with a default export of a JavaScript value + value with an environment settings object settings:
+ +Return CreateSyntheticModule(« "default" », the following steps, + settings's Realm, + value) with the following steps given module as an argument:
+ +To run a classic script given a classic script @@ -88491,6 +88642,9 @@ import "https://example.com/foo/../module2.mjs";
Set base URL to referencing script's base URL.
Assert: base URL is not null, as referencing script is a + classic script or a JavaScript module script.
Set fetch options to the descendant script fetch options for referencing script's fetch options.
Assert: Neither base URL nor fetch options is null, as + referencing script is a classic script or a JavaScript module + script.
As explained above for HostResolveImportedModule, in the common @@ -88612,6 +88770,10 @@ import "https://example.com/foo/../module2.mjs";
Let module script be moduleRecord.[[HostDefined]].
Assert: module script's base + URL is not null, as module script is a JavaScript module + script.
Let urlString be module script's base URL, serialized.
Let base URL be initiating script's base URL.
Assert: base URL is not null, as initiating script is a + classic script or a JavaScript module script.
Let fetch options be a script fetch options whose cryptographic nonce is initiating
From b058240e31d99d1c1b7233a4ce01458231a74480 Mon Sep 17 00:00:00 2001
From: Daniel Clark
<script type="module">
-import peopleInSpace from "http://api.open-notify.org/astros.json";
+import peopleInSpace from "http://api.open-notify.org/astros.json" if { type: "json" };
const list = document.querySelector("#people-in-space");
for (const { craft, name } of peopleInSpace.people) {
@@ -87083,16 +87084,17 @@ interface ApplicationCache : EventTarget {
record.[[RequestedModules]] is empty,
asynchronously complete this algorithm with module script.
Let urls be a new empty list.
Let moduleRequests be a new empty list.
For each string requested of - record.[[RequestedModules]],
+For each ModuleRequest Record + requested of record.[[RequestedModules]],
Let url be the result of resolving a module specifier given module script's base URL and requested.
Assert: url is never failure, because resolving a module specifier must have been ApplicationCache : EventTarget { url, then:
Append url to urls.
Append requested to + moduleRequests.
Append url to visited set.
For each url in urls, perform the - internal module script graph fetching procedure given url, fetch - client settings object, destination, options, module - script's settings object, visited set, and module - script's base URL. If the caller of this +
For each moduleRequest in + moduleRequests, perform the internal module script graph fetching + procedure given moduleRequest, fetch client settings object, + destination, options, module script's settings + object, visited set, and module script's base URL. If the caller of this algorithm specified custom perform the fetch steps, pass those along while performing the internal module script graph fetching procedure.
@@ -87143,21 +87147,30 @@ interface ApplicationCache : EventTarget {To perform the internal module script graph fetching procedure given a - url, a fetch client settings object, a destination, some - options, a module map settings object, a visited set, and a + moduleRequest, a fetch client settings object, a destination, + some options, a module map settings object, a visited set, and a referrer, perform these steps. The algorithm will asynchronously complete with either null (on failure) or a module script (on success).
Let url be the result of resolving + a module specifier given referrer and + moduleRequst.[[Specifier]].
Assert: url is never failure, because resolving a module specifier must have been previously successful with these same two + arguments.
Assert: visited set contains url.
Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - referrer, and with the top-level module fetch flag unset. If the caller of - this algorithm specified custom perform the - fetch steps, pass those along while fetching a - single module script.
+ referrer, moduleRequest, and with the + top-level module fetch flag unset. If the caller of this algorithm specified custom + perform the fetch steps, pass those along + while fetching a single module script.Return from this algorithm, and run the following steps when fetching a single module script asynchronously completes with @@ -87176,11 +87189,21 @@ interface ApplicationCache : EventTarget {
To fetch a single module script, given a url, a fetch client settings object, a destination, some options, a module map - settings object, a referrer, and a top-level module fetch flag, run - these steps. The algorithm will asynchronously complete with either null (on failure) or a - module script (on success).
+ settings object, a referrer, an optional moduleRequest, and + a top-level module fetch flag, run these steps. The algorithm will asynchronously + complete with either null (on failure) or a module script (on success).If moduleRequest was given and if moduleRequest.[[Attributes]]
+ has a Record entry such that entry.[[Key]] is "type"
, then
+ let module type be entry.[[Value]]
+
Otherwise let module type be undefined.
+If module type is neither undefined nor "json"
, asynchronously complete this algorithm
+ with null, and abort these steps
Let moduleMap be module map settings object's module map.
If moduleMap[url] exists, - asynchronously complete this algorithm with moduleMap[url], and abort - these steps.
If moduleMap[url] exists, then:
+ +If any of the following conditions are met, asynchronously complete this algorithm + with moduleMap[url], and abort these steps.
+ +moduleMap[url] is a JavaScript module script + and module type is undefined.
moduleMap[url] is a JSON module script
+ and module type is "json"
.
Otherwise, asynchronously complete this algorithm with null, and abort these steps
+Set moduleMap[url] to "fetching
".
Let type be the result of extracting a
+ Let MIME type be the result of extracting a
MIME type from response's header
list.
If type is a JavaScript MIME type, then:
+If MIME type is a JavaScript MIME type and module type is + undefined, then:
Let source text be the result of UTF-8 @@ -87275,7 +87317,8 @@ interface ApplicationCache : EventTarget {
If type is a JSON MIME type, then:
+If MIME type is a JSON MIME type and module type is
+ "json"
, then:
Let source text be the result of UTF-8 @@ -87319,12 +87362,13 @@ interface ApplicationCache : EventTarget { Cyclic Module Record:
Let childSpecifiers be the value of moduleScript's Let moduleRequests be the value of moduleScript's record's [[RequestedModules]] internal slot.
Let childURLs be the list obtained by calling - resolve a module specifier once for each item of childSpecifiers, given - moduleScript's base URL and that item. + resolve a module specifier once for each item moduleRequest of + moduleRequest, given moduleScript's base URL and moduleRequest.[[Specifier]]. (None of these will ever fail, as otherwise moduleScript would have been marked as itself having a parse error.)
For each string requested of - result.[[RequestedModules]]:
+For each ModuleRequest record + requested of result.[[RequestedModules]]:
Let url be the result of resolving a module specifier given script's base - URL and requested.
If url is failure, then:
@@ -121394,6 +121438,7 @@ INSERT INTERFACES HERE Daniel Brumbaugh Keeney, Daniel Buchner, Daniel Cheng, + Daniel Clark, Daniel Davis, Daniel Ehrenberg, Daniel Glazman, From d0137f5478da1e5c9c61cd3df02fd276ecf74e0e Mon Sep 17 00:00:00 2001 From: Daniel ClarkTo fetch an import() module script graph given a specifier, a base
- URL, a settings object, and some options, run these steps. The
- algorithm will asynchronously complete with either null (on failure) or a module
+ To fetch an import() module script graph given a moduleRequest, a
+ base URL, a settings object, and some options, run these steps.
+ The algorithm will asynchronously complete with either null (on failure) or a module
script (on success). Let url be the result of resolving a
- module specifier given base URL and specifier.
given base URL and moduleRequest.[[Specifier]].
If url is failure, then asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, settings
object, "script
", options, settings object,
- "client
", and with the top-level module fetch flag set. If the
- caller of this algorithm specified custom perform
- the fetch steps, pass those along as well. Wait until the algorithm asynchronously
- completes with result.
client
", moduleRequest, and with the top-level module
+ fetch flag set. If the caller of this algorithm specified custom perform the fetch steps, pass those along as well.
+ Wait until the algorithm asynchronously completes with result.If result is null, asynchronously complete this algorithm with null, and abort these steps.
JavaScript contains an implementation-defined HostResolveImportedModule abstract operation. User @@ -88710,7 +88711,8 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-settings-object-module-map">module map.
Let url be the result of resolving a - module specifier given base URL and specifier.
Assert: url is never failure, because resolving a module specifier must have been previously successful with these @@ -88731,7 +88733,7 @@ import "https://example.com/foo/../module2.mjs";
JavaScript contains an implementation-defined HostImportModuleDynamically abstract operation. @@ -88772,9 +88774,9 @@ import "https://example.com/foo/../module2.mjs"; case, referencingScriptOrModule is non-null.
Fetch an import() module script graph given specifier, base - URL, settings object, and fetch options. Wait until the algorithm - asynchronously completes with result.
Fetch an import() module script graph given moduleRequest, + base URL, settings object, and fetch options. Wait until the + algorithm asynchronously completes with result.
If result is null, then:
@@ -88784,7 +88786,7 @@ import "https://example.com/foo/../module2.mjs";TypeError
, [[Target]]: empty }.Perform FinishDynamicImport(referencingScriptOrModule, - specifier, promiseCapability, completion).
Return.
If running the module script throws an exception, then perform - FinishDynamicImport(referencingScriptOrModule, specifier, + FinishDynamicImport(referencingScriptOrModule, moduleRequest, promiseCapability, the thrown exception completion).
Otherwise, perform - FinishDynamicImport(referencingScriptOrModule, specifier, + FinishDynamicImport(referencingScriptOrModule, moduleRequest, promiseCapability, NormalCompletion(undefined)).
Return undefined.
Let module script be null.
-If the resource does not have a MIME type which HTML knows how to handle - as a module, then module script will remain null, which is interpreted as - failure.
+If the resource does not have a MIME type which HTML knows how to handle + as a module or if the MIME type does not match the type specified in moduleRequest, + then module script will remain null, which is interpreted as failure.
+ +In the former case where a non-module MIME type is received, a null entry is added to + moduleMap so that future attempts to fetch a module at url will always + fail. On the other hand for the case where the MIME type is valid but does not match the + requested module type, nothing is cached in moduleMap, meaning that + future attempts to fetch the same url in another module graph could succeed if the correct + type were specified.
+If MIME type is a JavaScript MIME type and module type is - undefined, then:
+If MIME type is a JavaScript MIME type, then:
-Let source text be the result of UTF-8 - decoding response's body.
If module type is not undefined, asynchronously complete this algorithm with + null, and abort these steps.
Set module script to the result of creating a JavaScript module - script given source text, module map settings object, - response's url, and - options.
Let source text be the result of UTF-8 + decoding response's body.
Set module script to the result of creating a JavaScript module + script given source text, module map settings object, + response's url, and + options.
If MIME type is a JSON MIME type and module type is
- "json"
, then:
If MIME type is a JSON MIME type, then:
+If module type is not "json"
, asynchronously complete
+ this algorithm with null, and abort these steps.
Let source text be the result of UTF-8 - decoding response's body.
Let source text be the result of UTF-8 + decoding response's body.
Set module script to the result of creating a JSON module - script given source text and module map settings object.
Set module script to the result of creating a JSON module + script given source text and module map settings object.
Fetch a single module script given url, settings
object, "script
", options, settings object,
- "client
", and with the top-level module fetch flag set. If the
- caller of this algorithm specified custom perform
- the fetch steps, pass those along as well. Wait until the algorithm asynchronously
- completes with result.
client
", with the module type must match flag set, and with
+ the top-level module fetch flag set. If the caller of this algorithm specified custom
+ perform the fetch steps, pass those along as
+ well. Wait until the algorithm asynchronously completes with result.If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, settings
object, "script
", options, settings object,
- "client
", moduleRequest, and with the top-level module
- fetch flag set. If the caller of this algorithm specified custom perform the fetch steps, pass those along as well.
- Wait until the algorithm asynchronously completes with result.
client
", moduleRequest, with the module type must
+ match flag set, and with the top-level module fetch flag set. If the caller of
+ this algorithm specified custom perform the
+ fetch steps, pass those along as well. Wait until the algorithm asynchronously completes
+ with result.
If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, settings
object, destination, options, settings object, "client
", and with the top-level module fetch flag set. Wait until
- algorithm asynchronously completes with result.
Asynchronously complete this algorithm with result, but do not abort these steps.
Optionally, perform the following steps:
+If result is not null, optionally perform the following steps:
Let visited set be « url ».
Fetch a single module script given url, fetch client settings
object, destination, options, module map settings object,
- "client
", and with the top-level module fetch flag set. If the
- caller of this algorithm specified custom perform
- the fetch steps, pass those along as well. Wait until the algorithm asynchronously
- completes with result.
client
", with the module type must match flag set, and with
+ the top-level module fetch flag set. If the caller of this algorithm specified custom
+ perform the fetch steps, pass those along as
+ well. Wait until the algorithm asynchronously completes with result.If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - referrer, moduleRequest, and with the - top-level module fetch flag unset. If the caller of this algorithm specified custom - perform the fetch steps, pass those along - while fetching a single module script.
+ referrer, moduleRequest, with the module type must match flag + set, and with the top-level module fetch flag unset. If the caller of this algorithm + specified custom perform the fetch steps, + pass those along while fetching a single module + script.Return from this algorithm, and run the following steps when fetching a single module script asynchronously completes with @@ -87190,9 +87193,10 @@ interface ApplicationCache : EventTarget {
To fetch a single module script, given a url, a fetch client settings object, a destination, some options, a module map - settings object, a referrer, an optional moduleRequest, and - a top-level module fetch flag, run these steps. The algorithm will asynchronously - complete with either null (on failure) or a module script (on success).
+ settings object, a referrer, an optional moduleRequest, a + module type must match flag, and a top-level module fetch flag, run these + steps. The algorithm will asynchronously complete with either null (on failure) or a + module script (on success).The module type must match flag is unset.
moduleMap[url] is a JavaScript module script and module type is undefined.
If MIME type is a JavaScript MIME type, then:
If module type is not undefined, asynchronously complete this algorithm with - null, and abort these steps.
If the module type must match flag is set and module type is not + undefined, asynchronously complete this algorithm with null, and abort these steps.
Let source text be the result of UTF-8 decoding response's body.
If MIME type is a JSON MIME type, then:
If module type is not "json"
, asynchronously complete
- this algorithm with null, and abort these steps.
If the module type must match flag is set and module type is not
+ "json"
, asynchronously complete this algorithm with null, and abort
+ these steps.
Let source text be the result of UTF-8 decoding response's body.
Let json be ? Call(%JSONParse%, undefined, +
Let json be ? Call(%JSON.Parse%, undefined, « source »).
If this throws an exception, set script's
Date: Mon, 22 Jun 2020 11:37:00 -0700
Subject: [PATCH 07/56] Fix typo in JSON modules example and add note on
requiring JSON MIME type.
---
source | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/source b/source
index 1b7e9f911a8..03d4602a4fc 100644
--- a/source
+++ b/source
@@ -57405,7 +57405,7 @@ o............A....e
The following sample shows how to you can import a JSON module script from inside
+ The following sample shows how a JSON module script can be imported from inside
a JavaScript module script: MIME type checking for module scripts is strict. In order for the fetch of the
+ JSON module script to succeed, the HTTP reponse must have a
+ JSON MIME type, for example Otherwise, asynchronously complete this algorithm with null, and abort these steps Otherwise, asynchronously complete this algorithm with null, and abort these steps. User agents that support JavaScript must also implement the import attributes
+ proposal. The following term is defined there, and used in this specification: Users agents that support JavaScript must also implement ECMAScript
Internationalization API. If result is not null, optionally perform the following steps: Optionally, perform the following steps: Let visited set be « url ». User agents that support JavaScript must also implement the import attributes
- proposal. The following term is defined there, and used in this specification: Users agents that support JavaScript must also implement ECMAScript
@@ -87585,37 +87584,18 @@ interface ApplicationCache : EventTarget {
error to rethrow to null. Let json be ? Call(%JSON.Parse%, undefined,
- « source »). Let result be ParseJSONModule(source).
If this throws an exception, set script's parse error to that exception, and return
script. Set script's record to the result
- of creating a synthetic
- module record with a default export of json with settings. Set script's record to result.
Return script. To create a synthetic module record with a default export of a JavaScript value
- value with an environment settings object settings: Return CreateSyntheticModule(« "default" », the following steps,
- settings's Realm,
- value) with the following steps given module as an argument: To run a classic script given a classic script
From a2d42607ad7241e9ce4827d2e3224035305582ca Mon Sep 17 00:00:00 2001
From: Daniel Clark If the resource does not have a MIME type which HTML knows how to handle
as a module or if the MIME type does not match the type specified in moduleRequest,
- then module script will remain null, which is interpreted as failure. In the former case where a non-module MIME type is received, a null entry is added to
moduleMap so that future attempts to fetch a module at url will always
fail. On the other hand for the case where the MIME type is valid but does not match the
- requested module type, nothing is cached in moduleMap, meaning that
- future attempts to fetch the same url in another module graph could succeed if the correct
- type were specified. If MIME type is a JavaScript MIME type, then: If the module type must match flag is set and module type is not
- undefined, asynchronously complete this algorithm with null, and abort these steps. Let source text be the result of UTF-8
decoding response's body. If MIME type is a JSON MIME type, then: If the module type must match flag is set and module type is not
- Let source text be the result of UTF-8
decoding response's body. Set moduleMap[url] to module
- script, and asynchronously complete this algorithm with module script. It is intentional that the module map is keyed by the request URL, whereas the ApplicationCache : EventTarget {
set to the response URL. The former is used to
deduplicate fetches, while the latter is used for URL resolution. If any of the following conditions are met, asynchronously complete this algorithm
+ with module script. The module type must match flag is unset. module script is a JavaScript module script
+ and module type is undefined. module script is a JSON module script
+ and module type is Otherwise, asynchronously complete this algorithm with null. To find the first parse error given a root
From f79c01f2a77f1ccaf9d4aa68da70b1eedac251fe Mon Sep 17 00:00:00 2001
From: Daniel Clark
+ <script type="module">
@@ -57419,6 +57419,13 @@ for (const { craft, name } of peopleInSpace.people) {
}
</script>
Content-Type: text/json
. On the
+ other hand, if the if { type: "json" }
part of the statement is omitted,
+ it is assumed that the intent is to import a JavaScript module script, and the fetch
+ will fail if the HTTP response has a MIME type that is not a JavaScript MIME type.
+
+
+
[LegacyFactoryFunction]
-
-
-
- Calling scripts
-
-
"json"
, asynchronously complete this algorithm with null, and abort
- these steps.
+
+
+ "json"
.
Fetch a single module script given url, settings
object, "script
", options, settings object,
- "client
", with the module type must match flag set, and with
- the top-level module fetch flag set. If the caller of this algorithm specified custom
- perform the fetch steps, pass those along as
- well. Wait until the algorithm asynchronously completes with result.
client
", and with the top-level module fetch flag set. If the
+ caller of this algorithm specified custom perform
+ the fetch steps, pass those along as well. Wait until the algorithm asynchronously
+ completes with result.If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, settings
object, "script
", options, settings object,
- "client
", moduleRequest, with the module type must
- match flag set, and with the top-level module fetch flag set. If the caller of
- this algorithm specified custom perform the
- fetch steps, pass those along as well. Wait until the algorithm asynchronously completes
- with result.
client
", moduleRequest, and with the
+ top-level module fetch flag set. If the caller of this algorithm specified custom
+ perform the fetch steps, pass those along as
+ well. Wait until the algorithm asynchronously completes with result.If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, settings
object, destination, options, settings object, "client
", with the module type must match flag unset, and with the
- top-level module fetch flag set. Wait until algorithm asynchronously completes with
- result.
Asynchronously complete this algorithm with result, but do not abort these steps.
Fetch a single module script given url, fetch client settings
object, destination, options, module map settings object,
- "client
", with the module type must match flag set, and with
- the top-level module fetch flag set. If the caller of this algorithm specified custom
- perform the fetch steps, pass those along as
- well. Wait until the algorithm asynchronously completes with result.
client
", and with the top-level module fetch flag set. If the
+ caller of this algorithm specified custom perform
+ the fetch steps, pass those along as well. Wait until the algorithm asynchronously
+ completes with result.
If result is null, asynchronously complete this algorithm with null, and abort these steps.
Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - referrer, moduleRequest, with the module type must match flag - set, and with the top-level module fetch flag unset. If the caller of this algorithm - specified custom perform the fetch steps, - pass those along while fetching a single module - script.
+ referrer, moduleRequest, and with the + top-level module fetch flag unset. If the caller of this algorithm specified custom + perform the fetch steps, pass those along + while fetching a single module script.Return from this algorithm, and run the following steps when fetching a single module script asynchronously completes with @@ -87206,10 +87203,9 @@ interface ApplicationCache : EventTarget {
To fetch a single module script, given a url, a fetch client settings object, a destination, some options, a module map - settings object, a referrer, an optional moduleRequest, a - module type must match flag, and a top-level module fetch flag, run these - steps. The algorithm will asynchronously complete with either null (on failure) or a - module script (on success).
+ settings object, a referrer, an optional moduleRequest, and a + top-level module fetch flag, run these steps. The algorithm will asynchronously + complete with either null (on failure) or a module script (on success).If moduleMap[url] exists, then:
- -If any of the following conditions are met, asynchronously complete this algorithm - with moduleMap[url], and abort these steps.
+If moduleMap[url] is a fetch response, then asynchronously complete this algorithm with the + result of creating a module script + with matching type given url, requested type, + moduleMap[url], options, and module map settings + object, and abort these steps.
The module type must match flag is unset.
moduleMap[url] is a JavaScript module script - and module type is undefined.
moduleMap[url] is a JSON module script
- and module type is "json"
.
Otherwise, asynchronously complete this algorithm with null, and abort these steps.
-If moduleMap[url] is null, asynchronously complete this algorithm + with null, and abort these steps.
Set moduleMap[url] to "fetching
".
response's status is not an ok status
Let MIME type be the result of extracting a - MIME type from response's header - list.
+The result of extracting a + MIME type from response's header + list is neither a JavaScript MIME type nor a JSON MIME type. +
-For historical reasons, fetching a - classic script does not include MIME type checking. In contrast, module scripts' - interpretation is driven by their MIME type, and they will fail to load if they are not of - a supported MIME type.
+For historical reasons, fetching a + classic script does not include MIME type checking.
+ +In contrast, module scripts' interpretation is driven by their MIME type, and they will + fail to load if they are not of a supported MIME type. If the resource does not have a MIME + type which HTML knows how to handle as a module then this algorithm will complete with null, + which is interpreted as failure, and a null entry is added to moduleMap so that + future attempts to fetch a module at url will always fail.
+Let module script be null.
+Set moduleMap[url] to + response.
If the resource does not have a MIME type which HTML knows how to handle - as a module or if the MIME type does not match the type specified in moduleRequest, - then this algorithm will complete with null, which is interpreted as failure.
- -In the former case where a non-module MIME type is received, a null entry is added to - moduleMap so that future attempts to fetch a module at url will always - fail. On the other hand for the case where the MIME type is valid but does not match the - requested module type, module script is cached in moduleMap, - meaning that future attempts to fetch the same url in another module graph could succeed if the - requested type matched the MIME type, without triggering another network request. An important - detail of this process is that parsing a module and inserting it into the module map is - side-effect-free, so a module will have no observable effect until it is evaluated, which can - only happen after the type is matched.
+If the MIME type is valid but does not match the requested module type, then + create a module script with matching type will fail and response will + remain cached in the module map. Then, future attempts to fetch the same url in + another module graph could succeed if the requested type matched the MIME type, without + triggering another network request. Caching response instead of creating and + caching a module script at this point is done to ensure that no side-effects occur until there + is a type match.
+ +If requested type does turn out to match the MIME type then create a module + script with matching type will create a module script and overwrite this module + map entry with it.
Asychronously complete this algorithm with the result of creating a module script with matching + type given url, requested type, response, + options, and module map settings object.
To create a module script with matching type, given a url, a + requested type, a fetch response + response, some options, and module map settings object, + run these steps. The algorithm will complete with either null (on failure) or a + module script (on success).
+ +Let module script be null.
Let MIME type be the result of extracting a + MIME type from response's header + list.
If MIME type is a JavaScript MIME type, then:
+If MIME type is a JavaScript MIME type and module type is + undefined, then:
-Let source text be the result of UTF-8 - decoding response's body.
Set module script to the result of creating a JavaScript module - script given source text, module map settings object, + script given source, module map settings object, response's url, and options.
If MIME type is a JSON MIME type, then:
-If MIME type is a JSON MIME type and module type is
+ "json"
, then:
Let source text be the result of UTF-8 - decoding response's body.
Set module script to the result of creating a JSON module script given source text and module map settings object.
Set moduleMap[url] to module - script
- -It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is - set to the response URL. The former is used to - deduplicate fetches, while the latter is used for URL resolution.
+If any of the following conditions are met, asynchronously complete this algorithm - with module script.
- -The module type must match flag is unset.
If module script is not null, then:
-module script is a JavaScript module script - and module type is undefined.
Let moduleMap be module map settings object's module map.
module script is a JSON module script
- and module type is "json"
.
Set moduleMap[url] to module script.
Otherwise, asynchronously complete this algorithm with null.
+It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is + set to the response URL. The former is used to + deduplicate fetches, while the latter is used for URL resolution.
+ +Return module script.
To find the first parse error given a root @@ -88572,10 +88573,11 @@ document.querySelector("button").addEventListener("click", bound);
A module map is a map of URL records to values that are either a module script,
- null (used to represent failed fetches), or a placeholder value "fetching
". Module maps are used to ensure
- that imported JavaScript modules are only fetched, parsed, and evaluated once per
- Document
or worker.
fetching
", or a fetch response.
+ Module maps are used to ensure that imported JavaScript modules
+ are only fetched, parsed, and evaluated once per Document
or worker.
Since module maps are keyed by URL, the following code will
From 55c9ed9bef7b43175624858d1e1fd0d130231789 Mon Sep 17 00:00:00 2001
From: Daniel Clark in Let moduleMap be module map settings object's module map. Set moduleMap[url] to module script. Set moduleMap[url] to module script. It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is
- set to the response URL. The former is used to
- deduplicate fetches, while the latter is used for URL resolution. It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is
+ set to the response URL. The former is used to
+ deduplicate fetches, while the latter is used for URL resolution., which the Travis CI build doesn't like.
---
source | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/source b/source
index 4640f9387f1..468b9b51647 100644
--- a/source
+++ b/source
@@ -87377,13 +87377,15 @@ interface ApplicationCache : EventTarget {
In contrast, module scripts' interpretation is driven by their MIME type, and they will - fail to load if they are not of a supported MIME type. If the resource does not have a MIME + fail to load if they are not of a supported MIME type. If the resource does not have a MIME type which HTML knows how to handle as a module then this algorithm will complete with null, which is interpreted as failure, and a null entry is added to moduleMap so that future attempts to fetch a module at url will always fail.
@@ -87309,9 +87309,9 @@ interface ApplicationCache : EventTarget {If the MIME type is valid but does not match the requested module type, then create a module script with matching type will fail and response will - remain cached in the module map. Then, future attempts to fetch the same url in + remain cached in the module map. Then, future attempts to fetch the same url in another module graph could succeed if the requested type matched the MIME type, without - triggering another network request. Caching response instead of creating and + triggering another network request. Caching response instead of creating and caching a module script at this point is done to ensure that no side-effects occur until there is a type match.
From 9f2ae27b45760d696faf2c73c324ea7774df783b Mon Sep 17 00:00:00 2001 From: Daniel ClarkIf moduleMap[url] is a fetch response, then asynchronously complete this algorithm with the - result of creating a module script - with matching type given url, requested type, + data-x="concept-response">response, then create a module script with matching + type given url, requested type, moduleMap[url], options, and module map settings - object, and abort these steps.
If moduleMap[url] is null, asynchronously complete this algorithm with null, and abort these steps.
Asychronously complete this algorithm with the result of creating a module script with matching - type given url, requested type, response, - options, and module map settings object.
Create a module script with matching type given url, + requested type, response, options, and module map settings + object, and asychronously complete this algorithm with the result.
To create a module script with matching type, given a url, a
requested type, a fetch response
response, some options, and module map settings object,
From e86dd65581b26f9eb7a8c40f4f449247b6f66525 Mon Sep 17 00:00:00 2001
From: Daniel Clark
Let module type be undefined.
If moduleRequest was given and if moduleRequest.[[Attributes]]
- has a Record entry such that entry.[[Key]] is
- "type"
, then let module type be entry.[[Value]]
-
Otherwise let module type be undefined.
+If moduleRequest was given, then:
+ +If moduleRequest.[[Attributes]] has any Record entry
+ such that entry.[[Key]] is not "type"
, then asynchronously
+ complete this algorithm with null, and
+ abort these steps.
If moduleRequest.[[Attributes]] has a Record entry such
+ that entry.[[Key]] is "type"
, then set module
+ type to entry.[[Value]].
Assert: No more than one such Record exists.
+If module type is neither undefined nor If moduleMap[url] is a fetch response, then create a module script with matching
- type given url, requested type,
- moduleMap[url], options, and module map settings
- object, asynchronously complete this algorithm with the result, and abort these steps."json"
,
From 3318ed318a1a82f5011e0504f7526efc304375cc Mon Sep 17 00:00:00 2001
From: Daniel Clark
If moduleMap[url] is null, asynchronously complete this algorithm with null, and abort these steps.
Create a module script with matching type given url, - requested type, response, options, and module map settings + requested type, options, and module map settings object, and asychronously complete this algorithm with the result.
To create a module script with matching type, given a url, a - requested type, a fetch response - response, some options, and module map settings object, + requested type, some options, and module map settings object, run these steps. The algorithm will complete with either null (on failure) or a module script (on success).
Let module script be null.
Let moduleMap be module map settings object's module map.
Let response be moduleMap[url].
Assert: response is a fetch response.
+
Let MIME type be the result of extracting a MIME type from response's header list.
Set module script to the result of creating a JavaScript module - script given source, module map settings object, - response's url, and - options.
Set module script to the result of creating a JavaScript module + script given source, module map settings object, + response's url, and + options.
+ +It is intentional that the module map is keyed by the request URL, whereas the base URL for the JavaScript module script + is set to the response URL. The former is used to + deduplicate fetches, while the latter is used for URL resolution.
+If module script is not null, then:
- -Let moduleMap be module map settings object's module map.
Set moduleMap[url] to module script.
- -It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is - set to the response URL. The former is used to - deduplicate fetches, while the latter is used for URL resolution.
-If module script is not null, then set moduleMap[url] to + module script
Return module script.
Assert: These steps are running on the event loop, not + in parallel.
Let module script be null.
Let moduleMap be module map settings object's
Date: Wed, 8 Jul 2020 11:20:45 -0700
Subject: [PATCH 20/56] Reword caching comment
---
source | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/source b/source
index 2a8d738d675..ba04d1d893f 100644
--- a/source
+++ b/source
@@ -88903,11 +88903,12 @@ document.querySelector("button").addEventListener("click", bound);
If the MIME type is valid but does not match the requested module type, then
create a module script with matching type will fail and response will
- remain cached in the module map. Then, future attempts to fetch the same url in
- another module graph could succeed if the requested type matched the MIME type, without
- triggering another network request. Caching response instead of creating and
- caching a module script at this point is done to ensure that no side-effects occur until there
- is a type match. Caching response instead of creating and caching a module script at this point is
+ done to ensure that no side-effects occur until there is a type match. If requested type does turn out to match the MIME type then create a module
script with matching type will create a module script and overwrite this module
From 3247e99275b9fbeb97c957a7f9b779c72fba6bf6 Mon Sep 17 00:00:00 2001
From: Daniel Clark User agents that support JavaScript must also implement the import attributes
- proposal. The following terms are defined there, and used in this specification: User agents that support JavaScript must also implement the import conditions
+ proposal. The following terms are defined there, and used in this specification: Users agents that support JavaScript must also implement ECMAScript
@@ -88795,13 +88795,12 @@ document.querySelector("button").addEventListener("click", bound);
If moduleRequest was given, then: If moduleRequest.[[Attributes]] has any Record entry
+ If moduleRequest.[[Conditions]] has any Record entry
such that entry.[[Key]] is not If moduleRequest.[[Attributes]] has a Record entry such
+ If moduleRequest.[[Conditions]] has a Record entry such
that entry.[[Key]] is User agents that support JavaScript must also implement the import conditions
+ User agents that support JavaScript must also implement the import assertions
proposal. The following terms are defined there, and used in this specification: Users agents that support JavaScript must also implement ECMAScript
@@ -88795,12 +88795,12 @@ document.querySelector("button").addEventListener("click", bound);
If moduleRequest was given, then: If moduleRequest.[[Conditions]] has any Record entry
+ If moduleRequest.[[Assertions]] has any Record entry
such that entry.[[Key]] is not If moduleRequest.[[Conditions]] has a Record entry such
+ If moduleRequest.[[Assertions]] has a Record entry such
that entry.[[Key]] is Let moduleMap be module map settings object's module map. If moduleMap[url] is " If moduleMap[url / module type] is
+ " If moduleMap[url] is a fetch response, then create a module script with matching
- type given url, requested type, options, and
- module map settings object, asynchronously complete this algorithm with the result,
- and abort these steps. If moduleMap[url] is null, asynchronously complete this algorithm
- with null, and abort these steps. If moduleMap[url / module type] is null, asynchronously
+ complete this algorithm with null, and abort these steps. Set moduleMap[url] to " Set moduleMap[url /
+ module type] to " Let request be a new request whose
url is url,
If any of the following conditions are met, set
+ If either of the following conditions are met, set
moduleMap[url] to null, asynchronously complete this algorithm with null,
and abort these steps: response's status is not an
ok status The result of extracting a
- MIME type from response's header
- list is neither a JavaScript MIME type nor a JSON MIME type.
- For historical reasons, fetching a
- classic script does not include MIME type checking. In contrast, module scripts' interpretation is driven by their MIME type, and they will
- fail to load if they are not of a supported MIME type. If the resource does not have a MIME
- type which HTML knows how to handle as a module then this algorithm will complete with null,
- which is interpreted as failure, and a null entry is added to moduleMap so that
- future attempts to fetch a module at url will always fail. Set moduleMap[url] to
- response. Let MIME type be the result of extracting a
+ MIME type from response's header
+ list. If the MIME type is valid but does not match the requested module type, then
- create a module script with matching type will fail and response will
- remain cached in the module map. Future attempts to fetch the same url in another
- module graph could succeed, without triggering another network request, if the requested type
- matched the MIME type. Caching response instead of creating and caching a module script at this point is
- done to ensure that no side-effects occur until there is a type match. If requested type does turn out to match the MIME type then create a module
- script with matching type will create a module script and overwrite this module
- map entry with it. For historical reasons, fetching a
+ classic script does not include MIME type checking. In contrast, module scripts' interpretation is driven by their MIME type, and they will
+ fail to load if they are not of a supported MIME type. If the resource does not have a MIME
+ type which HTML knows how to handle as a module then this algorithm will complete with null,
+ which is interpreted as failure, and a null entry is added to moduleMap so that
+ future attempts to fetch a module at url will always fail. Create a module script with matching type given url,
- requested type, options, and module map settings
- object, and asychronously complete this algorithm with the result. To create a module script with matching type, given a url, a
- requested type, some options, and module map settings object,
- run these steps. The algorithm will complete with either null (on failure) or a
- module script (on success). Assert: These steps are running on the event loop, not
- in parallel. Let source text be the result of UTF-8
+ decoding response's body. Let module script be null. Let moduleMap be module map settings object's module map. Let response be moduleMap[url]. Assert: response is a fetch response.
+ If MIME type is a JavaScript MIME type and module type
+ is undefined, then set module script to the result of creating a JavaScript
+ module script given source text, module map settings object,
+ response's url, and options. Let MIME type be the result of extracting a
- MIME type from response's header
- list. If MIME type is a JavaScript MIME type and module type is
- undefined, then: Let source text be the result of UTF-8
- decoding response's body. Set module script to the result of creating a JavaScript module
- script given source, module map settings object,
- response's url, and
- options. It is intentional that the module map is keyed by the request URL, whereas the base URL for the JavaScript module script
- is set to the response URL. The former is used to
- deduplicate fetches, while the latter is used for URL resolution. If MIME type is a JSON MIME type and module type is
+ If MIME type is a JSON MIME type and module type is
- Let source text be the result of UTF-8
- decoding response's body. Set moduleMap[url /
+ module type] to module script, and asynchronously complete this algorithm
+ with module script. Set module script to the result of creating a JSON module
- script given source text and module map settings object. It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is
+ set to the response URL. The former is used to
+ deduplicate fetches, while the latter is used for URL resolution. If module script is not null, then set moduleMap[url] to
- module script Return module script. To find the first parse error given a root
@@ -89011,22 +88943,25 @@ document.querySelector("button").addEventListener("click", bound);
Let moduleRequests be the value of moduleScript's record's [[RequestedModules]] internal slot. Let childURLs be the list obtained by calling
- resolve a module specifier once for each item moduleRequest of
- moduleRequest, given moduleScript's base URL and moduleRequest.[[Specifier]].
- (None of these will ever fail, as otherwise moduleScript would have been marked as
- itself having a parse error.) Let childModules be the list obtained by getting each value in moduleMap whose key is given by an
- item of childURLs. For each childModule of
- childModules: For each moduleRequest of
+ moduleRequests: Let childURL be the result of resolving a module specifier given
+ moduleScript's base URL and
+ moduleRequest.[[Specifier]]. (This will never fail, as otherwise
+ moduleScript would have been marked as itself having a parse error.) If moduleRequest.[[Assertions]] has a Record entry
+ such that entry.[[Key]] is Let childModule be moduleMap[childURL /
+ module type]. Assert: childModule is a module script (i.e., it is not " A module map is a map of URL records to values that are either a module script,
- null (used to represent failed fetches), a placeholder value " A module map is a map keyed by
+ URL record / module type string pairs whose values are
+ either a module script, null (used to represent failed fetches), or a placeholder
+ value " Since module maps are keyed by URL, the following code will
- create three separate entries in the module map, since it results in three different
- URLs: Since module maps are keyed by URL / module type, the
+ following code will create three separate entries in the module map, since it
+ results in three different URL/module type pairs (all with null type):
+ Note that this behavior is the same as how shared workers are keyed by their parsed constructor url. Since module type is also part of the module map key, the following code will
+ create two separate entries in the module map (the type is undefined for the first,
+ and Therefore two separate fetches and two separate module evaluations will be performed. Let resolved module script be moduleMap[url]. (This entry
- must exist for us to have gotten to this point.) If moduleRequest.[[Assertions]] has a Record entry such
+ that entry.[[Key]] is Let resolved module script be moduleMap[url /
+ module type]. (This entry must exist for us to have
+ gotten to this point.) Assert: resolved module script is a module script (i.e., is not
null or " If moduleRequest.[[Assertions]] has any Record entry
such that entry.[[Key]] is not If moduleRequest.[[Assertions]] has a Record entry such
From 9164acf16e14c0e715f7b7269959217e76a31c91 Mon Sep 17 00:00:00 2001
From: Daniel Clark User agents that support JavaScript must also implement the import assertions
- proposal. The following terms are defined there, and used in this specification: Setting the attribute to an ASCII case-insensitive match for the string
- " Setting the attribute to any other value means that the script is a data
block, which is not processed. None of the Classic scripts and JavaScript module scripts can be embedded inline, or be imported from an external
- file using the The contents of inline The contents of the external script resource for JSON module
- scripts must conform to the requirements of the JSON specification . When used to include data blocks, the data must be embedded
inline, the format of the data must be given using the The following sample shows how a Additionally, if code from another This example shows how to include a JavaScript module script for modern user
- agents, and a classic script for older user agents: This example shows how to include a module script for modern user agents, and a
+ classic script for older user agents: In modern user agents that support JavaScript module
- scripts, the In modern user agents that support module scripts, the
+ The following sample shows how a Some notable features gained by using a JavaScript module script include the ability to import
- functions from other JavaScript modules, strict mode by default, and how top-level declarations
- do not introduce new properties onto the global object. Also note that no matter
- where this The following sample shows how a JSON module script can be imported from inside
- a JavaScript module script: Some notable features gained by using a module script include the ability to import functions
+ from other JavaScript modules, strict mode by default, and how top-level declarations do not
+ introduce new properties onto the global object. Also note that no matter where
+ this MIME type checking for module scripts is strict. In order for the fetch of the
- JSON module script to succeed, the HTTP reponse must have a
- JSON MIME type, for example A script is one of three possible A script is one of two possible structs. All scripts have: One of the following: a script record, for classic
- scripts; a Source Text Module Record, for JavaScript module scripts; a Synthetic Module Record, for JSON
- module scripts; or null, representing a parsing failure. Either a Script Record, for classic
+ scripts; a Source Text Module Record, for module scripts; or null. In the former two cases, it represents a parsed script;
+ null represents a failure parsing. Module scripts can be classified into two types: A module script is a JavaScript module script if
- its record is a Source Text Module
- Record. A module script is a JSON module script if its record is a Synthetic Module Record, and it
- was created via the create a JSON module
- script algorithm. JSON module scripts represent a parsed JSON document. As JSON documents do not import dependent modules, and do not throw exceptions
- on evaluation, the fetch options and
- base URL of a JSON module script are
- always null. The active script is determined by the following algorithm: Let script be the result of creating a JavaScript module script
- using source text, settings object, base URL, and
+ Let script be the result of creating a module script using
+ source text, settings object, base URL, and
options. If script is null, asynchronously complete this algorithm with null, and
@@ -89544,8 +89469,8 @@ document.querySelector("button").addEventListener("click", bound);
Let options be the descendant script fetch options for module
script's fetch options. Assert: options is not null, as module script is a JavaScript
- module script. Assert: options is not null, as module script is a module
+ script. For each moduleRequest in
@@ -89619,42 +89544,30 @@ document.querySelector("button").addEventListener("click", bound);
complete with either null (on failure) or a module script (on success). Let module type be undefined. If moduleRequest was given, then: If moduleRequest.[[Assertions]] has any Record entry
- such that entry.[[Key]] is not If moduleRequest.[[Assertions]] has a Record entry such
- that entry.[[Key]] is If moduleRequest was given and moduleRequest.[[Assertions]] contains
+ any Records, then asynchronously complete this algorithm with null,
+ and return. Assert: No more than one such Record exists. Currently no import assertions are supported, so we conservatively fail
+ if any are present. Eventually these will be used for checks such as confirming that the
+ type of the module matches the type expected by the importer. If module type is neither undefined nor Let moduleMap be module map settings object's module map. If moduleMap[url / module type] is
+ If moduleMap[url / undefined] is
" If moduleMap[url / module type] is null, asynchronously
- complete this algorithm with null, and return. If moduleMap[url / undefined] exists,
+ asynchronously complete this algorithm with moduleMap[url / undefined], and
+ return. Set moduleMap[url /
- module type] to " Set moduleMap[url / undefined] to
+ " Let request be a new request whose
url is url,
If either of the following conditions are met: If any of the following conditions are met: response's type is " response's status is not an
- ok status, then set moduleMap[url / module
- type] to null, asynchronously complete this algorithm with null, and return. the result of extracting a MIME type from
+ response's header list is not a
+ JavaScript MIME type, then set moduleMap[url / undefined] to
+ null, asynchronously complete this algorithm with null, and return. Let source text be the result of UTF-8
decoding response's body. Let module script be null. If MIME type is a JavaScript MIME type and module type
- is undefined, then set module script to the result of creating a JavaScript
- module script given source text, module map settings object,
- response's url, and options. If MIME type is a JSON MIME type and module type is
- Let module script be the result of creating a module script given
+ source text, module map settings object, response's url, and options. Set moduleMap[url /
- module type] to module script, and asynchronously complete this algorithm
- with module script. Set moduleMap[url / undefined] to
+ module script, and asynchronously complete this algorithm with module
+ script. It is intentional that the module map is keyed by the request URL, whereas the moduleScript's parse
error. Let moduleRequests be the value of moduleScript's record's [[RequestedModules]] internal slot. If moduleScript's record is a
- Cyclic Module Record: For each moduleRequest of
+ moduleRequests: Let moduleRequests be the value of moduleScript's record's [[RequestedModules]] internal slot. For each moduleRequest of
- moduleRequests: Let childURL be the result of resolving a module specifier given
- moduleScript's base URL and
- moduleRequest.[[Specifier]]. (This will never fail, as otherwise
- moduleScript would have been marked as itself having a parse error.) If moduleRequest.[[Assertions]] has a Record entry
- such that entry.[[Key]] is Let childURL be the result of resolving a module specifier given
+ moduleScript's base URL and
+ moduleRequest.[[Specifier]]. (This will never fail, as otherwise
+ moduleScript would have been marked as itself having a parse error.) Let childModule be moduleMap[childURL /
- module type]. Let childModule be moduleMap[childURL / undefined].
+ Assert: childModule is a module script (i.e., it is not " Assert: childModule is a module script (i.e., it is not " If discoveredSet already contains
- childModule, continue. If discoveredSet already contains
+ childModule, continue. Let childParseError be the result of finding the first parse
- error given childModule and discoveredSet. Let childParseError be the result of finding the first parse
+ error given childModule and discoveredSet. If childParseError is not null, return childParseError. If childParseError is not null, return childParseError. Return script. To create a JavaScript module script,
- given a string source, an environment settings
- object settings, a URL baseURL, and some script
- fetch options options: To create a module script, given a
+ string source, an environment settings object
+ settings, a URL baseURL, and some script fetch
+ options options: If scripting is disabled for
@@ -89939,34 +89835,6 @@ document.querySelector("button").addEventListener("click", bound);
Return script. To create a JSON module script, given a
- string source and an environment settings object settings: Let script be a new module script that this algorithm will
- subsequently initialize. Set script's settings object to settings. Set script's base URL and
- fetch options to null. Set script's parse error and
- error to rethrow to null. Let result be ParseJSONModule(source).
-
- If this throws an exception, set script's parse error to that exception, and return
- script. Set script's record to result.
-
- Return script. To run a classic script given a classic script
@@ -90684,7 +90552,9 @@ dictionary PromiseRejectionEventInit : EventInit {
either a module script, null (used to represent failed fetches), or a placeholder
value " Since module maps are keyed by URL / module type, the
@@ -90716,14 +90586,18 @@ import "https://example.com/foo/../module2.mjs";
data-x="SharedWorker">shared workers are keyed by their parsed constructor url. Since module type is also part of the module map key, the following code will
- create two separate entries in the module map (the type is undefined for the first,
- and Once additional module types are introduced, it will be possible to have multiple map entries
+ for a single URL since module type is also part of the module map key. For
+ example, once JSON modules are introduced the following code will create two separate entries in
+ the module map (the type is undefined for the first, and
+ Therefore two separate fetches and two separate module evaluations will be performed. Therefore two separate fetches and two separate module evaluations will be performed. Note
+ however that least one of the imports will fail the module type check unless the server
+ responds with a different MIME type for each. Let module script be moduleRecord.[[HostDefined]]. Assert: module script's base
- URL is not null, as module script is a JavaScript module
- script. Let urlString be module script's base URL, serialized. Set fetch options to the descendant script fetch options for
referencing script's fetch
options. Assert: Neither base URL nor fetch options is null, as
- referencing script is a classic script or a JavaScript module
- script. As explained above for HostResolveImportedModule, in the common
@@ -90929,9 +90795,6 @@ import "https://example.com/module.json" assert { type: "json" };
Set base URL to referencing script's base URL. Assert: base URL is not null, as referencing script is a
- classic script or a JavaScript module script. If moduleRequest.[[Assertions]] has a Record entry such
- that entry.[[Key]] is Let resolved module script be moduleMap[url /
- module type]. (This entry must exist for us to have
- gotten to this point.) Let resolved module script be moduleMap[url / undefined].
+ (This entry must exist for us to have gotten to this point.)
+ Assert: resolved module script is a module script (i.e., is not
null or " Let base URL be initiating script's base URL. Assert: base URL is not null, as initiating script is a
- classic script or a JavaScript module script. Let fetch options be a script fetch options whose cryptographic nonce is initiating
From 9eda0e2732a537375c37f0c2f2c1aea0765ee046 Mon Sep 17 00:00:00 2001
From: Daniel Clark If moduleMap[url / module type] is null, asynchronously
- complete this algorithm with null, and return. If moduleMap[url / module type] exists, asynchronously complete this algorithm with
+ moduleMap[url / module type], and return. Set moduleMap[url /
module type] to " User agents that support JavaScript must also implement the import assertions
- proposal. The following terms are defined there, and used in this specification: User agents that support JavaScript must also implement the JSON modules
+ proposal. The following term is defined there, and used in this specification: Therefore two separate fetches and two separate module evaluations will be performed. In theory, this means that two separate fetches and two separate module evaluations would be
+ performed. In practice, due to the memory cache the resource will only be fetched once.
+ Additionally, as long as all module types are mutually exclusive, the module type check in
+ fetch a single module script will fail for at least one of the imports, so at most
+ one module evaluation will occur. The purpose of including the type in the module map key is so that an import
+ with the wrong type assertion does not prevent a different import of the same specifier but with
+ the correct type from succeeding. Therefore two separate fetches and two separate module evaluations will be performed. Note
- however that least one of the imports will fail the module type check unless the server
- responds with a different MIME type for each. In theory, this means that two separate fetches and two separate module evaluations would be
+ performed. In practice, due to the memory cache the resource will only be fetched once.
+ Additionally, as long as all module types are mutually exclusive, the module type check in
+ fetch a single module script will fail for at least one of the imports, so at most
+ one module evaluation will occur. The purpose of including the type in the module map key is so that an import
+ with the wrong type assertion does not prevent a different import of the same specifier but with
+ the correct type from succeeding. Let module type be undefined. If moduleRequest was given, then: If moduleRequest was given and moduleRequest.[[Assertions]] has a
+ Record entry such that entry.[[Key]] is If moduleRequest.[[Assertions]] has any Record entry
- such that entry.[[Key]] is not Assert: No more than one such Record exists. If moduleRequest.[[Assertions]] has a Record entry such
- that entry.[[Key]] is Assert: No more than one such Record exists. Set module type to entry.[[Value]]. If moduleRequest was given and moduleRequest.[[Assertions]] contains
- any Records, then asynchronously complete this algorithm with null,
- and return. If moduleRequest was given and moduleRequest.[[Assertions]] has a
+ Record entry such that entry.[[Key]] is Currently no non-JS module types are supported, so we conservatively fail
+ if any type is specified. When support is added for other module types, the Currently no import assertions are supported, so we conservatively fail
- if any are present. Eventually these will be used for checks such as confirming that the
- type of the module matches the type expected by the importer. Assertions with unknown keys are ignored. Let moduleMap be module map settings object's
Date: Mon, 5 Oct 2020 14:14:18 -0700
Subject: [PATCH 32/56] Move check for unknown type assertion to 'create a
module script'.
---
source | 51 +++++++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/source b/source
index 67904f2c488..fb06c2111e3 100644
--- a/source
+++ b/source
@@ -89661,6 +89661,21 @@ document.querySelector("button").addEventListener("click", bound);
If url is failure, then asynchronously complete this algorithm with null, and
return. If moduleRequest.[[Assertions]] has a Record entry such
+ that entry.[[Key]] is Currently no non-JS module types are supported, so we conservatively fail if any type
+ assertion is provided. When support is added for other module types, the Assertions with unknown keys are ignored. Fetch a single module script given url, settings
object, " If moduleRequest was given and moduleRequest.[[Assertions]] has a
- Record entry such that entry.[[Key]] is Currently no non-JS module types are supported, so we conservatively fail
- if any type is specified. When support is added for other module types, the Assertions with unknown keys are ignored. Let moduleMap be module map settings object's module map. If url is failure, then: If url is failure, or if requested.[[Assertions]] has a
+ Record entry such that entry.[[Key]] is Let error be a new This step is essentially validating all of the requested module specifiers. We
- treat a module with unresolvable module specifiers the same as one that cannot be parsed; in
- both cases, a syntactic issue makes it impossible to ever contemplate linking the module
- later. This step is essentially validating all of the requested module specifiers and type
+ assertions. We treat a module with unresolvable module specifiers or an unsupported type
+ assertion the same as one that cannot be parsed; in both cases, a syntactic issue makes
+ it impossible to ever contemplate linking the module later. Currently no non-JS module types are supported, so we conservatively fail if any type
+ assertion is provided. When support is added for other module types, the Assertions with unknown keys are ignored. Set script's record to
From 24483424121b51dbf05f62b4ed9960ecf4904b35 Mon Sep 17 00:00:00 2001
From: Daniel Clark If url is failure, then asynchronously complete this algorithm with null, and
return. If moduleRequest.[[Assertions]] has a Record entry such
+ that entry.[[Key]] is Fetch a single module script given url, settings
object, " If module type is neither undefined nor Assert: module type is either undefined or Let moduleMap be module map settings object's module map. If requested.[[Assertions]] has a Record entry such
+ that entry.[[Key]] is If url is failure, then: If url is failure, or if module type is neither undefined nor
+ Let error be a new This step is essentially validating all of the requested module specifiers. We
- treat a module with unresolvable module specifiers the same as one that cannot be parsed; in
- both cases, a syntactic issue makes it impossible to ever contemplate linking the module
- later. This step is essentially validating all of the requested module specifiers and type
+ assertions. We treat a module with unresolvable module specifiers or unsupported type
+ assertions the same as one that cannot be parsed; in both cases, a syntactic issue makes
+ it impossible to ever contemplate linking the module later. Assertions with unknown keys are ignored. Set script's record to
From 3c94b3151c45c6fdbdcd0c21ce93b899ae68f7ba Mon Sep 17 00:00:00 2001
From: Daniel Clark Users agents that support JavaScript must also implement ECMAScript
Internationalization API. User agents that support JavaScript must also implement the import assertions
+ User agents that support JavaScript must also implement the Import Assertions
proposal. The following term is defined there, and used in this specification: Let url be the result of resolving
- a module specifier given referrer and
- moduleRequst.[[Specifier]]. Assert: url is never failure, because resolving a module specifier must have been previously successful with these same two
- arguments. Assert: url is never failure, because resolving a module specifier must have been previously successful with these same two
+ arguments. Assert: visited set contains
url. Let moduleMap be module map settings object's module map. If moduleMap[url / undefined] is
+ If moduleMap[(url, If moduleMap[url / undefined] exists,
- asynchronously complete this algorithm with moduleMap[url / undefined], and
- return. If moduleMap[(url, Set moduleMap[url / undefined] to
- " Set moduleMap[(url, Let request be a new request whose
url is url, JavaScript MIME type, then set moduleMap[url / undefined] to
- null, asynchronously complete this algorithm with null, and return. then set moduleMap[(url, Let source text be the result of UTF-8
@@ -90305,9 +90305,9 @@ document.querySelector("button").addEventListener("click", bound);
data-x="concept-response-url">url, and options. Set moduleMap[url / undefined] to
- module script, and asynchronously complete this algorithm with module
- script. Set moduleMap[(url, It is intentional that the module map is keyed by the request URL, whereas the moduleScript would have been marked
as itself having a parse error.) Let childModule be moduleMap[childURL / undefined].
- Let childModule be moduleMap[(childURL, Assert: childModule is a module script (i.e., it is not " A module map is a map keyed by
- URL record / module type string pairs whose values are
- either a module script, null (used to represent failed fetches), or a placeholder
- value " A module map is a map keyed by tuples consisting of a URL record and a string.
+ The URL record is the request URL at which
+ the module was fetched, and the string indicates the type of the module (e.g. Since module maps are keyed by URL / module type, the
+ Since module maps are keyed by (URL, module type), the
following code will create three separate entries in the module map, since it
- results in three different URL/module type pairs (all with null type):
- Once additional module types are introduced, it will be possible to have multiple map entries
- for a single URL since module type is also part of the module map key. For
- example, once JSON modules are introduced the following code will create two separate entries in
- the module map (the type is undefined for the first, and
- Once additional module types are introduced, it will be possible to have multiple map entries
+ for a single URL since module type is also part of the module map key. For
+ example, once JSON modules are introduced the following code will create two separate entries in
+ the module map (the type is In theory, this means that two separate fetches and two separate module evaluations would be
- performed. In practice, due to the memory cache the resource will only be fetched once.
- Additionally, as long as all module types are mutually exclusive, the module type check in
- fetch a single module script will fail for at least one of the imports, so at most
- one module evaluation will occur. In theory, this means that two separate fetches and two separate module evaluations would be
+ performed. In practice, due to the memory cache the resource will only be fetched once.
+ Additionally, as long as all module types are mutually exclusive, the module type check in
+ fetch a single module script will fail for at least one of the imports, so at most
+ one module evaluation will occur. The purpose of including the type in the module map key is so that an import
- with the wrong type assertion does not prevent a different import of the same specifier but with
- the correct type from succeeding. The purpose of including the type in the module map key is so that an import
+ with the wrong type assertion does not prevent a different import of the same specifier but with
+ the correct type from succeeding. Let resolved module script be moduleMap[url / undefined].
- (This entry must exist for us to have gotten to this point.)
- Let resolved module script be moduleMap[(url, Assert: resolved module script is a module script (i.e., is not
null or " Let url be the result of resolving a
- module specifier given base URL and moduleRequest.[[Specifier]]. If url is failure, then asynchronously complete this algorithm with null, and
return. Let url be the result of resolving
- data-x="concept-script-base-url">base URL and requested.[[Specifier]]. Assert: url is never failure, because resolving a module specifier must have been the result of extracting a MIME type from
response's header list is not a
JavaScript MIME type, then set moduleMap[(url, Since module maps are keyed by (URL, module type), the
following code will create three separate entries in the module map, since it
- results in three different (URL, module type) tuples (all with null
- type): In theory, this means that two separate fetches and two separate module evaluations would be
- performed. In practice, due to the memory cache the resource will only be fetched once.
- Additionally, as long as all module types are mutually exclusive, the module type check in
+ performed. In practice, due to the due to the as-yet-unspecified memory cache (see issue #6110) the resource will only be fetched
+ once. Additionally, as long as all module types are mutually exclusive, the module type check in
fetch a single module script will fail for at least one of the imports, so at most
one module evaluation will occur. Let url be the result of resolving a
- module specifier given base URL and moduleRequest.[[Specifier]]. Assert: url is never failure, because resolving a module specifier must have been previously successful with these
@@ -91540,8 +91538,8 @@ import "https://example.com/module" assert { type: "json" };
corresponding module script, or in fetch an import() module script graph). Let resolved module script be moduleMap[(url, Assert: resolved module script is a module script (i.e., is not
null or " In theory, this means that two separate fetches and two separate module evaluations would be
- performed. In practice, due to the due to the as-yet-unspecified memory cache (see issue #6110) the resource will only be fetched
once. Additionally, as long as all module types are mutually exclusive, the module type check in
fetch a single module script will fail for at least one of the imports, so at most
From 4ad7d2d0a6a9678ec6f48fd2103427ded4f7ca13 Mon Sep 17 00:00:00 2001
From: Daniel Clark If moduleRequest.[[Assertions]] has a Record entry such
- that entry.[[Key]] is Currently no non-JS module types are supported, so we conservatively fail if any type
- assertion is provided. When support is added for other module types, the Assertions with unknown keys are ignored. Let moduleMap be module map settings object's module map. If moduleMap[(url, If moduleMap[(url, " If moduleMap[(url, If moduleMap[(url, " Set moduleMap[(url, Set moduleMap[(url, " Let request be a new request whose
url is url, JavaScript MIME type, then set moduleMap[(url, then set moduleMap[(url, " Set moduleMap[(url, Set moduleMap[(url, " It is intentional that the module map is keyed by the moduleScript would have been marked
as itself having a parse error.) Let childModule be moduleMap[(childURL, Let childModule be moduleMap[(childURL, " Assert: childModule is a module script (i.e., it is not " If url is failure, or if requested.[[Assertions]] has a
- Record entry such that entry.[[Key]] is Let error be a new Currently no non-JS module types are supported, so we conservatively fail if any type
- assertion is provided. When support is added for other module types, the Assertions with unknown keys are ignored. A module map is a map keyed by tuples consisting of a URL record and a string.
The URL record is the request URL at which
- the module was fetched, and the string indicates the type of the module (e.g. Since module maps are keyed by (URL, module type), the
following code will create three separate entries in the module map, since it
- results in three different (URL, module type) tuples (all with Once additional module types are introduced, it will be possible to have multiple map entries
for a single URL since module type is also part of the module map key. For
example, once JSON modules are introduced the following code will create two separate entries in
- the module map (the type is Let resolved module script be moduleMap[(url, Let resolved module script be moduleMap[(url, " Assert: resolved module script is a module script (i.e., is not
From 614a9f4b94dac773329b6ae9a153d35eeb7611e6 Mon Sep 17 00:00:00 2001
From: Daniel Clark User agents that support JavaScript must also implement the Import Assertions
- proposal. The following term is defined there, and used in this specification: If url is failure, then asynchronously complete this algorithm with null, and
return. Assert: moduleRequest.[[Assertions]] does not contain any Record
+ entry such that entry.[[Key]] is not " If moduleRequest.[[Assertions]] has a Record entry such
that entry.[[Key]] is " Currently no non-JS module types are supported, so we conservatively fail if any type
- assertion is provided. When support is added for other module types, the " Assertions with unknown keys are ignored. Currently no non-JS module types are supported, so we conservatively fail if any
+ type assertion is provided. When support is added for other module types, the " Fetch a single module script given url, settings
@@ -90476,6 +90478,11 @@ document.querySelector("button").addEventListener("click", bound);
Assert: requested.[[Assertions]] does not contain any Record
+ entry such that entry.[[Key]] is not " For each ModuleRequest record
requested of result.[[RequestedModules]]: Assertions with unknown keys are ignored. The Import Assertions proposal contains an implementation-defined
+ HostGetSupportedAssertions abstract operation.
+ User agents must use the following implementation: Return a new List whose sole item is the string
+ " The Import Assertions proposal contains an implementation-defined
- HostGetSupportedAssertions abstract operation.
- User agents must use the following implementation: The Import Assertions proposal contains an implementation-defined
+ HostGetSupportedAssertions abstract operation.
+ User agents must use the following implementation: Return a new List whose sole item is the string
- " Return « " Assert: visited set contains
- url. Fetch a single module script given url, fetch client settings
object, destination, options, module map settings object,
From cf01c6de1cd7fd0271efdac6f3643ba09ea188e8 Mon Sep 17 00:00:00 2001
From: Daniel Clark Since module type is also part of the module map key, the following code will
- create two separate entries in the module map (the type is undefined for the first,
- and In theory, this means that two separate fetches and two separate module evaluations would be
- performed. In practice, due to the memory cache the resource will only be fetched once.
- Additionally, as long as all module types are mutually exclusive, the module type check in
- fetch a single module script will fail for at least one of the imports, so at most
- one module evaluation will occur. The purpose of including the type in the module map key is so that an import
- with the wrong type assertion does not prevent a different import of the same specifier but with
- the correct type from succeeding. Since module type is also part of the module map key, the following code will
+ create two separate entries in the module map (the type is undefined for the first,
+ and In theory, this means that two separate fetches and two separate module evaluations would be
+ performed. In practice, due to the memory cache the resource will only be fetched once.
+ Additionally, as long as all module types are mutually exclusive, the module type check in
+ fetch a single module script will fail for at least one of the imports, so at most
+ one module evaluation will occur. The purpose of including the type in the module map key is so that an import
+ with the wrong type assertion does not prevent a different import of the same specifier but with
+ the correct type from succeeding. If result is null, asynchronously complete this algorithm with null, and
return. Let visited set be « url ». Let visited set be « (url, " Fetch the
descendants of and link result given settings object,
@@ -88398,7 +88399,8 @@ document.querySelector("button").addEventListener("click", bound);
If result is null, asynchronously complete this algorithm with null, and
return. Let visited set be « url ». Let visited set be « (url, " Fetch the
descendants of and link result given settings object,
@@ -88425,7 +88427,8 @@ document.querySelector("button").addEventListener("click", bound);
If result is not null, optionally perform the following steps: Let visited set be « url ». Let visited set be « (url, " Fetch the
descendants of and link result given settings object,
@@ -88653,7 +88656,8 @@ document.querySelector("button").addEventListener("click", bound);
If result is null, asynchronously complete this algorithm with null, and
return. Let visited set be « url ». Let visited set be « (url, " Fetch the
descendants of and link result given fetch client settings
@@ -88745,14 +88749,14 @@ document.querySelector("button").addEventListener("click", bound);
If visited set does not contain
- url, then: Append requested to
moduleRequests. Append url to visited
- set. Append (url, " Assert: visited set contains
- url. Fetch a single module script given url, fetch client settings
object, destination, options, module map settings object,
From 5bc28f6725f5af81b66ca584b5303f1c92e75b06 Mon Sep 17 00:00:00 2001
From: Daniel Clark User agents that support JavaScript must also implement the JSON modules
@@ -88384,6 +88385,11 @@ document.querySelector("button").addEventListener("click", bound);
If url is failure, then asynchronously complete this algorithm with null, and
return. Assert: moduleRequest.[[Assertions]] does not contain any Record
+ entry such that entry.[[Key]] is not " If moduleRequest.[[Assertions]] has a Record entry such
that entry.[[Key]] is Assert: requested.[[Assertions]] does not contain any Record
+ entry such that entry.[[Key]] is not " For each ModuleRequest record
requested of result.[[RequestedModules]]: Assertions with unknown keys are ignored. The Import Assertions proposal contains an implementation-defined
+ HostGetSupportedAssertions abstract operation.
+ User agents must use the following implementation: Return a new List whose sole item is the string
+ " The Import Assertions proposal contains an implementation-defined
- HostGetSupportedAssertions abstract operation.
- User agents must use the following implementation: The Import Assertions proposal contains an implementation-defined
+ HostGetSupportedAssertions abstract operation.
+ User agents must use the following implementation: Return a new List whose sole item is the string
- " Return « " Setting the attribute to an ASCII case-insensitive match for the string
- " Setting the attribute to any other value means that the script is a data
block, which is not processed. None of the The following sample shows how a Additionally, if code from another This example shows how to include a module script for modern user agents, and a
- classic script for older user agents: This example shows how to include a JavaScript module script for modern user
+ agents, and a classic script for older user agents: In modern user agents that support module scripts, the
- In modern user agents that support JavaScript module
+ scripts, the The following sample shows how a Some notable features gained by using a module script include the ability to import functions
- from other JavaScript modules, strict mode by default, and how top-level declarations do not
- introduce new properties onto the global object. Also note that no matter where
- this Some notable features gained by using a JavaScript module script include the ability to import
+ functions from other JavaScript modules, strict mode by default, and how top-level declarations
+ do not introduce new properties onto the global object. Also note that no matter
+ where this The following sample shows how a JSON module script can be imported from inside
+ a JavaScript module script: MIME type checking for module scripts is strict. In order for the fetch of the
+ JSON module script to succeed, the HTTP reponse must have a
+ JSON MIME type, for example Either a Script Record, for classic
- scripts; a Source Text Module Record, for module scripts; or null. In the former two cases, it represents a parsed script;
- null represents a failure parsing. One of the following: a script record, for classic
+ scripts; a Source Text Module Record, for JavaScript module scripts; a Synthetic Module Record, for JSON
+ module scripts; or null, representing a parsing failure. If moduleRequest.[[Assertions]] has a Record entry such
that entry.[[Key]] is Fetch a single module script given url, settings
@@ -88728,8 +88768,8 @@ document.querySelector("button").addEventListener("click", bound);
Let options be the descendant script fetch options for module
script's fetch options. Assert: options is not null, as module script is a module
- script. Assert: options is not null, as module script is a JavaScript
+ module script. For each moduleRequest in
@@ -88817,8 +88857,8 @@ document.querySelector("button").addEventListener("click", bound);
Assert: module type is either " Assert: module type is either " If MIME type is a JSON MIME type and module type is
- If url is failure, or if module type is neither " Let error be a new Since module type is also part of the module map key, the following code will
create two separate entries in the module map (the type is " Let module script be moduleRecord.[[HostDefined]]. Assert: module script's base
+ URL is not null, as module script is a JavaScript module
+ script. Let urlString be module script's base URL, serialized. Set fetch options to the descendant script fetch options for
referencing script's fetch
options. Assert: Neither base URL nor fetch options is null, as
+ referencing script is a classic script or a JavaScript module
+ script. As explained above for HostResolveImportedModule, in the common
@@ -90119,6 +90167,9 @@ import "https://example.com/foo/../module2.mjs";
Set base URL to referencing script's base URL. Assert: base URL is not null, as referencing script is a
+ classic script or a JavaScript module script. Let resolved module script be moduleMap[(url, " If moduleRequest.[[Assertions]] has a Record entry such
+ that entry.[[Key]] is Let resolved module script be moduleMap[(url, module
+ type)]. (This entry must exist for us to have gotten to
+ this point.) Assert: resolved module script is a module script (i.e., is not
null or " Let base URL be initiating script's base URL. Assert: base URL is not null, as initiating script is a
+ classic script or a JavaScript module script. Let fetch options be a script fetch options whose cryptographic nonce is initiating
From 87eec91434d85e49d7269c65123f1ab671016797 Mon Sep 17 00:00:00 2001
From: Daniel Clark If moduleRequest.[[Assertions]] has a Record entry such
- that entry.[[Key]] is If moduleRequest.[[Assertions]] has a Record entry
+ such that entry.[[Key]] is If module type is neither " Fetch a single module script given url, settings
object, " If result is null, asynchronously complete this algorithm with null, and
return. Let visited set be « (url, " Let visited set be « (url, module type) ». Fetch the
descendants of and link result given settings object,
@@ -88750,16 +88752,21 @@ document.querySelector("button").addEventListener("click", bound);
href="#validate-requested-module-specifiers">previously successful with these same two
arguments. If moduleRequest.[[Assertions]] has a Record entry
+ such that entry.[[Key]] is If visited set does not contain
- (url, " Append requested to
moduleRequests. Append (url, " Append (url, module type) to
+ visited set. If moduleRequest.[[Assertions]] has a Record entry
+ such that entry.[[Key]] is Assert: visited set contains
- (url, " Fetch a single module script given url, fetch client settings
object, destination, options, module map settings object,
@@ -88992,7 +89004,7 @@ document.querySelector("button").addEventListener("click", bound);
If moduleRequest.[[Assertions]] has a Record entry
such that entry.[[Key]] is Let childModule be moduleMap[(childURL, module
type)]. In theory, this means that two separate fetches and two separate module evaluations would be
- performed. In practice, due to the as-yet-unspecified memory cache (see issue #6110) the resource will only be fetched
- once. Additionally, as long as all module types are mutually exclusive, the module type check in
- fetch a single module script will fail for at least one of the imports, so at most
- one module evaluation will occur. This can result in two separate fetches and two separate module evaluations being performed.
+ This is a willful violation of a constraint recommended (but not required) by the import
+ assertions specification stating that each call to HostResolveImportedModule with
+ the same referencingScriptOrModule, moduleRequest.[[Specifier]] pair must return the
+ same Module Record. In practice, due to the as-yet-unspecified memory cache (see issue #6110) the resource may only be fetched
+ once in WebKit and Blink-based browsers. Additionally, as long as all module types are mutually
+ exclusive, the module type check in fetch a single module script will fail for at
+ least one of the imports, so at most one module evaluation will occur. The purpose of including the type in the module map key is so that an import
with the wrong type assertion does not prevent a different import of the same specifier but with
From 9ec7c7ea0f28ee15ceffb6820122939a026214dd Mon Sep 17 00:00:00 2001
From: Daniel Clark In practice, due to the as-yet-unspecified memory cache (see issue In practice, due to the as-yet-unspecified memory cache (see issue #6110) the resource may only be fetched
once in WebKit and Blink-based browsers. Additionally, as long as all module types are mutually
exclusive, the module type check in fetch a single module script will fail for at
From aa104e0dbac4c08378efa600613d90b89b5c860c Mon Sep 17 00:00:00 2001
From: Daniel Clark MIME type checking for module scripts is strict. In order for the fetch of the JSON
module script to succeed, the HTTP reponse must have a JSON MIME type, for
From 64c523d887ad5f6af209d29d9f238124c0d71e3f Mon Sep 17 00:00:00 2001
From: Daniel Clark Note that this behavior is the same as how shared workers are keyed by their parsed constructor url. Since module type is also part of the module map key, the following code will
- create two separate entries in the module map (the type is " This can result in two separate fetches and two separate module evaluations being performed.
- This is a willful violation of a constraint recommended (but not required) by the import
- assertions specification stating that each call to HostResolveImportedModule with
- the same referencingScriptOrModule, moduleRequest.[[Specifier]] pair must return the
- same Module Record. In practice, due to the as-yet-unspecified memory cache (see issue #6110) the resource may only be fetched
- once in WebKit and Blink-based browsers. Additionally, as long as all module types are mutually
- exclusive, the module type check in fetch a single module script will fail for at
- least one of the imports, so at most one module evaluation will occur. The purpose of including the type in the module map key is so that an import
- with the wrong type assertion does not prevent a different import of the same specifier but with
- the correct type from succeeding. As CSS stylesheets do not import dependent modules, and do not throw exceptions
on evaluation, the fetch options and
base URL of a CSS module script are
@@ -90485,6 +90491,12 @@ document.querySelector("button").addEventListener("click", bound);
was created via the create a JSON module
script algorithm. JSON module scripts represent a parsed JSON document. As JSON documents do not import dependent modules, and do not throw exceptions
on evaluation, the fetch options and
base URL of a JSON module script are
From 9de359aa44a9aad9da62c0a7814de2753cd253ba Mon Sep 17 00:00:00 2001
From: Daniel Clark a Source Text Module Record, for JavaScript module scripts; a Synthetic Module Record, for CSS
- module scripts; or a Synthetic Module Record, for JSON
- module scripts; or a Synthetic Module Record, for CSS module
+ scripts and JSON module scripts null, representing a parsing failure. As CSS stylesheets do not import dependent modules, and do not throw exceptions
- on evaluation, the fetch options and
- base URL of a CSS module script are
- always null. As JSON documents do not import dependent modules, and do not throw exceptions
- on evaluation, the fetch options and
- base URL of a JSON module script are
- always null. As CSS stylesheets and JSON documents do not import dependent modules, and do not
+ throw exceptions on evaluation, the fetch
+ options and base URL of CSS module scripts and JSON module
+ scripts and are always null. The active script is determined by the following algorithm: Let result be ParseJSONModule(source).
+ Let result be ParseJSONModule(source). If this throws an exception, set script's parse error to that exception, and return
@@ -91780,7 +91780,7 @@ document.querySelector("button").addEventListener("click", bound);
Set script's record to
- result.
+ result. Return script. Set script's record to the result
- of creating a synthetic
- module record with a default export of sheet with settings. Return script. To create a synthetic module record with a default export of a JavaScript value
- value with an environment settings object settings: Return CreateSyntheticModule(« " To create a JSON module script, given a
string source and an environment settings object settings: If module type is neither " If module type is not " Fetch a single module script given url, settings
@@ -91373,11 +91373,12 @@ document.querySelector("button").addEventListener("click", bound);
Assert: module type is either " Assert: module type is " Let moduleMap be module map settings object's module map. If url is failure, or if module type is neither " If url is failure, or if module type is not " Let error be a new
-
-
"type"
, then asynchronously
- complete this algorithm with null, and
- abort these steps."type"
, then set module
type to entry.[[Value]].
-
-
-
- "type"
, then asynchronously
complete this algorithm with null, and abort these steps."type"
, then set module
type to entry.[[Value]].fetching
", wait
- in parallel until that entry's value changes, then queue a task on
- the networking task source to proceed with running the following steps.fetching
", wait in parallel until that entry's value
+ changes, then queue a task on the networking task source to proceed
+ with running the following steps.fetching
".fetching
".
-
-
- "json"
, then set module script to the result of creating
+ a JSON module script given source text and module map settings
+ object."json"
, then:
-
+
+
"type"
, then let module
+ type be entry.[[Value]]. Otherwise let module type be undefined.
+ fetching
" or null); by now all module
scripts in the graph rooted at moduleScript will have successfully been
@@ -89921,18 +89856,18 @@ dictionary PromiseRejectionEventInit : EventInit {
- fetching
", or a fetch response.
- Module maps are used to ensure that imported JavaScript modules
- are only fetched, parsed, and evaluated once per Document
or worker.fetching
". Module maps are
+ used to ensure that imported JavaScript modules are only fetched, parsed, and evaluated once per
+ Document
or worker.import "https://example.com/module.mjs";
import "https://example.com/module.mjs#map-buster";
@@ -89957,6 +89892,15 @@ import "https://example.com/foo/../module2.mjs";
"json"
for the second):
+
+
+
+ import "https://example.com/module.json";
+import "https://example.com/module.json" assert { type: "json" };
"type"
, then let module type
+ be entry.[[Value]]. Otherwise let module type be undefined.fetching
").
- "type"
, then asynchronously
- complete this algorithm with null, and abort these steps.[LegacyFactoryFunction]
[LegacyLenientThis]
@@ -57386,14 +57384,11 @@ interface HTMLScriptElement : HTMLElement {
redundantly setting it.module
" means that the script is a module script. If it has
- a JavaScript MIME type, or if the script is embedded inline, then it will be
- interpreted as a JavaScript module script according to the JavaScript Module top-level production; if it has a JSON MIME
- type, then it will be interpreted as a JSON module script. Module scripts
- are not affected by the defer
attribute, but are
- affected by the async
attribute (regardless of the state
- of the src
attribute).module
" means that the script is a module script, to be
+ interpreted according to the JavaScript Module top-level
+ production. Module scripts are not affected by the defer
+ attribute, but are affected by the async
attribute
+ (regardless of the state of the src
attribute).
script
attributes (except HTMLScriptElement : HTMLElement {
scripts. By using a valid MIME type string now, you ensure that your data block will not
ever be reinterpreted as a different script type, even in future user agents.
Classic scripts and module
+ scripts can be embedded inline, or be imported from an external file using the
src
attribute, which if specified gives the URL
of the external script resource to use. If src
is specified,
- it must be a valid non-empty URL potentially surrounded by spaces.script
elements, or the external script resource, must
- conform with the requirements of the JavaScript specification's Script or Module productions, for classic scripts and JavaScript module scripts respectively. script
elements, or the external script resource, must conform with the
+ requirements of the JavaScript specification's Script or Module productions, for classic
+ scripts and module scripts respectively.
type
@@ -57661,7 +57652,7 @@ o............A....e
script
element can be used to include an
- external JavaScript module script.
+ external module script.
@@ -57672,37 +57663,37 @@ o............A....e
<script type="module" src="app.mjs"></script>
script
element in the same Window
imports the module from app.mjs
(e.g. via import
- "./app.mjs";
), then the same JavaScript module script created by the
+ "./app.mjs";), then the same module script created by the
former script
element will be imported.
- <script type="module" src="app.mjs"></script>
<script nomodule defer src="classic-app-bundle.js"></script>
script
element with the nomodule
attribute will be ignored, and the
+ script
element with the nomodule
attribute
+ will be ignored, and the script
element with a type
of "module
" will be fetched and
+ evaluated (as a module script). Conversely, older user agents will ignore the
script
element with a type
of "module
" will be fetched and evaluated (as a JavaScript module
- script). Conversely, older user agents will ignore the script
element with a
- type
of "module
", as that is an
- unknown script type for them — but they will have no problem fetching and evaluating the other
- script
element (as a classic script), since they do not implement the
- nomodule
attribute.script
element (as a classic
+ script), since they do not implement the nomodule
attribute.
script
element can be used to write an inline
- JavaScript module script that performs a number of substitutions on the document's
- text, in order to make for a more interesting reading experience (e.g. on a news site): module script that performs a number of substitutions on the document's text, in
+ order to make for a more interesting reading experience (e.g. on a news site):
- <script type="module">
@@ -57734,38 +57725,13 @@ o............A....e
walkAllTextNodeDescendants(document.body, substitute);
</script>
script
element appears in the document, it will not be evaluated until
- both document parsing has complete and its dependency (dom-utils.mjs
) has
- been fetched and evaluated.script
element appears in the document, it will not be evaluated until both
+ document parsing has complete and its dependency (dom-utils.mjs
) has been
+ fetched and evaluated.
-
- <script type="module">
-import peopleInSpace from "http://api.open-notify.org/astros.json" if { type: "json" };
-
-const list = document.querySelector("#people-in-space");
-for (const { craft, name } of peopleInSpace.people) {
- const li = document.createElement("li");
- li.textContent = `${name} / ${craft}`;
- list.append(li);
-}
-</script>
Content-Type: text/json
. On the
- other hand, if the if { type: "json" }
part of the statement is omitted,
- it is assumed that the intent is to import a JavaScript module script, and the fetch
- will fail if the HTTP response has a MIME type that is not a JavaScript MIME type.
- Scripts
-
@@ -88738,22 +88704,10 @@ document.querySelector("button").addEventListener("click", bound);
-
-
-
-
@@ -89292,8 +89217,8 @@ document.querySelector("button").addEventListener("click", bound);
success).
-
-
-
-
+ "type"
, then asynchronously
- complete this algorithm with null, and return."type"
, then set module
- type to entry.[[Value]]."json"
,
- asynchronously complete this algorithm with null, and return.fetching
", wait in parallel until that entry's value
changes, then queue a task on the networking task source to proceed
with running the following steps.fetching
".fetching
".
+ ok status; orerror
"; or"json"
, then set module script to the result of creating
- a JSON module script given source text and module map settings
- object.
-
-
- "type"
, then let module
- type be entry.[[Value]]. Otherwise let module type be undefined.
- fetching
" or null); by now all module
- scripts in the graph rooted at moduleScript will have successfully been
- fetched.fetching
" or null); by now all module
+ scripts in the graph rooted at moduleScript will have successfully been
+ fetched.
-
-
-
Calling scripts
fetching
". Module maps are
used to ensure that imported JavaScript modules are only fetched, parsed, and evaluated once per
- Document
or worker.Document
or worker. Currently only JavaScript
+ module scripts are supported, so the module type will always
+ be null until additional module types are introduced.
"json"
for the second):
+ "json"
for the second):
- import "https://example.com/module.json";
import "https://example.com/module.json" assert { type: "json" };
"type"
, then let module type
- be entry.[[Value]]. Otherwise let module type be undefined.fetching
").fetching
".
+
+
+
@@ -122706,6 +122713,9 @@ INSERT INTERFACES HERE
"json"
for the second):
-
-
- import "https://example.com/module.json";
-import "https://example.com/module.json" assert { type: "json" };
+
+ import "https://example.com/module";
+import "https://example.com/module" assert { type: "json" };
"json"
for the second):
-
-
- import "https://example.com/module.json";
-import "https://example.com/module.json" assert { type: "json" };
+
+ import "https://example.com/module";
+import "https://example.com/module" assert { type: "json" };
"type"
, then:
-
"type"
, then asynchronously
- complete this algorithm with null, and return."type"
, then set module
- type to entry.[[Value]].
- "type"
, then asynchronously complete this algorithm with null, and return."type"
assertion will be used to check that the type of the fetched module
+ matches the type expected by the importer."type"
then asynchronously complete this
+ algorithm with null, and return."type"
assertion will be used to check that the type of the fetched module
+ matches the type expected by the importer.script
", options, settings object,
"client
", moduleRequest, and with the
@@ -90046,21 +90061,6 @@ document.querySelector("button").addEventListener("click", bound);
complete with either null (on failure) or a module script (on success).
-
"type"
, then asynchronously complete this algorithm with null, and return."type"
assertion will be used to check that the type of the fetched module
- matches the type expected by the importer."type"
then:
TypeError
exception."type"
assertion will be used to check that the type of the fetched module
+ matches the type expected by the importer."type"
and entry.[[Value]] is
+ neither undefined nor "json"
, then asynchronously complete this
+ algorithm with null, and return.script
", options, settings object,
"client
", moduleRequest, and with the
@@ -90143,8 +90148,11 @@ document.querySelector("button").addEventListener("click", bound);
"json"
,
- asynchronously complete this algorithm with null, and return."json"
.
+ Otherwise we would not have reached this point because a failure would have been raised when
+ inspecting moduleRequest.[[Assertions]] in create a JavaScript module script or fetch
+ an import() module script graph."type"
, then let module type
+ be entry.[[Value]]. Otherwise let module type be undefined."json"
, then:
TypeError
exception.
"javascript"
)] is
"fetching
", wait in parallel until that entry's value
changes, then queue a task on the networking task source to proceed
with running the following steps."javascript"
)] exists, asynchronously complete this algorithm with
+ moduleMap[(url, "javascript"
)], and return.fetching
"."javascript"
)] to "fetching
"."javascript"
)] to null, asynchronously complete this algorithm with null, and
+ return."javascript"
)] to module script, and asynchronously complete this
+ algorithm with module script."javascript"
)].fetching
" or null); by now all module
@@ -91238,20 +91238,23 @@ dictionary PromiseRejectionEventInit : EventInit {
- fetching
". Module maps are
- used to ensure that imported JavaScript modules are only fetched, parsed, and evaluated once per
- Document
or worker. Currently only JavaScript
- module scripts are supported, so the module type will always
- be null until additional module types are introduced."javascript"
). The module map's values are either a module
+ script, null (used to represent failed fetches), or a placeholder value "fetching
". Module maps are used to ensure
+ that imported JavaScript modules are only fetched, parsed, and evaluated once per
+ Document
or worker . Currently only JavaScript module scripts are supported, so the module type will always be
+ "javascript"
until additional module types are introduced.
data-x="SharedWorker">shared workers are keyed by their parsed constructor url.
- import "https://example.com/module.mjs";
import "https://example.com/module.mjs#map-buster";
@@ -91277,24 +91280,24 @@ import "https://example.com/foo/../module2.mjs";
"json"
for the second):
+ "javascript"
for the first, and
+ "json"
for the second):
- import "https://example.com/module";
+
- import "https://example.com/module";
import "https://example.com/module" assert { type: "json" };
"javascript"
)]. (This entry must exist for us to
+ have gotten to this point.)fetching
").
"javascript"
)] to null, asynchronously complete this algorithm with null, and
@@ -91253,8 +91251,8 @@ dictionary PromiseRejectionEventInit : EventInit {
"javascript"
type):
import "https://example.com/module" assert { type: "json" };
import "https://example.com/module.mjs";
import "https://example.com/module.mjs#map-buster";
@@ -91290,8 +91288,9 @@ import "https://example.com/foo/../module2.mjs";
"javascript"
)]. (This entry must exist for us to
- have gotten to this point.)fetching
"). elements.
---
source | 54 +++++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/source b/source
index 330254c2b6e..b9761f489af 100644
--- a/source
+++ b/source
@@ -89768,13 +89768,13 @@ document.querySelector("button").addEventListener("click", bound);
"type"
then asynchronously complete this
+ that entry.[[Key]] is "type
" then asynchronously complete this
algorithm with null, and return."type"
assertion will be used to check that the type of the fetched module
+ assertion is provided. When support is added for other module types, the "type
" assertion will be used to check that the type of the fetched module
matches the type expected by the importer."javascript"
)] is
+ javascript
")] is
"fetching
", wait in parallel until that entry's value
changes, then queue a task on the networking task source to proceed
with running the following steps."javascript"
)] javascript
")] exists, asynchronously complete this algorithm with
- moduleMap[(url, "javascript"
)], and return.javascript
")], and return.
- "javascript"
)] to "fetching
".javascript
")] to "fetching
"."javascript"
)] to null, asynchronously complete this algorithm with null, and
+ javascript
")] to null, asynchronously complete this algorithm with null, and
return."javascript"
)] to module script, and asynchronously complete this
+ javascript
")] to module script, and asynchronously complete this
algorithm with module script."javascript"
)].javascript
")].fetching
" or null); by now all module
@@ -90487,8 +90487,8 @@ document.querySelector("button").addEventListener("click", bound);
"type"
then:type
" then:
TypeError
exception."type"
assertion will be used to check that the type of the fetched module
+ assertion is provided. When support is added for other module types, the "type
" assertion will be used to check that the type of the fetched module
matches the type expected by the importer."javascript"
). The module map's values are either a module
+ the module was fetched, and the string indicates the type of the module (e.g. "javascript
"). The module map's values are either a module
script, null (used to represent failed fetches), or a placeholder value "fetching
". Module maps are used to ensure
that imported JavaScript modules are only fetched, parsed, and evaluated once per
Document
or worker . Currently only JavaScript module scripts are supported, so the module type will always be
- "javascript"
until additional module types are introduced.javascript
" until additional module types are introduced.
"javascript"
type):javascript
" type):
import "https://example.com/module.mjs";
import "https://example.com/module.mjs#map-buster";
@@ -91281,8 +91281,8 @@ import "https://example.com/foo/../module2.mjs";
"javascript"
for the first, and
- "json"
for the second):
+ the module map (the type is "javascript
" for the first, and
+ "json
" for the second):
@@ -91537,8 +91537,8 @@ import "https://example.com/module" assert { type: "json" };
same two arguments (either while creating the
corresponding module script, or in fetch an import() module script graph).
- import "https://example.com/module";
import "https://example.com/module" assert { type: "json" };
"javascript"
)]. (This entry must exist for us
+ javascript
")]. (This entry must exist for us
to have gotten to this point.)
@@ -89766,19 +89767,20 @@ document.querySelector("button").addEventListener("click", bound);
type
", because
+ we only asked for "type
" assertions in
+ HostGetSupportedAssertions.type
" then asynchronously complete this
algorithm with null, and return.type
" assertion will be used to check that the type of the fetched module
- matches the type expected by the importer.type
" assertion will be used to check that the type of the fetched module
+ matches the type expected by the importer.type
", because
+ we only asked for "type
" assertions in
+ HostGetSupportedAssertions.type
" assertion will be used to check that the type of the fetched module
matches the type expected by the importer.
-
- HostGetSupportedAssertions()
+
+
+
+
type
".Event loops
From 2fc3616a44156363f9abf7a297b60ea4dc15bd7c Mon Sep 17 00:00:00 2001
From: Daniel Clark HostGetSupportedAssertions()
-
-
+ type
".
+
type
" ».javascript
" for the first, and
"json
" for the second):
-
+ import "https://example.com/module";
-import "https://example.com/module" assert { type: "json" };
<script>
+ import "https://example.com/module";
+</script>
+<script>
+ import "https://example.com/module" assert { type: "json" };
+</script>
javascript
").
"json"
for the second):
-
-
-
- import "https://example.com/module";
-import "https://example.com/module" assert { type: "json" };
"json"
for the second):
+
+
+
+ <script>
+ import "https://example.com/module";
+</script>
+<script>
+ import "https://example.com/module" assert { type: "json" };
+</script>
javascript
")
+ ».javascript
")
+ ».
-
@@ -88805,7 +88809,7 @@ document.querySelector("button").addEventListener("click", bound);
arguments.javascript
")
+ ».javascript
")
+ ».javascript
"), then:
javascript
") to visited set.javascript
").
type
", because
+ we only asked for "type
" assertions in
+ HostGetSupportedAssertions."type"
and entry.[[Value]] is
neither undefined nor "json"
, then asynchronously complete this
@@ -89125,6 +89131,11 @@ document.querySelector("button").addEventListener("click", bound);
type
", because
+ we only asked for "type
" assertions in
+ HostGetSupportedAssertions.HostGetSupportedAssertions()
+
+
+
+
type
".Event loops
From 1b4da46b23fb649938ff5f8e5453b6c8529a7bd1 Mon Sep 17 00:00:00 2001
From: Daniel Clark HostGetSupportedAssertions()
-
-
+ type
".
+
type
" ».module
" means that the script is a module script, to be
- interpreted according to the JavaScript Module top-level
- production. Module scripts are not affected by the defer
- attribute, but are affected by the async
attribute
- (regardless of the state of the src
attribute).module
" means that the script is a module script. If it has
+ a JavaScript MIME type, or if the script is embedded inline, then it will be
+ interpreted as a JavaScript module script according to the JavaScript Module top-level production; if it has a JSON MIME
+ type, then it will be interpreted as a JSON module script. Module scripts
+ are not affected by the defer
attribute, but are
+ affected by the async
attribute (regardless of the state
+ of the src
attribute).
script
attributes (except
), then the same JavaScript module script created by the
former script
element can be used to include an
- external module script.
+ external JavaScript module script.
@@ -57863,37 +57866,37 @@ o............A....e
<script type="module" src="app.mjs"></script>
script
element in the same Window
imports the module from app.mjs
(e.g. via import
- "./app.mjs";
), then the same module script created by the
+ "./app.mjs";script
element will be imported.
- <script type="module" src="app.mjs"></script>
<script nomodule defer src="classic-app-bundle.js"></script>
script
element with the nomodule
attribute
- will be ignored, and the script
element with a type
of "module
" will be fetched and
- evaluated (as a module script). Conversely, older user agents will ignore the
+ script
element with the nomodule
attribute will be ignored, and the
script
element with a type
of "module
", as that is an unknown script type for them — but they will have no
- problem fetching and evaluating the other script
element (as a classic
- script), since they do not implement the nomodule
attribute.script
element with a
+ type
of "module
", as that is an
+ unknown script type for them — but they will have no problem fetching and evaluating the other
+ script
element (as a classic script), since they do not implement the
+ nomodule
attribute.
script
element can be used to write an inline
- module script that performs a number of substitutions on the document's text, in
- order to make for a more interesting reading experience (e.g. on a news site): JavaScript module script that performs a number of substitutions on the document's
+ text, in order to make for a more interesting reading experience (e.g. on a news site):
- <script type="module">
@@ -57925,12 +57928,37 @@ o............A....e
walkAllTextNodeDescendants(document.body, substitute);
</script>
script
element appears in the document, it will not be evaluated until both
- document parsing has complete and its dependency (dom-utils.mjs
) has been
- fetched and evaluated.script
element appears in the document, it will not be evaluated until
+ both document parsing has complete and its dependency (dom-utils.mjs
) has
+ been fetched and evaluated.
+
+ <script type="module">
+ import peopleInSpace from "http://api.open-notify.org/astros.json" assert { type: "json" };
+
+ const list = document.querySelector("#people-in-space");
+ for (const { craft, name } of peopleInSpace.people) {
+ const li = document.createElement("li");
+ li.textContent = `${name} / ${craft}`;
+ list.append(li);
+ }
+ </script>
Content-Type: text/json
. On the
+ other hand, if the assert { type: "json" }
part of the statement is omitted,
+ it is assumed that the intent is to import a JavaScript module script, and the fetch
+ will fail if the HTTP response has a MIME type that is not a JavaScript MIME type.
+
+
+ "type"
and entry.[[Value]] is
- neither undefined nor "json"
, then asynchronously complete this
+ neither undefined nor "json
", then asynchronously complete this
algorithm with null, and return.javascript
" or "json"
. Otherwise we would not have reached this point because a failure would
+ javascript
" or "json
". Otherwise we would not have reached this point because a failure would
have been raised when inspecting moduleRequest.[[Assertions]] in create a JavaScript module script or fetch
an import() module script graph."json"
, then set module script to the result of creating
+ "json
", then set module script to the result of creating
a JSON module script given source text and module map settings
object.javascript
" nor "json"
, then:json
", then:
TypeError
exception.javascript
" for the first,
- and "json"
for the second):
+ and "json
" for the second):
<script>
import "https://example.com/module";
@@ -90016,6 +90056,10 @@ import "https://example.com/foo/../module2.mjs";
javascript
")]. (This entry must exist for us
- to have gotten to this point.)"type"
, then let module type
+ be entry.[[Value]]. Otherwise let module type be undefined.fetching
").type
" assertions in
HostGetSupportedAssertions."type"
and entry.[[Value]] is
- neither undefined nor "json
", then asynchronously complete this
- algorithm with null, and return."type"
, then let module
+ type be entry.[[Value]]. Otherwise let module type be "javascript
".javascript
" nor "json
", then asynchronously complete this algorithm with null, and return.script
", options, settings object,
@@ -88403,8 +88406,7 @@ document.querySelector("button").addEventListener("click", bound);
javascript
")
- »."type"
, then let module
+ type be entry.[[Value]]. Otherwise let module type be "javascript
".javascript
"), then:
javascript
") to visited set."type"
, then let module
+ type be entry.[[Value]]. Otherwise let module type be "javascript
".javascript
")."type"
, then let module
type be entry.[[Value]]. Otherwise let module type be "javascript
". javascript
" for the first,
- and "json
" for the second):
-
-
-
- <script>
- import "https://example.com/module";
-</script>
-<script>
- import "https://example.com/module" assert { type: "json" };
-</script>
From d4f5bd0b35269d76fe8a364d3606746f2478e15d Mon Sep 17 00:00:00 2001
From: Daniel Clark
-
-
-
default
" », the following
- steps, settings's Realm,
- value) with the following steps given module as an argument:
-
- default
", module.[[HostDefined]]).javascript
".
- javascript
", "css
", nor "json
", then asynchronously complete this
+ javascript
", "css
", or "json
", then asynchronously complete this
algorithm with null, and return.javascript
", "css
", or "json
". Otherwise we would not have reached this
- point because a failure would have been raised when inspecting
- moduleRequest.[[Assertions]] in create
- a JavaScript module script or fetch an import() module script graph.javascript
", "css
", or "json
". Otherwise we would not have reached
+ this point because a failure would have been raised when inspecting
+ moduleRequest.[[Assertions]] in create a JavaScript module script or
+ fetch an import() module script graph.javascript
", "css
", nor "json
",
+ javascript
", "css
", or "json
",
then:
TypeError
exception.