diff --git a/source b/source index 292a6968425..1ffccf86a3a 100644 --- a/source +++ b/source @@ -3112,6 +3112,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

Users agents that support JavaScript must also implement ECMAScript Internationalization API. JSINTL

+

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

+ + +

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

@@ -9827,6 +9836,23 @@ interface DOMStringList { +
  • +

    Otherwise, if value has a [[SourceTextModuleRecord]] internal slot, then:

    + +
      +
    1. If forStorage is true, then throw a + "DataCloneError" DOMException.

    2. + +
    3. Let moduleScript be value.[[SourceTextModuleRecord]]. + [[HostDefined]].

    4. + +
    5. Set serialized to { [[Type]]: "SourceTextModule", [[SourceText]]: value + .[[SourceTextModuleRecord]].[[SourceText]], [[BaseURL]]: moduleScript's + base URL, [[AgentCluster]]: the surrounding agent's agent + cluster }.

    6. +
    +
  • +
  • Otherwise, if value has an [[ErrorData]] internal slot and value is not a platform object, then:

    @@ -10230,6 +10256,34 @@ o.myself = o;
  • +
  • Set serialized to { [[Type]]: "SourceTextModule", [[SourceText]]: + value.[[SourceTextModuleRecord]].[[SourceText]], [[URL]]: moduleScript's + base URL, [[AgentCluster]]: the surrounding + agent's agent cluster }.

  • + +
  • +

    Otherwise, if serialized.[[Type]] is "SourceTextModule", then:

    + +
      +
    1. If targetRealm's corresponding agent cluster is not + serialized.[[AgentCluster]], then throw a + "DataCloneError" DOMException.

      + +
    2. Let settingsObject be targetRealm's environment settings + object.

    3. + +
    4. Let options be a the default script fetch options.

    5. + +
    6. Let moduleScript be the result of creating a JavaScript module script + using serialized.[[SourceText]], settingsObject, + serialized.[[BaseURL]], options, and false.

    7. + +
    8. Let moduleRecord be moduleScript's record.

    9. + +
    10. Set value to moduleRecord.GetModuleSource().

    11. +
    +
  • +
  • Otherwise, if serialized.[[Type]] is "Map", then:

    @@ -107248,8 +107302,18 @@ document.querySelector("button").addEventListener("click", bound);

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

    + data-x="concept-script">script that has the following additional + item:

    + +
    +
    A rooted source boolean
    + +

    A boolean which, if true, means that this script was initialized from a source text that + was securely obtained from a "script" destination request for its base URL, + against the realm's policy container. It is true for modules loaded into the module registry, and + false for modules created via dynamic evaluation or compilation.

    +

    Module scripts can be classified into four types:

    @@ -107811,8 +107875,8 @@ document.querySelector("button").addEventListener("click", bound);
    1. Let script be the result of creating a JavaScript module script - using sourceText, settingsObject, baseURL, and - options.

    2. + using sourceText, settingsObject, baseURL, options, + and false.

    3. Fetch the descendants of and link script, given settingsObject, "javascript-or-wasm", then set moduleScript to the result of creating a WebAssembly module script given bodyBytes, settingsObject, response's URL, and options.

    4. + data-x="concept-response-url">URL, options, and true.

    5. Otherwise:

      @@ -108198,10 +108262,10 @@ document.querySelector("button").addEventListener("click", bound); decoding bodyBytes.

    6. If mimeType is a JavaScript MIME type and moduleType - is "javascript-or-wasm", then set moduleScript to the result of - creating a JavaScript module script given sourceText, + is "javascript-or-wasm", then set moduleScript to the result + of creating a JavaScript module script given sourceText, settingsObject, response's URL, and options.

    7. + data-x="concept-response-url">URL, options and true.

    8. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to @@ -108331,8 +108395,8 @@ document.querySelector("button").addEventListener("click", bound);

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

      + object settings, a URL baseURL, a script fetch + options options, and a boolean rootedSource:

      1. If scripting is disabled for @@ -108353,6 +108417,9 @@ document.querySelector("button").addEventListener("click", bound);

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

      3. +
      4. Set script's rooted source boolean to rootedSource.

        +
      5. +
      6. Let result be ParseModule(source, settings's realm, @@ -108381,8 +108448,8 @@ document.querySelector("button").addEventListener("click", bound);

        To create a WebAssembly module script, given a byte sequence bodyBytes, an environment settings - object settings, a URL baseURL, and a script fetch - options options:

        + object settings, a URL baseURL, a script fetch + options options, and a boolean rootedSource:

        1. @@ -108409,6 +108476,9 @@ document.querySelector("button").addEventListener("click", bound);
        2. Set script's parse error and error to rethrow to null.

        3. +
        4. Set script's rooted source boolean to rootedSource.

          +
        5. +
        6. Let result be the result of parsing a WebAssembly module given bodyBytes, @@ -108759,7 +108829,6 @@ document.querySelector("button").addEventListener("click", bound); [[HostDefined]] field in the ScriptOrModule component of the running JavaScript execution context.

          -
          Killing scripts

          Although the JavaScript specification does not account for this possibility, it's sometimes @@ -111058,6 +111127,75 @@ import "https://example.com/foo/../module2.mjs";

      7. +
      8. +

        If moduleRequest is a Module Record then:

        + +
          +
        1. Let moduleScript be moduleRequest.[[HostDefined]].

        2. + +
        3. Assert: moduleScript is a JavaScript module script or a + WebAssembly module script.

        4. + +
        5. Let url be moduleScript's + base URL.

        6. + +
        7. Let moduleType be "javascript-or-wasm".

        8. + +
        9. Let moduleMap be settingsObject's module map.

        10. + +
        11. Let completion be uninitialized.

        12. + +
        13. +

          If moduleMap[(url, moduleType)] does not exist, then:

          + +
            +
          1. Set moduleMap[(url, moduleType)] to moduleScript + .

          2. + +
          3. Set completion to Completion Record { [[Type]]: normal, + [[Value]]: moduleRequest, [[Target]]: empty }.

          4. +
          + +

          Otherwise: +

            +
          1. If moduleMap[(url, moduleType)] 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.

          2. + +
          3. Let registryModule be moduleMap[(url, + moduleType)].

          4. + +
          5. +

            If registryModule is not null and moduleRequest.ModuleSourcesEqual( + registryModule) is true then:

            + +
              +
            1. Set completion to Completion Record { [[Type]]: normal, + [[Value]]: registryModule, [[Target]]: empty }.

            2. +
            +
          6. + +
          7. +

            Otherwise:

            + +
              +
            1. Set completion to Completion Record { [[Type]]: normal, + [[Value]]: moduleRequest, [[Target]]: empty }.

            2. + +

              When a different module at the same module key already exists, we load the + module that was requested, but do not insert it into the registry, retaining the original + reference.

              +
            +
          8. +
          +
        14. + +
        15. Perform FinishLoadingImportedModule(referrer, + moduleRequest, payload, completion).

        16. +
        +
      9. +
      10. Let referencingScript be null.

      11. Let originalFetchOptions be the default script fetch @@ -120055,6 +120193,12 @@ function showLogout() {

        var worker = new Worker('helper.mjs', { type: "module" });
        +

        Alternatively a module script Module Source Object + object can be provided directly:

        + +
        import source MyModule from './module.js';
        +var worker = new Worker(MyModule);
        +  
        Communicating with a dedicated worker
        @@ -120531,12 +120675,15 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope

        Processing model

        When a user agent is to run a worker for a script with Worker or - SharedWorker object worker, URL url, - environment settings object outside settings, MessagePort - outside port, and a WorkerOptions dictionary options, it must - run the following steps.

        + SharedWorker object worker, URL or module record + urlOrModuleRecord, environment settings object outside settings, + MessagePort outside port, and a WorkerOptions dictionary + options, it must run the following steps.

          +
        1. Assert: If urlOrModuleRecord is a URL, thenoptions's + type member is not "classic"

        2. +
        3. Let is shared be true if worker is a SharedWorker object, and false otherwise.

        4. @@ -120589,9 +120736,11 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope outside settings's origin.

          +
        5. Assert: urlOrModuleRecord is a URL.

        6. +
        7. Set worker global scope's constructor url to - url.

        8. + urlOrModuleRecord.

        9. Set worker global scope's type to the value of options's @@ -120608,10 +120757,15 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope shared is true, and "worker" otherwise.

        10. -

          Obtain script by switching on the value of options's type member:

          +

          If urlOrModuleRecord is a URL, then obtain script by + switching on the value of options's type member:

          +
          "auto"
          +
          Fetch a classic worker script given url, outside + settings, destination, inside settings, and with + onComplete and performFetch as defined below.
          +
          "classic"
          Fetch a classic worker script given url, outside settings, destination, inside settings, and with @@ -120624,7 +120778,7 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope performFetch as defined below.
          -

          In both cases, let performFetch be the following In all cases, let performFetch be the following perform the fetch hook given request, isTopLevel and processCustomFetchResponse:

          @@ -120709,116 +120863,254 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope
        -

        In both cases, let onComplete given script be the following steps:

        +

        In all cases, let onComplete given script be the following step:

          -
        1. If script is null or if script's error to rethrow is non-null, then:

          - -
            -
          1. Queue a global task on the DOM manipulation task source given - worker's relevant global object to fire an event named error - at worker.

          2. +
          3. Initialize a worker given worker, outside port, + is shared, script, inside settings, and worker global scope + .

          4. +
          +
        2. -
        3. Run the environment discarding steps - for inside settings.

        4. +
        5. +

          Otherwise,

          -
        6. Abort these steps.

        7. -
        +
          +
        1. Let script be urlOrModuleRecord.[[HostDefined]].

        2. -
        3. Associate worker with worker global scope.

        4. +
        5. Let baseURL be script's base URL

        6. -
        7. Let inside port be a new MessagePort object in - inside settings's realm.

        8. +
        9. +

          If baseURL is null, then: +

            +
          • Assert: script's rooted source property is false. +

          • -
          • Associate inside port with worker global scope.

          • +
          • Set baseURL to outside settings's API base URL

            +
          • +
          +
        10. -
        11. Entangle outside port and inside port.

        12. +
        13. Set worker global scope's url + to baseURL.

        14. -
        15. Create a new WorkerLocation object and associate it with worker global - scope.

          +
        16. Set workerGlobalScope's policy container to a clone of outside settings's + policy container. + +

        17. Let target module be undefined.

        18. + +
        19. Let options be a script fetch options whose cryptographic nonce is the empty string, integrity metadata is the empty string, + parser metadata is "not-parser-inserted", credentials mode is the value of the + credentials member of options, referrer policy is the empty + string, and fetch priority is + "auto".

        20. -

          Closing orphan workers: Start monitoring the worker such that no sooner than - it stops being a protected worker, and no later than it stops being a - permissible worker, worker global scope's closing flag is set to true.

          -
        21. +

          If urlOrModuleRecord is a Source Text Module Record then:

          +
            +
          1. Let sourceText be urlOrModuleRecord.[[SourceText]].

          2. +
          3. Set target module to the result of creating a JavaScript module script + with sourceText, inside settings, urlOrModuleRecord's + base URL, options and urlOrModuleRecord's + rooted source.

          4. +
          +
        22. -

          Suspending workers: Start monitoring the worker, such that whenever - worker global scope's closing - flag is false and the worker is a suspendable worker, the user agent suspends - execution of script in that worker until such time as either the closing flag switches to true or the worker stops - being a suspendable worker.

          +

          Otherwise, urlOrModuleRecord is a WebAssembly Module Record, then: +

          + +
            +
          1. Let wasmModule be urlOrModuleRecord.[[WebAssemblyModule]].

            +
          2. +
          3. Let bytes be wasmModule.[[Bytes]].

          4. +
          5. Set target module to the result of creating a JavaScript module script + with sourceText, inside settings, urlOrModuleRecord's + base URL, and urlOrModuleRecord's rooted source.

          6. +
        23. -
        24. Set inside settings's execution ready flag.

        25. +
        26. TODO: CSP filter on transferred modules - eval (rooted source) / src checks?

        27. + +
        28. If the Run CSP initialization for a global object algorithm returns + "Blocked" when executed upon worker global scope, throw a new + DOMException and run fail worker initialization with worker + , and inside settings and abort these steps. CSP

        29. + +
        30. TODO: refactor out use of response here:

        31. + +
        32. Otherwise, if the result of + checking a global object's embedder policy with worker global scope, + outsidesettings, and response is false, then throw a DOMException + and run fail worker initialization with worker, and inside + settings and abort these steps. + +

        33. Set worker global scope's cross-origin isolated + capability to true if agent's agent cluster's cross-origin isolation mode is "concrete".

        34. + +
        35. If owner's cross-origin isolated + capability is false, then set worker global scope's cross-origin isolated + capability to false.

        36. + +
        37. If modules's rooted source property is false, then set + worker global scope's cross-origin isolated + capability to false.

        38. -

          If script is a classic script, then run the classic script script. Otherwise, it is a module - script; run the module script - script.

          - -

          In addition to the usual possibilities of returning a value or failing due to - an exception, this could be prematurely aborted by - the terminate a worker algorithm defined below.

          +

          Fetch the descendants + of and link target module given inside settings, + "script", and onComplete and with onComplete + given module defined as the following step:

          + +
            +
          • Initialize a worker given worker, outside port, + false, module, inside settings, and worker global scope.

            +
          • +
        39. +
        +
      -
    9. Enable outside port's port message queue.

    10. +
      -
    11. If is shared is false, enable the port message queue - of the worker's implicit port.

    12. +

      When a user agent is to fail worker initialization for a script with + Worker or SharedWorker object worker, and environment settings + object inside settings , it must run the following steps.

      -
    13. If is shared is true, then queue a global task on DOM - manipulation task source given worker global scope to fire an event named connect at worker global scope, using - MessageEvent, with the data attribute - initialized to the empty string, the ports attribute - initialized to a new frozen array containing inside port, and the source attribute initialized to inside - port.

    14. +
        +
      1. Queue a global task on the DOM manipulation task source given + worker's relevant global object to fire an event named error + at worker.

      2. -
      3. Enable the client message queue of the - ServiceWorkerContainer object whose associated service worker client is - worker global scope's relevant settings object.

      4. +
      5. Run the environment discarding steps + for inside settings.

      6. +
      -
    15. -

      Event loop: Run the responsible - event loop specified by inside settings until it is destroyed.

      +
      -

      The handling of events or the execution of callbacks by tasks run by the event loop might get prematurely aborted by the terminate a - worker algorithm defined below.

      +

      When a user agent is to initialize a worker for a script with Worker + or SharedWorker object worker, MessagePort + outside port, boolean is shared, module script or classic + script script, environment settings object inside settings + , and a global object worker global scope, it must run the following + steps.

      -

      The worker processing model remains on this step until the event loop is - destroyed, which happens after the closing - flag is set to true, as described in the event loop processing model.

      -
    16. +
        +
      1. If script is null or if script's error to rethrow is non-null, then:

        -
      2. -

        Clear the worker global scope's - map of active timers.

        -
      3. +
          +
        1. Fail worker initialization given worker and inside settings +

        2. -
        3. -

          Disentangle all the ports in the list of the worker's ports.

          -
        4. +
        5. Abort these steps.

        6. +
        -
      4. -

        Empty worker global scope's owner set.

        -
      5. -
      +
    17. Associate worker with worker global scope.

    18. + +
    19. Let inside port be a new MessagePort object in + inside settings's realm.

    20. + +
    21. Associate inside port with worker global scope.

    22. + +
    23. Entangle outside port and inside port.

    24. + +
    25. Create a new WorkerLocation object and associate it with worker global + scope.

      + +
    26. +

      Closing orphan workers: Start monitoring the worker such that no sooner than + it stops being a protected worker, and no later than it stops being a + permissible worker, worker global scope's closing flag is set to true.

      +
    27. + +
    28. +

      Suspending workers: Start monitoring the worker, such that whenever + worker global scope's closing + flag is false and the worker is a suspendable worker, the user agent suspends + execution of script in that worker until such time as either the closing flag switches to true or the worker stops + being a suspendable worker.

      +
    29. + +
    30. Set inside settings's execution ready flag.

    31. + +
    32. +

      If script is a classic script, then run the classic script script. Otherwise, it is a module + script; run the module script + script.

      + +

      In addition to the usual possibilities of returning a value or failing due to + an exception, this could be prematurely aborted by + the terminate a worker algorithm defined below.

      +
    33. + +
    34. Enable outside port's port message queue.

    35. + +
    36. If is shared is false, enable the port message queue + of the worker's implicit port.

    37. + +
    38. If is shared is true, then queue a global task on DOM + manipulation task source given worker global scope to fire an event named connect at worker global scope, using + MessageEvent, with the data attribute + initialized to the empty string, the ports attribute + initialized to a new frozen array containing inside port, and the source attribute initialized to inside + port.

    39. + +
    40. Enable the client message queue of the + ServiceWorkerContainer object whose associated service worker client is + worker global scope's relevant settings object.

    41. + +
    42. +

      Event loop: Run the responsible + event loop specified by inside settings until it is destroyed.

      + +

      The handling of events or the execution of callbacks by tasks run by the event loop might get prematurely aborted by the terminate a + worker algorithm defined below.

      + +

      The worker processing model remains on this step until the event loop is + destroyed, which happens after the closing + flag is set to true, as described in the event loop processing model.

      +
    43. + +
    44. +

      Clear the worker global scope's + map of active timers.

      +
    45. + +
    46. +

      Disentangle all the ports in the list of the worker's ports.

      +
    47. + +
    48. +

      Empty worker global scope's owner set.

    @@ -120981,7 +121273,7 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope
    [Exposed=(Window,DedicatedWorker,SharedWorker)]
     interface Worker : EventTarget {
    -  constructor((TrustedScriptURL or USVString) scriptURL, optional WorkerOptions options = {});
    +  constructor((TrustedScriptURL or USVString or object) moduleOrURL, optional WorkerOptions options = {});
     
       undefined terminate();
     
    @@ -120992,25 +121284,27 @@ interface Worker : EventTarget {
     };
     
     dictionary WorkerOptions {
    -  WorkerType type = "classic";
    +  WorkerType type = "auto";
       RequestCredentials credentials = "same-origin"; // credentials is only used if type is "module"
       DOMString name = "";
     };
     
    -enum WorkerType { "classic", "module" };
    +enum WorkerType { "classic", "module", "auto" };
     
     Worker includes AbstractWorker;
    -
    worker = new Worker(scriptURL [, options ])
    -

    Returns a new Worker object. scriptURL will be fetched and - executed in the background, creating a new global environment for which worker - represents the communication channel. options can be used to define the worker = new Worker(moduleOrURL [, options ]) +

    Returns a new Worker object. moduleOrURL will be loaded in the + background, creating a new global environment for which worker represents the + communication channel. options can be used to define the name of that global environment via the name option, primarily for debugging purposes. It can also ensure this new - global environment supports JavaScript modules (specify type: "module"), - and if that is specified, can also be used to specify how scriptURL is fetched through - the credentials option.

    + data-x="">name option, primarily for debugging purposes. It can also be used to specify + that moduleOrURL must be loaded as a JavaScript module by setting + type: "module", and if that is specified, can also be used to specify how moduleOrURL + and its dependencies are fetched through the credentials option. + When moduleOrURL is a Module Source Object, type: "module + is the default and only setting supported.

    worker.terminate()
    Aborts worker's associated global environment.
    @@ -121074,19 +121368,60 @@ enum WorkerType { "classic", "module" };
    -

    When the Worker(scriptURL, +

    When the Worker(moduleOrURL, options) constructor is invoked, the user agent must run the following steps:

      +
    1. Let outside settings be the current settings object.

      + +
    2. +

      If moduleOrURL is an object, then:

      + +
        +
      1. Let module be the result of invoking GetModuleSourceModuleRecord + with moduleOrURL.

      2. + +
      3. +

        If module is not ~not-a-module~, then:

        + +
          +
        1. Assert: module is either a Source Text Module Record + or a WebAssembly Module Record.

        2. + +
        3. Let worker be a new Worker object.

        4. + +
        5. Let outside port be a new MessagePort in + outside settings's realm.

          +
        6. + +
        7. Associate the outside port with worker.

        8. + +
        9. If options's type member is "classic + ", then throw a "TypeError" DOMException.

          +
        10. + +
        11. +

          Run this step in parallel:

          + +
            +
          1. Run a worker given worker, module, + outside settings, outside port, and options.

          2. +
          +
        12. + +
        13. Return worker.

        14. +
        +
      4. +
      +
    3. +
    4. Let compliantScriptURL be the result of invoking the Get Trusted Type compliant string algorithm with TrustedScriptURL, this's relevant global - object, scriptURL, "Worker constructor", and ", scriptURLOrModule, "Worker constructor", and "script".

    5. -
    6. Let outside settings be the current settings object.

      -
    7. Let worker URL be the result of encoding-parsing a URL given compliantScriptURL, relative to outside settings.

      @@ -144897,6 +145232,9 @@ INSERT INTERFACES HERE
      [JSDYNAMICCODEBRANDCHECKS]
      Dynamic code brand checks. Ecma International.
      +
      [JSESMPHASEIMPORTS]
      +
      ESM Phase Imports. Ecma International.
      +
      [JSIMPORTATTRIBUTES]
      Import attributes. Ecma International.