From d76829fe0f162b66ee87c4dc3c9ee147384371d6 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sat, 16 Feb 2019 17:50:15 +0100 Subject: [PATCH 01/11] [WIP] JSON module support This patch provides JSON modules as a single default export, with parse errors checked before instantiating the module graph. Note, editorially, it's unclear whether JSON modules should be considered a type of "module script", with a settings object, fetch options, base URL, etc or not. This patch considers them "module scripts", but leaves those record fields unset (as they are unused). This patch is based on https://github.com/tc39/proposal-javascript-standard-library/pull/44 which hasn't landed yet, so the references are a bit awkward, and this patch should not land until that one does. Closes #4315 --- source | 89 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 16 deletions(-) diff --git a/source b/source index 413dea01e24..c87427977b2 100644 --- a/source +++ b/source @@ -2778,6 +2778,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • the RequestCredentials enumeration
  • the RequestDestination enumeration
  • the fetch() method
  • +
  • consume body
  • response and its @@ -3116,6 +3117,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

    User agents that support JavaScript must also implement the BigInt proposal.

    + +

    User agents that support JavaScript must also implement the JavaScript standard library proposal. + The following terms are defined there, and used in this specification:

    + @@ -86655,7 +86665,7 @@ interface ApplicationCache : EventTarget {
    Definitions
    -

    A script is one of two possible A script is one of three possible structs. All scripts have:

    @@ -86668,7 +86678,9 @@ interface ApplicationCache : EventTarget {

    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; + script">module scripts; a Synthetic Module Record for JSON module scripts; or null. In the + former two cases, it represents a parsed script; in the third case, a parsed JSON document; null represents a failure parsing.

    A parse @@ -86721,6 +86733,10 @@ interface ApplicationCache : EventTarget { data-x="concept-script">script. It has no additional items.

    +

    A JSON module script is another type of script. It has no additional items.

    +

    The active script is determined by the following algorithm:

      @@ -87359,25 +87375,63 @@ interface ApplicationCache : EventTarget {
    1. response's status is not an ok status

    2. + + -
    3. -

      The result of extracting a MIME type from - response's header list is not a - JavaScript MIME type

      +
    4. +

      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.

      -
    5. - +

      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.

      -
    6. Let source text be the result of UTF-8 - decoding response's body.

    7. +
    8. Let module script be null.

    9. -
    10. Let module script be the result of creating a module script given - source text, module map settings object, response's url, and options.

    11. +
    12. +

      If type is a JavaScript MIME type, then:

      + +
        +
      1. Let source text be the result of UTF-8 + decoding response's body.

      2. + +
      3. Set module script to the result of creating a module script given + source text, module map settings object, response's url, and options.

      4. +
      +
    13. + +
    14. +

      If type is a JSON MIME type, then:

      + +
        +
      1. Set module script to a new JSON module script that this algorithm + will subsequently initialize.

      2. + +
      3. +

        Let json be the result of running consume body on + response with JSON.

        + +

        If this throws an exception, catch it, and set module script's + parse error to that exception.

        +
      4. + +
      5. +

        If no exception was thrown, set module script's record to CreateSyntheticModule + (« "default" », the following steps, module map settings object's + Realm, json) with the + following steps given module as an argument:

        +
          +
        1. 1. SetSyntheticModuleExport(module, "default", + module.[[HostDefined]]).
        2. +
        +
      6. +
      +
    15. Set moduleMap[url] to module @@ -121954,6 +122008,9 @@ INSERT INTERFACES HERE

      [JSINTL]
      ECMAScript Internationalization API Specification. Ecma International.
      +
      [JSSTDLIB]
      +
      JavaScript Standard Library. Ecma International.
      +
      [JSON]
      The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
      From 602cf443a52070ee7208d675fed4412779251861 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 4 Mar 2019 23:00:14 +0100 Subject: [PATCH 02/11] Remove errant 1. --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index c87427977b2..f227e440053 100644 --- a/source +++ b/source @@ -87426,7 +87426,7 @@ interface ApplicationCache : EventTarget { Realm, json) with the following steps given module as an argument:

        -
      1. 1. SetSyntheticModuleExport(module, "default", +
      2. SetSyntheticModuleExport(module, "default", module.[[HostDefined]]).
    16. From 5c52c2d65ddec299821253bf600723ef43cd7c5c Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 6 Mar 2019 09:55:40 +0100 Subject: [PATCH 03/11] JSON is "a parsed script" --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index f227e440053..cb60470c243 100644 --- a/source +++ b/source @@ -86680,7 +86680,7 @@ interface ApplicationCache : EventTarget { scripts; a Source Text Module Record, for module scripts; a Synthetic Module Record for JSON module scripts; or null. In the - former two cases, it represents a parsed script; in the third case, a parsed JSON document; + all but the last case, it represents a parsed script; null represents a failure parsing.

      A parse From 35f53f5eb19bc57b775660e9a73dc7c2683746f8 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 6 Mar 2019 18:41:39 +0100 Subject: [PATCH 04/11] Rename module script to JavaScript module script This patch creates a common concept of a "module script", unifying JavaScript module scripts with JSON module scripts (and future concepts like style sheet module scripts, WebAssembly module scripts, etc.) The name change includes the following fixes: - Clarify that works for JSON module scripts. - Check for Cyclic Module Records in fetching module descendants and finding the first parse error. - Initialize the settings object and error to rethrow in JSON module scripts, both of which are used by algorithms in HTML. - Add various asserts to make it clear why we can use things when we do. Module scripts may be renamed to simply "modules" in a future patch. --- source | 274 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 171 insertions(+), 103 deletions(-) diff --git a/source b/source index cb60470c243..247e686def8 100644 --- a/source +++ b/source @@ -3032,6 +3032,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute Record specification types
    17. The Property Descriptor specification type
    18. The Script Record specification type
    19. +
    20. The Cyclic Module Record specification type
    21. The Source Text Module Record specification type and its Evaluate and Instantiate methods
    22. @@ -57769,11 +57770,13 @@ interface HTMLScriptElement : HTMLElement { redundantly setting it.

    23. 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).

    24. + "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. Module scripts are not affected by + the defer attribute, but are affected by the async attribute (regardless of the state of the src attribute).

    25. 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 may either be embedded inline or may 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.

      +

      Classic scripts and JavaScript module scripts may be embedded inline, and all script types may 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 + JavaScript module scripts respectively. +

      When used to include data blocks, the data must be embedded inline, the format of the data must be given using the type @@ -58041,7 +58045,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>
      @@ -58052,37 +58056,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 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.

      + data-x="">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.

      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">
      @@ -58114,12 +58118,12 @@ 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.

      @@ -58539,9 +58543,9 @@ o............A....e
      "module"
        -
      1. Let script be the result of creating a module script using - source text, settings object, base URL, and - options.

      2. +
      3. Let script be the result of creating a JavaScript module + script using source text, settings object, base + URL, and options.

      4. If this returns null, set the script's script to null and return; the script is ready.

      5. @@ -86677,11 +86681,10 @@ interface ApplicationCache : EventTarget {
        A record

        Either a Script Record, for classic - scripts; a Source Text Module Record, for module scripts; a Synthetic Module Record for JSON module scripts; or null. In the - all but the last case, it represents a parsed script; - null represents a failure parsing.

        + scripts; a Source Text Module Record, for JavaScript module scripts; a Synthetic Module Record for JSON module scripts; or null. In all but the last case, it + represents a parsed script; null represents a failure parsing.

      A parse error
      @@ -86733,9 +86736,19 @@ interface ApplicationCache : EventTarget { data-x="concept-script">script. It has no additional items.

      -

      A JSON module script is another type of script. It has no additional items.

      +

      This specification defines multiple types of module scripts. None of these have additional + items

      + +
        +
      • A JavaScript module script represents a JavaScript Source + Text Module Record.

      • + +
      • A JSON module script represents a parsed JSON document.

        + As JSON documents do import dependent modules and do not throw exceptions on execution, + the fetch options and base URL of a JSON module script + are always null.
      • +

      The active script is determined by the following algorithm:

      @@ -87398,9 +87411,10 @@ interface ApplicationCache : EventTarget {
    26. Let source text be the result of UTF-8 decoding response's body.

    27. -
    28. Set module script to the result of creating a module script given - source text, module map settings object, response's url, and options.

    29. +
    30. Set module script to the result of creating a JavaScript module + script given source text, module map settings object, + response's url, and + options.

  • @@ -87408,28 +87422,8 @@ interface ApplicationCache : EventTarget {

    If type is a JSON MIME type, then:

      -
    1. Set module script to a new JSON module script that this algorithm - will subsequently initialize.

    2. - -
    3. -

      Let json be the result of running consume body on - response with JSON.

      - -

      If this throws an exception, catch it, and set module script's - parse error to that exception.

      -
    4. - -
    5. -

      If no exception was thrown, set module script's record to CreateSyntheticModule - (« "default" », the following steps, module map settings object's - Realm, json) with the - following steps given module as an argument:

      -
        -
      1. SetSyntheticModuleExport(module, "default", - module.[[HostDefined]]).
      2. -
      -
    6. +
    7. Set module script to the result of creating a JSON module + script given response and module map settings object.

    @@ -87458,7 +87452,8 @@ interface ApplicationCache : EventTarget {
  • Let record be module script's record.

  • -
  • If record.[[RequestedModules]] is empty, +

  • If record is not a Cyclic Module Record, or if + record.[[RequestedModules]] is empty, asynchronously complete this algorithm with module script.

  • Let urls be a new empty list.

  • @@ -87494,6 +87489,9 @@ 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 JavaScript + module script.

  • +
  • For each url in urls, perform the internal module script graph fetching procedure given url, @@ -87585,38 +87583,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.)

  • +
      +
    1. Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.

    2. -
    3. Let childModules be the list obtained by getting each value in moduleMap whose key is given by an - item of childURLs.

    4. +
    5. 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.)

    6. -
    7. -

      For each childModule of - childModules:

      +
    8. Let childModules be the list obtained by getting each value in moduleMap whose key is given by an + item of childURLs.

    9. -
        -
      1. 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.

      2. +
      3. +

        For each childModule of + childModules:

        -
      4. If discoveredSet already contains - childModule, continue.

      5. +
          +
        1. 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.

        2. -
        3. Let childParseError be the result of finding the first parse - error given childModule and discoveredSet.

        4. +
        5. If discoveredSet already contains + childModule, continue.

        6. -
        7. If childParseError is not null, return childParseError.

        8. -
        - +
      6. Let childParseError be the result of finding the first parse + error given childModule and discoveredSet.

      7. + +
      8. If childParseError is not null, return childParseError.

      9. +
      + +
  • Return null.

  • @@ -87678,10 +87681,10 @@ interface ApplicationCache : EventTarget {
  • Return script.

  • -

    To create a module script, given a - JavaScript string source, an environment settings object - settings, a URL baseURL, and some script fetch - options options:

    +

    To create a JavaScript module script, + given a JavaScript string source, an environment settings + object settings, a URL baseURL, and some script + fetch options options:

    1. If scripting is disabled for @@ -87757,6 +87760,54 @@ interface ApplicationCache : EventTarget {

    2. Return script.

    +

    To create a JSON module script, given a response response and an environment settings + object settings:

    + +
      +
    1. Let script be a new JSON module script that this algorithm will + subsequently initialize.

    2. + +
    3. Set script's settings object to settings.

    4. + +
    5. Set script's base URL and + fetch options to null.

    6. + +
    7. Set script's parse error and + error to rethrow to null.

    8. + +
    9. +

      Let json be the result of running consume body on + response with JSON.

      + +

      If this throws an exception, catch it, set script's parse error to that exception, and return + script.

      +
    10. + +
    11. Set script's record to the result + of creating a synthetic + module record with a default export of json with settings.

    12. + +
    13. Return script.

    14. +
    + +

    To create a synthetic module record with a default export of a JavaScript value + value with an environment settings object settings:

    + +
      +
    1. +

      Return CreateSyntheticModule(« "default" », the following steps, + settings's Realm, + value) with the following steps given module as an argument:

      + +
        +
      1. SetSyntheticModuleExport(module, "default", + module.[[HostDefined]]).
      2. +
      +
    2. +
    +
    Calling scripts

    To run a classic script given a classic script @@ -88868,6 +88919,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.

  • @@ -88941,6 +88995,13 @@ import "https://example.com/foo/../module2.mjs";
  • 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.

  • + +
  • Assert: is not null, since this algorithm is always called + from a classic script or a JavaScript module script.

  • As explained above for HostResolveImportedModule, in the common @@ -89006,6 +89067,10 @@ import "https://example.com/foo/../module2.mjs";

    1. Let module script be moduleRecord.[[HostDefined]].

    2. +
    3. Assert: module script's base + URL is not null, as module script is a JavaScript module + script.

    4. +
    5. Let urlString be module script's base URL, serialized.

    6. @@ -92361,6 +92426,9 @@ document.body.appendChild(frame)
    7. Let base URL be initiating script's base URL.

    8. +
    9. Assert: base URL is not null, as initiating script is a + classic script or a JavaScript module script.

    10. +
    11. Let fetch options be a script fetch options whose cryptographic nonce is initiating From 42a5675b27099a851b44b7cbb338a945d830e27f Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 8 Mar 2019 10:41:26 +0100 Subject: [PATCH 05/11] Fix markup error --- source | 60 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/source b/source index 247e686def8..cccfaaf8277 100644 --- a/source +++ b/source @@ -87583,43 +87583,45 @@ interface ApplicationCache : EventTarget { then return moduleScript's parse error.

    12. -
    13. If moduleScript's record is a - Cyclic Module Record:

    14. +
    15. +

      If moduleScript's record is a + Cyclic Module Record:

      -
        -
      1. Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.

      2. +
          +
        1. Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.

        2. -
        3. 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.)

        4. +
        5. 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.)

        6. -
        7. Let childModules be the list obtained by getting each value in moduleMap whose key is given by an - item of childURLs.

        8. +
        9. Let childModules be the list obtained by getting each value in moduleMap whose key is given by an + item of childURLs.

        10. -
        11. -

          For each childModule of - childModules:

          +
        12. +

          For each childModule of + childModules:

          -
            -
          1. 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.

          2. +
              +
            1. 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.

            2. -
            3. If discoveredSet already contains - childModule, continue.

            4. +
            5. If discoveredSet already contains + childModule, continue.

            6. -
            7. Let childParseError be the result of finding the first parse - error given childModule and discoveredSet.

            8. +
            9. Let childParseError be the result of finding the first parse + error given childModule and discoveredSet.

            10. -
            11. If childParseError is not null, return childParseError.

            12. -
            - -
          +
        13. If childParseError is not null, return childParseError.

        14. +
        + +
      +
    16. Return null.

    From eab8fe525f25df136e164bcd91236f512fc7d424 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 8 Mar 2019 15:29:50 +0100 Subject: [PATCH 06/11] Improving formatting, fixing typos --- source | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/source b/source index cccfaaf8277..081d99e02f2 100644 --- a/source +++ b/source @@ -86680,11 +86680,22 @@ interface ApplicationCache : EventTarget {
    A record
    -

    Either 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. In all but the last case, it - represents a parsed script; null represents a failure parsing.

    +
    +

    One of the following:

    + +
      +
    • Script Record, for classic + scripts

    • + +
    • a Source Text Module Record, for JavaScript module scripts

    • + +
    • Synthetic Module Record, for JSON module + scripts

    • + +
    • null, representing a parsing failure.

    • +
    +
    A parse error
    @@ -86737,17 +86748,17 @@ interface ApplicationCache : EventTarget { item">items.

    This specification defines multiple types of module scripts. None of these have additional - items

    + items.

    • A JavaScript module script represents a JavaScript Source Text Module Record.

    • -
    • A JSON module script represents a parsed JSON document.

      +
    • A JSON module script represents a parsed JSON document. As JSON documents do import dependent modules and do not throw exceptions on execution, the fetch options and base URL of a JSON module script - are always null.

    • + are always null.

    The active script is determined by the following algorithm:

    @@ -89001,9 +89012,6 @@ import "https://example.com/foo/../module2.mjs";
  • Assert: Neither base URL nor fetch options is null, as referencing script is a classic script or a JavaScript module script.

  • - -
  • Assert: is not null, since this algorithm is always called - from a classic script or a JavaScript module script.

  • As explained above for HostResolveImportedModule, in the common From 712d7e6f5313f6c46b3891ed08c63c8f3c8c49ac Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 6 May 2019 11:56:56 +0200 Subject: [PATCH 07/11] Fix usage of "consume body", which returns a Promise --- source | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source b/source index 081d99e02f2..3e0cc2fb20f 100644 --- a/source +++ b/source @@ -87789,20 +87789,24 @@ interface ApplicationCache : EventTarget {

  • Set script's parse error and error to rethrow to null.

  • -
  • -

    Let json be the result of running consume body on - response with JSON.

    +
  • Let jsonPromise be the result of running consume body on + response with JSON.

  • -

    If this throws an exception, catch it, set script's parse error to that exception, and return - script.

    - +
  • Upon rejection of jsonPromise with reason, set script's + parse error to reason, and return + script.

  • -
  • Set script's record to the result - of creating a synthetic - module record with a default export of json with settings.

  • +
  • +

    Upon fulfillment of jsonPromise with json:

    -
  • Return script.

  • +
      +
    1. Set script's record to the result + of creating a synthetic + module record with a default export of json with settings.

    2. + +
    3. Return script.

    4. +
    +

    To create a synthetic module record with a default export of a JavaScript value From 888fe2b9400faac9610b1cb0c85b363649f45f8d Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 6 May 2019 23:08:48 +0200 Subject: [PATCH 08/11] Various editorial improvements from Domenic's review --- source | 56 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/source b/source index 3e0cc2fb20f..3d1ea201404 100644 --- a/source +++ b/source @@ -3018,7 +3018,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute @@toPrimitive, and @@toStringTag

  • Well-Known Intrinsic Objects, including - %ArrayPrototype% and + %ArrayBuffer%, + %ArrayPrototype%, + %JSONParse%, and %ObjProto_valueOf%
  • The FunctionBody production
  • @@ -57807,6 +57809,9 @@ interface HTMLScriptElement : HTMLElement { JavaScript module scripts respectively.

    +

    The external script resource of 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 @@ -86684,13 +86689,13 @@ interface ApplicationCache : EventTarget {

    One of the following:

      -
    • Script Record, for classic +

    • a script record, for classic scripts

    • a Source Text Module Record, for JavaScript module scripts

    • -
    • Synthetic Module Record, for JSON module +

    • a Synthetic Module Record, for JSON module scripts

    • null, representing a parsing failure.

    • @@ -86752,7 +86757,7 @@ interface ApplicationCache : EventTarget {
      • A JavaScript module script represents a JavaScript Source - Text Module Record.

      • + Text Module Record.

      • A JSON module script represents a parsed JSON document. As JSON documents do import dependent modules and do not throw exceptions on execution, @@ -87413,7 +87418,12 @@ interface ApplicationCache : EventTarget { a supported MIME type.

      • -
      • Let module script be null.

      • +
      • +

        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 be null, which is interpreted as failure.

        +
      • If type is a JavaScript MIME type, then:

        @@ -87433,8 +87443,11 @@ interface ApplicationCache : EventTarget {

        If type is a JSON MIME type, then:

          +
        1. Let source text be the result of UTF-8 + decoding response's body.

        2. +
        3. Set module script to the result of creating a JSON module - script given response and module map settings object.

        4. + script given source text and module map settings object.

      • @@ -87773,9 +87786,8 @@ interface ApplicationCache : EventTarget {
      • Return script.

      • -

        To create a JSON module script, given a response response and an environment settings - object settings:

        +

        To create a JSON module script, given a + string source and an environment settings object settings:

        1. Let script be a new JSON module script that this algorithm will @@ -87789,24 +87801,20 @@ interface ApplicationCache : EventTarget {

        2. Set script's parse error and error to rethrow to null.

        3. -
        4. Let jsonPromise be the result of running consume body on - response with JSON.

        5. - -
        6. Upon rejection of jsonPromise with reason, set script's - parse error to reason, and return - script.

        7. -
        8. -

          Upon fulfillment of jsonPromise with json:

          - -
            -
          1. Set script's record to the result - of creating a synthetic - module record with a default export of json with settings.

          2. +

            Let json be ? Call(%JSONParse%, undefined, + « source »).

            -
          3. Return script.

          4. -
          +

          If this throws an exception, set script's parse error to that exception, and return + script.

        9. + +
        10. Set script's record to the result + of creating a synthetic + module record with a default export of json with settings.

        11. + +
        12. Return script.

        To create a synthetic module record with a default export of a JavaScript value From d9e4d84f7f393812874d32a1e068197c6c9db34b Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 7 May 2019 15:13:25 -0400 Subject: [PATCH 09/11] A few more things - Tweaks to