diff --git a/source b/source index 493a6e8efc0..ceca857e0cf 100644 --- a/source +++ b/source @@ -2891,13 +2891,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
The following terms are defined in the JSON modules proposal and used in this - specification:
+User agents that support JavaScript must also implement the JSON modules + proposal. The following terms are defined there, and used in this specification:
The contents of the external script resource for CSS module scripts must conform to the requirements of the CSS specification.
+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
attribute, and the contents of the script
element must conform to the requirements
@@ -58791,7 +58796,29 @@ o............A....e
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 a JSON module script can be imported from inside + a JavaScript module script:
+ +<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>
+
+ 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 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.
a Source Text Module Record, for JavaScript module scripts;
a Synthetic Module Record, for CSS - module scripts; or
a Synthetic Module Record, for CSS module + scripts and JSON module scripts
null, representing a parsing failure.
Module scripts can be classified into two types:
+Module scripts can be classified into three types:
A module script is a JavaScript module script if @@ -90442,23 +90469,33 @@ document.querySelector("button").addEventListener("click", bound); data-x="concept-script-record">record is a Synthetic Module Record, and it was created via the create a CSS module script algorithm. CSS module scripts represent a parsed CSS stylesheet.
- - -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.
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 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:
javascript
".
- If module type is neither "javascript
" nor "css
", then asynchronously complete this algorithm with null, and return.
If module type is not "javascript
", "css
", or "json
", then asynchronously complete this
+ algorithm with null, and return.
Fetch a single module script given url, settings
object, "script
", options, settings object,
@@ -91335,11 +91373,12 @@ document.querySelector("button").addEventListener("click", bound);
Assert: module type is either "javascript
" or "css
". 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.
Assert: module type is "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.
Let moduleMap be module map settings object's module map.
If MIME type essence is a JSON MIME type and module
+ type is "json
", then set module script to the result of
+ creating a JSON module script given source text and module map
+ settings object.
Set moduleMap[(url, module type)] to module script, and asynchronously complete this algorithm with @@ -91626,8 +91670,9 @@ document.querySelector("button").addEventListener("click", bound); data-x="">javascript".
If url is failure, or if module type is neither "javascript
" nor "css
", then:
If url is failure, or if module type is not "javascript
", "css
", or "json
",
+ then:
Let error be a new TypeError
exception.
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:
+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.
Return CreateSyntheticModule(« "default
" », the following
- steps, settings's Realm,
- value) with the following steps given module as an argument:
Let result be ParseJSONModule(source).
-default
", module.[[HostDefined]]).If this throws an exception, set script's parse error to that exception, and return + script.
Set script's record to + result.
Return script.