From 2a871036b4c92bbc888bcd2fd04b5622a35f1675 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 Sep 2024 16:23:10 +0200 Subject: [PATCH 01/27] Editorial: make 'module type allowed' take a realm --- source | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source b/source index fd018b599ac..051d3d9a411 100644 --- a/source +++ b/source @@ -107276,10 +107276,11 @@ document.querySelector("button").addEventListener("click", bound); moduleRequest.

  • Assert: the result of running the module type allowed steps - given moduleType and settingsObject is true. Otherwise, we would not have - reached this point because a failure would have been raised when inspecting - moduleRequest.[[Attributes]] in - HostLoadImportedModule or fetch a single imported module script.

  • + given moduleType and settingsObject's realm is true. Otherwise, we would not have reached this point because a + failure would have been raised when inspecting moduleRequest.[[Attributes]] in + HostLoadImportedModule or + fetch a single imported module script.

  • Let moduleMap be settingsObject's module map.

  • @@ -107434,8 +107435,8 @@ document.querySelector("button").addEventListener("click", bound); request steps given moduleRequest.

  • If the result of running the module type allowed steps given - moduleType and settingsObject is false, then run onComplete - given null, and return.

  • + moduleType and settingsObject's realm is false, then run onComplete given null, and return.

  • Fetch a single module script given url, fetchClient, destination, options, settingsObject, referrer, @@ -107725,7 +107726,7 @@ document.querySelector("button").addEventListener("click", bound);

    The module type allowed steps, given a string moduleType - and an environment settings object settings, are as follows:

    + and a realm realm, are as follows:

    1. If moduleType is not "javascript-or-wasm", "

      If moduleType is "css" and the CSSStyleSheet interface is not exposed in - settings's realm, then - return false.

    2. + realm, then return false.

    3. Return true.

    @@ -109959,7 +109959,8 @@ import "https://example.com/foo/../module2.mjs";
  • If the result of running the module type allowed steps given - moduleType and settingsObject is false, then:

    + moduleType and settingsObject's realm is false, then:

    1. Let completion be Completion Record { [[Type]]: throw, From ca50b27e85670deae14bf0c8844e855c5d08a8ad Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 Sep 2024 16:19:21 +0200 Subject: [PATCH 02/27] Editorial: replace the settings object field in scripts by a realm field --- source | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/source b/source index 051d3d9a411..7fdf0621e42 100644 --- a/source +++ b/source @@ -106335,11 +106335,10 @@ document.querySelector("button").addEventListener("click", bound); module script). All scripts have:

      -
      A settings object
      +
      A realm
      -

      An environment settings object, containing various settings that are shared - with other scripts in the same context.

      +

      A realm where the script is evaluated, which is shared with other + scripts in the same context.

      A record
      @@ -106407,6 +106406,10 @@ document.querySelector("button").addEventListener("click", bound); containing document, for inline scripts.

      +

      The settings object of a script is the + settings object of the script's + realm.

      A classic script is a type of script that has the following additional item:

      @@ -107469,8 +107472,8 @@ document.querySelector("button").addEventListener("click", bound);
    2. Let script be a new classic script that this algorithm will subsequently initialize.

    3. -
    4. Set script's settings - object to settings.

    5. +
    6. Set script's realm to + settings's realm.

    7. Set script's base URL to baseURL.

    8. @@ -107525,8 +107528,8 @@ document.querySelector("button").addEventListener("click", bound);
    9. Let script be a new module script that this algorithm will subsequently initialize.

    10. -
    11. Set script's settings - object to settings.

    12. +
    13. Set script's realm to + settings's realm.

    14. Set script's base URL to baseURL.

    15. @@ -107581,8 +107584,8 @@ document.querySelector("button").addEventListener("click", bound);
    16. Let script be a new module script that this algorithm will subsequently initialize.

    17. -
    18. Set script's settings - object to settings.

    19. +
    20. Set script's realm to + settings's realm.

    21. Set script's base URL to baseURL.

    22. @@ -107632,8 +107635,8 @@ document.querySelector("button").addEventListener("click", bound);
    23. Let script be a new module script that this algorithm will subsequently initialize.

    24. -
    25. Set script's settings - object to settings.

    26. +
    27. Set script's realm to + settings's realm.

    28. Set script's base URL and fetch options to null.

    29. @@ -107672,8 +107675,8 @@ document.querySelector("button").addEventListener("click", bound);
    30. Let script be a new module script that this algorithm will subsequently initialize.

    31. -
    32. Set script's settings - object to settings.

    33. +
    34. Set script's realm to + settings's realm.

    35. Set script's base URL and fetch options to null.

    36. @@ -109593,8 +109596,7 @@ dictionary PromiseRejectionEventInit : EventInit

      If active script is not null, set script execution context to a new JavaScript execution context, with its Function field set to null, its Realm field - set to active script's settings - object's realm, and its + set to active script's realm, and its ScriptOrModule set to active script's record.

      From f2fb363376629f321ac69e3c9baa006b731095ba Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:24:27 +0100 Subject: [PATCH 03/27] Editorial: redefine scripting enabled/disabled in terms of realms --- source | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/source b/source index 7fdf0621e42..4ea0a96e190 100644 --- a/source +++ b/source @@ -63372,7 +63372,7 @@ not-slash = %x0000-002E / %x0030-10FFFF to a Document object with a null browsing context, and, accordingly, any script elements they create need to have their already started set to true in the prepare the script element - algorithm and never get executed (scripting is + algorithm and never get executed (scripting is disabled). Such script elements still need to have their parser document set, though, such that their async IDL attribute will return false in the absence of an async @@ -106233,45 +106233,45 @@ document.querySelector("button").addEventListener("click", bound);
      Enabling and disabling scripting
      -

      Scripting is enabled for - an environment settings object settings when all of the following - conditions are true:

      +

      Scripting is enabled for a realm realm + when all of the following conditions are true:

      • The user agent supports scripting.
      • - The user has not disabled scripting for settings at this time. (User agents may + The user has not disabled scripting for realm at this time. (User agents may provide users with the option to disable scripting globally, or in a finer-grained manner, e.g., - on a per-origin basis, down to the level of individual environment settings objects.)
      • + on a per-origin basis, down to the level of individual realms.) -
      • Either settings's global object is not a Window object, - or settings's global object's +
      • Either realm's global object is not a Window object, + or realm's global object's associated Document's active sandboxing flag set does not have its sandboxed scripts browsing context flag set.
      -

      Scripting is disabled - for an environment settings object when scripting is not enabled for it, i.e., when any of the above conditions - are false.

      +

      Scripting is disabled for a realm when + scripting is not enabled for it, i.e., when any of the + above conditions are false.


      Scripting is enabled for a node node if node's node document's browsing - context is non-null, and scripting is - enabled for node's relevant settings object.

      + context
      is non-null, and scripting is + enabled for node's relevant + realm.

      Scripting is disabled for a node when scripting is not enabled, i.e., when its node document's browsing context is null or when scripting is disabled for its relevant settings - object.

      + data-x="concept-realm-noscript">scripting is disabled
      for its relevant realm.

      Secure contexts
      @@ -107466,8 +107466,9 @@ document.querySelector("button").addEventListener("click", bound); baseURL is sanitized here.

      -
    37. If scripting is disabled for - settings, then set source to the empty string.

    38. +
    39. If scripting is disabled for + settings's realm, then set + source to the empty string.

    40. Let script be a new classic script that this algorithm will subsequently initialize.

    41. @@ -107522,8 +107523,9 @@ document.querySelector("button").addEventListener("click", bound); options options:

        -
      1. If scripting is disabled for - settings, then set source to the empty string.

      2. +
      3. If scripting is disabled for + settings's realm, then set + source to the empty string.

      4. Let script be a new module script that this algorithm will subsequently initialize.

      5. @@ -107573,9 +107575,9 @@ document.querySelector("button").addEventListener("click", bound);
        1. -

          If scripting is disabled for - settings, then set bodyBytes to the byte sequence 0x00 0x61 0x73 0x6d 0x01 - 0x00 0x00 0x00.

          +

          If scripting is disabled for + settings's realm, + then set bodyBytes to the byte sequence 0x00 0x61 0x73 0x6d 0x01 0x00 0x00 0x00.

          This byte sequence corresponds to an empty WebAssembly module with only the magic bytes and version number provided.

          @@ -107903,8 +107905,9 @@ document.querySelector("button").addEventListener("click", bound); settings is a Window object whose Document object is not fully active, then return "do not run".

          -
        2. If scripting is disabled for - settings, then return "do not run".

          +
        3. If scripting is disabled for + settings's realm, then + return "do not run".

        4. Return "run".

        From 6488451b48eaeef1d5b2a2c0f84b0377320f179c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:24:27 +0100 Subject: [PATCH 04/27] Editorial: create CSS/JSON modules with realm --- source | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source b/source index 4ea0a96e190..44a14a7c50f 100644 --- a/source +++ b/source @@ -107393,12 +107393,14 @@ document.querySelector("button").addEventListener("click", bound);
      6. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to the result of creating a CSS module script given sourceText and - settingsObject.

      7. + settingsObject's realm.

      8. If mimeType is a JSON MIME type and moduleType is "json", then set moduleScript to the result of creating a JSON module script given sourceText and - settingsObject.

      9. + settingsObject's realm.

      @@ -107631,14 +107633,14 @@ document.querySelector("button").addEventListener("click", bound); and multi-instantiation. WASMESM

      To create a CSS module script, given a - string source and an environment settings object settings:

      + string source and a realm realm:

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

      2. Set script's realm to - settings's realm.

      3. + realm.

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

      5. @@ -107671,14 +107673,14 @@ document.querySelector("button").addEventListener("click", bound);

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

      + string source and a realm realm:

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

      2. Set script's realm to - settings's realm.

      3. + realm.

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

      5. From 56aaeda963283f104569b8d8fdc487e59b70d363 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:42:23 +0100 Subject: [PATCH 05/27] Editorial: create JS modules with realm --- source | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source b/source index 44a14a7c50f..0c70296a016 100644 --- a/source +++ b/source @@ -106996,7 +106996,8 @@ document.querySelector("button").addEventListener("click", bound);
      6. Disallow further import maps given settingsObject.

      7. Let script be the result of creating a JavaScript module script - using sourceText, settingsObject, baseURL, and + using sourceText, settingsObject's + realm, baseURL, and options.

      8. Fetch the descendants of @@ -107387,8 +107388,9 @@ document.querySelector("button").addEventListener("click", bound);

      9. 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, - settingsObject, response's URL, and options.

      10. + settingsObjects realm, + response's URL, and + options.

      11. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to @@ -107520,20 +107522,19 @@ 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:

      + given a string source, a realm realm, + a URL baseURL, and a script fetch options + options:

      1. If scripting is disabled for - settings's realm, then set - source to the empty string.

      2. + realm, then set source to the empty string.

      3. Let script be a new module script that this algorithm will subsequently initialize.

      4. Set script's realm to - settings's realm.

      5. + realm.

      6. Set script's base URL to baseURL.

      7. @@ -107546,8 +107547,7 @@ document.querySelector("button").addEventListener("click", bound);
      8. Let result be ParseModule(source, - settings's realm, - script).

        + realm, script).

        Passing script as the last parameter here ensures result.[[HostDefined]] will be script.

        From 75677818503e4e29acb0fc53caba16cb38955e13 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 20 Sep 2024 14:32:43 +0200 Subject: [PATCH 06/27] Editorial: create WebAssembly modules with realm --- source | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/source b/source index 0c70296a016..fb6f1392d96 100644 --- a/source +++ b/source @@ -107376,8 +107376,9 @@ document.querySelector("button").addEventListener("click", bound); "application/wasm" and moduleType is "javascript-or-wasm", then set moduleScript to the result of creating a WebAssembly module script given bodyBytes, - settingsObject, response's URL, and options.

      9. + settingsObject's realm, + response's URL, and + options.

      10. Otherwise:

        @@ -107571,14 +107572,13 @@ 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:

      + given a byte sequence bodyBytes, a realm realm, + a URL baseURL, and a script fetch options + options:

      1. -

        If scripting is disabled for - settings's realm, +

        If scripting is disabled for realm, then set bodyBytes to the byte sequence 0x00 0x61 0x73 0x6d 0x01 0x00 0x00 0x00.

        This byte sequence corresponds to an empty WebAssembly module with only the magic @@ -107589,7 +107589,7 @@ document.querySelector("button").addEventListener("click", bound); subsequently initialize.

      2. Set script's realm to - settings's realm.

      3. + realm.

      4. Set script's base URL to baseURL.

      5. @@ -107602,8 +107602,7 @@ document.querySelector("button").addEventListener("click", bound);
      6. Let result be the result of parsing a - WebAssembly module given bodyBytes, - settings's realm, and + WebAssembly module given bodyBytes, realm, and script.

        Passing script as the last parameter here ensures From c3cad2cb99c2847b26b3b8cc669dc12d6de0f725 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 20 Nov 2023 17:12:23 +0100 Subject: [PATCH 07/27] Editorial: pass a realm to Disallow further import maps --- source | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/source b/source index fb6f1392d96..6e5beca0631 100644 --- a/source +++ b/source @@ -106935,7 +106935,8 @@ document.querySelector("button").addEventListener("click", bound); accepting null (on failure) or a module script (on success).

          -
        1. Disallow further import maps given settingsObject.

        2. +
        3. Disallow further import maps given settingsObject's + realm.

        4. Fetch a single module script given url, settingsObject, @@ -106961,7 +106962,8 @@ document.querySelector("button").addEventListener("click", bound); script (on success).

            -
          1. Disallow further import maps given settingsObject.

          2. +
          3. Disallow further import maps given settingsObject's + realm.

          4. Fetch a single module script given url, settingsObject, @@ -106993,7 +106995,8 @@ document.querySelector("button").addEventListener("click", bound); algorithm accepting null (on failure) or a module script (on success).

              -
            1. Disallow further import maps given settingsObject.

            2. +
            3. Disallow further import maps given settingsObject's + realm.

            4. Let script be the result of creating a JavaScript module script using sourceText, settingsObject's @@ -108890,12 +108893,11 @@ dictionary PromiseRejectionEventInit : EventInitEach Window has an import maps allowed boolean, initially true.

              -

              To disallow further import maps given an environment settings object - settingsObject:

              +

              To disallow further import maps given a realm realm:

                -
              1. Let global be settingsObject's global object.

              2. +
              3. Let global be realm's global object.

              4. If global does not implement Window, then return.

              5. @@ -109990,7 +109992,8 @@ import "https://example.com/foo/../module2.mjs";
            5. -
            6. Disallow further import maps given settingsObject.

            7. +
            8. Disallow further import maps given settingsObject's + realm.

            9. Let url be the result of resolving a module specifier given referencingScript and From 62af1fba6d16b5ccac17a3f9bc7c6ae3a18349ca Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 10:57:17 +0100 Subject: [PATCH 08/27] Editorial: pass a realm to 'creating a classic script' --- source | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/source b/source index 6e5beca0631..99a04e9ebd8 100644 --- a/source +++ b/source @@ -62819,8 +62819,8 @@ document.body.append(script1, script2);

              1. Let script be the result of creating a classic script using - source text, settings object, base URL, and - options.

              2. + source text, settings object's realm, base URL, and options.

              3. Mark as ready el given script.

              @@ -99535,8 +99535,9 @@ location.href = '#foo';
            10. Let baseURL be settings's API base URL.

            11. Let script be the result of creating a classic script given - scriptSource, settings, baseURL, and the default script - fetch options.

            12. + scriptSource, settings's realm, baseURL, and the default script fetch + options.

            13. Let evaluationStatus be the result of running the classic script script.

            14. @@ -106759,9 +106760,9 @@ document.querySelector("button").addEventListener("click", bound); CORS-cross-origin, and false otherwise.

            15. Let script be the result of creating a classic script given - sourceText, settingsObject, response's URL, options, - mutedErrors, and url.

            16. + sourceText, settingsObject's realm, response's URL, + options, mutedErrors, and url.

            17. Run onComplete given script.
            @@ -106840,9 +106841,9 @@ document.querySelector("button").addEventListener("click", bound); decoding bodyBytes.

          5. Let script be the result of creating a classic script using - sourceText, settingsObject, response's URL, and the default script fetch - options.

          6. + sourceText, settingsObject's realm, response's URL, and + the default script fetch options.

          7. Run onComplete given script.

          @@ -106921,9 +106922,9 @@ document.querySelector("button").addEventListener("click", bound); CORS-cross-origin, and false otherwise.

        5. Let script be the result of creating a classic script given - sourceText, settingsObject, response's URL, the default script fetch options, and - mutedErrors.

        6. + sourceText, settingsObject's realm, response's URL, the + default script fetch options, and mutedErrors.

        7. Return script.

        @@ -107458,9 +107459,9 @@ document.querySelector("button").addEventListener("click", bound);
        Creating scripts

        To create a classic script, given a - string source, an environment settings object - settings, a URL baseURL, a script fetch options - options, an optional boolean mutedErrors (default false), and an optional + string source, a realm realm, + a URL baseURL, a script fetch options options, + an optional boolean mutedErrors (default false), and an optional URL-or-null sourceURLForWindowScripts (default null):

          @@ -107475,14 +107476,13 @@ document.querySelector("button").addEventListener("click", bound);
        1. If scripting is disabled for - settings's realm, then set - source to the empty string.

        2. + realm, then set source to the empty string.

        3. Let script be a new classic script that this algorithm will subsequently initialize.

        4. Set script's realm to - settings's realm.

        5. + realm.

        6. Set script's base URL to baseURL.

        7. @@ -107500,8 +107500,7 @@ document.querySelector("button").addEventListener("click", bound);
        8. Let result be ParseScript(source, - settings's realm, - script).

          + realm, script).

          Passing script as the last parameter here ensures result.[[HostDefined]] will be script.

          @@ -114093,7 +114092,7 @@ enum DOMParserSupportedType {
        9. Let script be the result of creating a classic script given - handler, settings object, base URL, and fetch + handler, realm, base URL, and fetch options.

        10. Run the classic script From e9d665bf31212156d5224e994f746cd643ced768 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 16:39:35 +0200 Subject: [PATCH 09/27] Editorial: use realms in check if we can run script --- source | 59 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/source b/source index 99a04e9ebd8..85c0cfa161f 100644 --- a/source +++ b/source @@ -107767,15 +107767,16 @@ document.querySelector("button").addEventListener("click", bound); and an optional boolean rethrow errors (default false):

            -
          1. Let settings be the settings - object of script.

          2. +
          3. Let realm be the realm of + script.

          4. -
          5. Check if we can run script with settings. If this returns "do +

          6. Check if we can run script with realm. If this returns "do not run" then return NormalCompletion(empty).

          7. Record classic script execution start time given script.

          8. -
          9. Prepare to run script given settings.

          10. +
          11. Prepare to run script given realm's environment settings object.

          12. Let evaluationStatus be null.

          13. @@ -107804,7 +107805,8 @@ document.querySelector("button").addEventListener("click", bound); errors is false, then:

              -
            1. Clean up after running script with settings.

            2. +
            3. Clean up after running script with realm's environment settings object.

            4. Rethrow evaluationStatus.[[Value]].

            @@ -107814,7 +107816,8 @@ document.querySelector("button").addEventListener("click", bound); errors is true, then:

              -
            1. Clean up after running script with settings.

            2. +
            3. Clean up after running script with realm's environment settings object.

            4. Throw a "NetworkError" DOMException.

            @@ -107828,7 +107831,8 @@ document.querySelector("button").addEventListener("click", bound); script's settings object's global object.

            -
          14. Clean up after running script with settings.

          15. +
          16. Clean up after running script with realm's environment settings object.

          17. Return evaluationStatus.

          @@ -107836,7 +107840,8 @@ document.querySelector("button").addEventListener("click", bound);
      7. -
      8. Clean up after running script with settings.

      9. +
      10. Clean up after running script with realm's environment settings object.

      11. If evaluationStatus is a normal completion, then return evaluationStatus.

      12. @@ -107852,15 +107857,16 @@ document.querySelector("button").addEventListener("click", bound); and an optional boolean preventErrorReporting (default false):

          -
        1. Let settings be the settings - object of script.

        2. +
        3. Let realm be the realm of + script.

        4. -
        5. Check if we can run script with settings. If this returns "do not - run", then return a promise resolved with undefined.

        6. +
        7. Check if we can run script with realm. If this returns "do not + run", then return a promise resolved with with undefined.

        8. Record module script execution start time given script.

        9. -
        10. Prepare to run script given settings.

        11. +
        12. Prepare to run script given realm's environment settings object.

        13. Let evaluationPromise be null.

        14. @@ -107895,22 +107901,22 @@ document.querySelector("button").addEventListener("click", bound); reason for script's settings object's global object.

          -
        15. Clean up after running script with settings.

        16. +
        17. Clean up after running script with realm's environment settings object.

        18. Return evaluationPromise.

        -

        The steps to check if we can run script with an environment settings - object settings are as follows. They return either "run" or "do not run".

        +

        The steps to check if we can run script with a realm realm + are as follows. They return either "run" or "do not run".

          -
        1. If the global object specified by - settings is a Window object whose Document object is not +

        2. If the global object specified by + realm is a Window object whose Document object is not fully active, then return "do not run".

        3. If scripting is disabled for - settings's realm, then - return "do not run".

          + realm, then return "do not run".

        4. Return "run".

        @@ -109433,14 +109439,14 @@ dictionary PromiseRejectionEventInit : EventInit
      13. Let entry be - finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object.

      14. + finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]].

      15. Check if we can run script with entry. If this returns "do not run", then return.

      16. -

        Prepare to run script with entry.

        +

        Prepare to run script with entry's environment settings object.

        This affects the entry concept while the cleanup callback runs.

        @@ -109449,7 +109455,8 @@ dictionary PromiseRejectionEventInit : EventInit

        Let result be the result of performing CleanupFinalizationRegistry(finalizationRegistry).

      17. -
      18. Clean up after running script with entry.

      19. +
      20. Clean up after running script with entry's environment settings object.

      21. If result is an abrupt completion, then report an exception given by result.[[Value]] for @@ -109516,8 +109523,8 @@ dictionary PromiseRejectionEventInit : EventInitQueue a microtask to perform the following steps:

          -
        1. If job settings is not null, then check if we can run script - with job settings. If this returns "do not run" then return.

        2. +
        3. If realm is not null, then check if we can run script with + realm. If this returns "do not run" then return.

        4. If job settings is not null, then prepare to run script with From 5bf7ff8975366ef1ffdbaf2b8a18ed042a01bacd Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 26 Sep 2024 13:37:28 +0200 Subject: [PATCH 10/27] Editorial: don't go through the settings object to report an exception in 'run a classic/module script' --- source | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source b/source index 85c0cfa161f..916ad859937 100644 --- a/source +++ b/source @@ -107828,8 +107828,7 @@ document.querySelector("button").addEventListener("click", bound);

          1. Report an exception given by evaluationStatus.[[Value]] for - script's settings object's - global object.

          2. + realm's global object.

          3. Clean up after running script with realm's environment settings object.

          4. @@ -107898,8 +107897,8 @@ document.querySelector("button").addEventListener("click", bound);
          5. If preventErrorReporting is false, then upon rejection of evaluationPromise with reason, report an exception given by - reason for script's settings - object's global object.

          6. + reason for realm's + global object.

          7. Clean up after running script with realm's environment settings object.

          8. From 7b7b904c00d5f89f68cc884068eab2dedf20f4ed Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 16:32:43 +0200 Subject: [PATCH 11/27] Editorial: use realms in prepare to run script/clean up after running script --- source | 131 +++++++++++++++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 68 deletions(-) diff --git a/source b/source index 916ad859937..2f5d8201fa5 100644 --- a/source +++ b/source @@ -92544,8 +92544,8 @@ enum NavigationHistoryBehavior {
          9. -

            Prepare to run script given navigation's relevant settings - object.

            +

            Prepare to run script given navigation's relevant realm.

            See the discussion for other navigation API events to understand why we do this.

            @@ -92569,8 +92569,8 @@ enum NavigationHistoryBehavior {
        5. -
        6. Clean up after running script given navigation's relevant - settings object.

        7. +
        8. Clean up after running script given navigation's relevant realm.

        In implementations, same-document navigations can cause is same document is true.

      22. -

        Prepare to run script given navigation's relevant settings - object.

        +

        Prepare to run script given navigation's relevant realm.

        This is done to avoid the JavaScript execution context stack becoming empty @@ -95259,8 +95259,8 @@ interface NavigationDestination { apiMethodTracker.

      23. -

        Clean up after running script given navigation's relevant - settings object.

        +

        Clean up after running script given navigation's relevant realm.

        Per the previous note, this stops suppressing any potential promise handler microtasks, causing them to run @@ -103304,12 +103304,12 @@ location.href = '#foo';

        1. Prepare to run script given document's - relevant settings object.

        2. + relevant realm.

        3. Activate transition.

        4. Clean up after running script given document's - relevant settings object.

        5. + relevant realm.

        Activating a view transition might resolve/reject promises, so by wrapping the @@ -105752,6 +105752,11 @@ new PaymentRequest(…); // Allowed to use

      24. Return realm execution context.

      +

      The execution context of a + realm realm is the realm execution context of the + environment settings object of + realm.

      +

      When defining algorithm steps throughout this specification, it is often important to indicate @@ -107775,8 +107780,7 @@ document.querySelector("button").addEventListener("click", bound);

    42. Record classic script execution start time given script.

    43. -
    44. Prepare to run script given realm's environment settings object.

    45. +
    46. Prepare to run script given realm.

    47. Let evaluationStatus be null.

    48. @@ -107805,8 +107809,7 @@ document.querySelector("button").addEventListener("click", bound); errors is false, then:

        -
      1. Clean up after running script with realm's environment settings object.

      2. +
      3. Clean up after running script with realm.

      4. Rethrow evaluationStatus.[[Value]].

      @@ -107816,8 +107819,7 @@ document.querySelector("button").addEventListener("click", bound); errors is true, then:

        -
      1. Clean up after running script with realm's environment settings object.

      2. +
      3. Clean up after running script with realm.

      4. Throw a "NetworkError" DOMException.

      @@ -107830,8 +107832,7 @@ document.querySelector("button").addEventListener("click", bound);
    49. Report an exception given by evaluationStatus.[[Value]] for realm's global object.

    50. -
    51. Clean up after running script with realm's environment settings object.

    52. +
    53. Clean up after running script with realm.

    54. Return evaluationStatus.

    @@ -107839,8 +107840,7 @@ document.querySelector("button").addEventListener("click", bound);
  • -
  • Clean up after running script with realm's environment settings object.

  • +
  • Clean up after running script with realm.

  • If evaluationStatus is a normal completion, then return evaluationStatus.

  • @@ -107864,8 +107864,7 @@ document.querySelector("button").addEventListener("click", bound);
  • Record module script execution start time given script.

  • -
  • Prepare to run script given realm's environment settings object.

  • +
  • Prepare to run script given realm.

  • Let evaluationPromise be null.

  • @@ -107900,8 +107899,7 @@ document.querySelector("button").addEventListener("click", bound); reason for realm's global object.

    -
  • Clean up after running script with realm's environment settings object.

  • +
  • Clean up after running script with realm.

  • Return evaluationPromise.

  • @@ -107920,28 +107918,32 @@ document.querySelector("button").addEventListener("click", bound);
  • Return "run".

  • -

    The steps to prepare to run script with an environment settings - object settings are as follows:

    +

    The steps to prepare to run script with a realm realm + are as follows:

      -
    1. Push settings's realm execution context onto the JavaScript - execution context stack; it is now the running JavaScript execution - context.

    2. +
    3. Push realm's execution + context onto the JavaScript execution context stack; it is now the + running JavaScript execution context.

    4. + +
    5. Let settings be realm's settings object.

    6. Add settings to the surrounding agent's event loop's currently running task's script evaluation environment settings object set.

    -

    The steps to clean up after running script with an environment settings - object settings are as follows:

    +

    The steps to clean up after running script with a realm + realm are as follows:

      -
    1. Assert: settings's realm execution context is the +

    2. Assert: realm's execution context is the running JavaScript execution context.

    3. -
    4. Remove settings's realm execution context from the - JavaScript execution context stack.

    5. +
    6. Remove realm's execution + context from the JavaScript execution context stack.

    7. If the JavaScript execution context stack is now empty, perform a microtask checkpoint. (If this runs scripts, these algorithms will be invoked @@ -109444,8 +109446,7 @@ dictionary PromiseRejectionEventInit : EventInit

    8. -

      Prepare to run script with entry's environment settings object.

      +

      Prepare to run script with entry.

      This affects the entry concept while the cleanup callback runs.

      @@ -109454,8 +109455,7 @@ dictionary PromiseRejectionEventInit : EventInit

      Let result be the result of performing CleanupFinalizationRegistry(finalizationRegistry).

    9. -
    10. Clean up after running script with entry's environment settings object.

    11. +
    12. Clean up after running script with entry.

    13. If result is an abrupt completion, then report an exception given by result.[[Value]] for @@ -109492,32 +109492,6 @@ dictionary PromiseRejectionEventInit : EventInitJAVASCRIPT

        -
      1. -

        If realm is not null, then let job settings be the settings object for realm. Otherwise, - let job settings be null.

        - -
        -

        If realm is not null, it is the realm of the author code that will - run. When job is returned by NewPromiseReactionJob, it is the realm of - the promise's handler function. When job is returned by - NewPromiseResolveThenableJob, it is the realm of the then - function. - -

        If realm is null, either no author code will run or author code is guaranteed to - throw. For the former, the author may not have passed in code to run, such as in promise.then(null, null). For the latter, it is because a revoked Proxy was - passed. In both cases, all the steps below that would otherwise use job settings - get skipped.

        - -

        NewPromiseResolveThenableJob - and NewPromiseReactionJob - both seem to provide non-null realms (the current Realm Record) in the case of a revoked - proxy. The previous text could be updated to reflect that.

        -
        -
      2. -
      3. Queue a microtask to perform the following steps:

        @@ -109526,8 +109500,8 @@ dictionary PromiseRejectionEventInit : EventInitrealm. If this returns "do not run" then return.

      4. -

        If job settings is not null, then prepare to run script with - job settings.

        +

        If realm is not null, then prepare to run script with + realm.

        This affects the entry concept while the job runs.

        @@ -109546,8 +109520,8 @@ dictionary PromiseRejectionEventInit : EventInitHostMakeJobCallback and restores them in HostCallJobCallback.

      5. -
      6. If job settings is not null, then clean up after running script - with job settings.

      7. +
      8. If realm is not null, then clean up after running script + with realm.

      9. If result is an abrupt completion, then @@ -109568,6 +109542,27 @@ dictionary PromiseRejectionEventInit : EventInit

      +
      +

      If realm is not null, it is the realm of the author code that will + run. When job is returned by NewPromiseReactionJob, it is the realm of + the promise's handler function. When job is returned by + NewPromiseResolveThenableJob, it is the realm of the then + function. + +

      If realm is null, either no author code will run or author code is guaranteed to + throw. For the former, the author may not have passed in code to run, such as in promise.then(null, null). For the latter, it is because a revoked Proxy was + passed. In both cases, all the steps below that would otherwise use realm + get skipped.

      + +

      NewPromiseResolveThenableJob + and NewPromiseReactionJob + both seem to provide non-null realms (the current Realm Record) in the case of a revoked + proxy. The previous text could be updated to reflect that.

      +
      + +
      HostEnqueueTimeoutJob(job, realm, milliseconds)
      From 8ef4d76086ca6889369ccf5eca765cb066523c45 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 17:09:19 +0200 Subject: [PATCH 12/27] Editorial: use realms around 'incumbent' --- source | 154 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/source b/source index 2f5d8201fa5..a1f6bf19bfd 100644 --- a/source +++ b/source @@ -105950,23 +105950,23 @@ new PaymentRequest(…); // Allowed to use callback">cleaning up after running a callback, this value will be incremented and decremented.

      -

      Every event loop has an associated backup incumbent settings object - stack, initially empty. Roughly speaking, it is used to determine the incumbent - settings object when no author code is on the stack, but author code is responsible for the - current algorithm having been run in some way. The process of preparing to run a callback and cleaning up after running a callback manipulate this stack. WEBIDL

      +

      Every event loop has an associated backup incumbent realm stack, + initially empty. Roughly speaking, it is used to determine the incumbent realm when no author code is on the stack, but + author code is responsible for the current algorithm having been run in some way. + The process of preparing to run a callback and + cleaning up after running a callback + manipulate this stack. WEBIDL

      When Web IDL is used to invoke author code, or when HostEnqueuePromiseJob invokes a promise job, they use the following - algorithms to track relevant data for determining the incumbent settings object:

      + algorithms to track relevant data for determining the incumbent realm:

      -

      To prepare to run a callback with an environment settings object - settings:

      +

      To prepare to run a callback with a realm realm:

        -
      1. Push settings onto the backup incumbent settings object - stack.

      2. +
      3. Push realm onto the backup incumbent realm stack.

      4. Let context be the topmost script-having execution context.

      5. @@ -105975,8 +105975,8 @@ new PaymentRequest(…); // Allowed to use skip-when-determining-incumbent counter.

      -

      To clean up after running a callback with an environment settings - object settings:

      +

      To clean up after running a callback with a realm + realm:

      1. @@ -105990,19 +105990,18 @@ new PaymentRequest(…); // Allowed to use
      2. If context is not null, decrement context's skip-when-determining-incumbent counter.

      3. -
      4. Assert: the topmost entry of the backup incumbent settings object - stack is settings.

      5. +
      6. Assert: the topmost entry of the backup incumbent realm stack is + realm.

      7. -
      8. Remove settings from the backup incumbent settings object - stack.

      9. +
      10. Remove realm from the backup incumbent realm stack.

      Here, the topmost script-having execution context is the topmost entry of the JavaScript execution context stack that has a non-null ScriptOrModule component, or null if there is no such entry in the JavaScript execution context stack.

      -

      With all this in place, the incumbent settings object is determined as - follows:

      +

      With all this in place, the incumbent realm + is determined as follows:

      1. Let context be the topmost script-having execution @@ -106014,31 +106013,29 @@ new PaymentRequest(…); // Allowed to use

        1. -

          Assert: the backup incumbent settings object stack is not - empty.

          - -

          This assert would fail if you try to obtain the incumbent settings - object from inside an algorithm that was triggered neither by calling scripts nor by Web IDL invoking a callback. For example, it would - trigger if you tried to obtain the incumbent settings object inside an algorithm - that ran periodically as part of the event loop, with no involvement of author - code. In such cases the incumbent concept - cannot be used.

          +

          Assert: the backup incumbent realm stack is not empty.

          + +

          This assert would fail if you try to obtain the incumbent realm from inside an algorithm that was + triggered neither by calling scripts nor by Web IDL invoking a callback. + For example, it would trigger if you tried to obtain the incumbent realm inside an algorithm that ran + periodically as part of the event loop, with no involvement of author code. + In such cases the incumbent concept cannot + be used.

        2. -
        3. Return the topmost entry of the backup incumbent settings object - stack.

        4. +
        5. Return the topmost entry of the backup incumbent realm stack.

      2. -
      3. Return context's Realm component's settings object.

      4. +
      5. Return context's Realm component.

      -

      Then, the incumbent realm is the realm of the incumbent settings - object.

      +

      Then, the incumbent settings object is the + incumbent realm's + settings object.

      Similarly, the incumbent global object is the global object of the incumbent @@ -106058,10 +106055,10 @@ new PaymentRequest(…); // Allowed to use frames[0].postMessage("some data", "*"); </script> -

      There are two interesting environment settings - objects here: that of window, and that of frames[0]. Our concern is: what is the incumbent settings object at - the time that the algorithm for postMessage() +

      There are two interesting realms here: that of + window, and that of frames[0]. + Our concern is: what is the incumbent realm at the + time that the algorithm for postMessage() executes?

      It should be that of window, to capture the intuitive notion that the @@ -106111,15 +106108,15 @@ new PaymentRequest(…); // Allowed to use

      This time, the result involves more complicated mechanisms:

      When bound is converted to a - Web IDL callback type, the incumbent settings object is that corresponding to window (in the same manner as in our starter example above). Web IDL stores this - as the resulting callback value's callback context.

      + Web IDL callback type, the incumbent realm is that + corresponding to window (in the same manner as in our starter example + above). Web IDL stores this as the resulting callback value's callback context.

      When the task posted by setTimeout() executes, the algorithm for that task uses Web IDL to invoke the stored callback value. Web IDL in turn calls the above prepare to run a callback algorithm. This pushes the stored - callback context onto the backup incumbent settings object stack. At + callback context onto the backup incumbent realm stack. At this time (inside the timer task) there is no author code on the stack, so the topmost script-having execution context is null, and nothing gets its skip-when-determining-incumbent counter incremented.

      @@ -106134,11 +106131,12 @@ new PaymentRequest(…); // Allowed to use data-x="dom-window-postMessage">postMessage(), with no ScriptEvaluation context or similar below it.

      -

      This is where we fall back to the backup incumbent settings object stack. As - noted above, it will contain as its topmost entry the relevant settings object of - window. So that is what is used as the incumbent settings - object while executing the postMessage() - algorithm.

      +

      This is where we fall back to the backup incumbent realm stack. + As noted above, it will contain as its topmost entry the relevant realm of window. + So its settings object is what is used as the + incumbent settings object while executing the postMessage() algorithm.

      @@ -106163,21 +106161,21 @@ document.querySelector("button").addEventListener("click", bound); }; </script> -

      Again there are two interesting environment - settings objects in play: that of a.html, and that of b.html. When the location.assign() - method triggers the Location-object navigate algorithm, what will be - the incumbent settings object? As before, it should intuitively be that of a.html: the click listener was originally - scheduled by a.html, so even if something involving b.html causes the listener to fire, the incumbent responsible is that of a.html.

      +

      Again there are two interesting realms in play: that of + a.html, and that of b.html. + When the location.assign() method triggers the + Location-object navigate algorithm, what will be the incumbent realm? + As before, it should intuitively be that of a.html: the click listener was originally scheduled by a.html, so even if something involving b.html causes the + listener to fire, the incumbent responsible is + that of a.html.

      The callback setup is similar to the previous example: when bound is - converted to a Web IDL callback type, the - incumbent settings object is that corresponding to a.html, - which is stored as the callback's callback context.

      + converted to a Web IDL callback type, the incumbent realm is that corresponding to a.html, which is stored as the callback's callback context.

      When the click() method is called inside b.html, it dispatches a is author code on the stack; the topmost script-having execution context is that of the onLoad function, whose skip-when-determining-incumbent counter gets incremented. Additionally, a.html's environment settings object (stored as the - EventHandler's callback context) is pushed onto the - backup incumbent settings object stack.

      + data-x="">a.html's realm (stored as the EventHandler's + callback context) is pushed onto the backup incumbent realm stack.

      Now, when the Location-object navigate algorithm looks up the - incumbent settings object, the topmost script-having execution - context is still that of the onLoad function (due to the fact we - are using a bound function as the callback). Its skip-when-determining-incumbent - counter value is one, however, so we fall back to the backup incumbent settings - object stack. This gives us the environment settings object of a.html, as expected.

      + incumbent global object, the topmost + script-having execution context is still that of the onLoad + function (due to the fact we are using a bound function as the callback). + Its skip-when-determining-incumbent counter value is one, however, so we fall back + to the backup incumbent realm stack. + This gives us the realm of a.html, as expected.

      Note that this means that even though it is the iframe inside a.html that navigates, it is a.html itself that is used @@ -109374,14 +109371,14 @@ dictionary PromiseRejectionEventInit : EventInitJAVASCRIPT

        -
      1. Let incumbent settings be - callback.[[HostDefined]].[[IncumbentSettings]].

      2. +
      3. Let incumbent realm be + callback.[[HostDefined]].[[IncumbentRealm]].

      4. Let script execution context be callback.[[HostDefined]].[[ActiveScriptContext]].

      5. -

        Prepare to run a callback with incumbent settings.

        +

        Prepare to run a callback with incumbent realm.

        This affects the incumbent concept while the callback runs.

        @@ -109402,8 +109399,7 @@ dictionary PromiseRejectionEventInit : EventInitpop script execution context from the JavaScript execution context stack.

      6. -
      7. Clean up after running a callback with incumbent - settings.

      8. +
      9. Clean up after running a callback with incumbent realm.

      10. Return result.

      @@ -109593,7 +109589,7 @@ dictionary PromiseRejectionEventInit : EventInitJAVASCRIPT

        -
      1. Let incumbent settings be the incumbent settings object.

      2. +
      3. Let incumbent realm be the incumbent realm.

      4. Let active script be the active script.

      5. @@ -109645,7 +109641,7 @@ dictionary PromiseRejectionEventInit : EventInit
      6. Return the JobCallback Record { [[Callback]]: callable, - [[HostDefined]]: { [[IncumbentSettings]]: incumbent settings, [[ActiveScriptContext]]: + [[HostDefined]]: { [[IncumbentRealm]]: incumbent realm, [[ActiveScriptContext]]: script execution context } }.

      From 8e8b12226b03b0893fa52d1f3b46c8e649230a5e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 26 Sep 2024 14:59:46 +0200 Subject: [PATCH 13/27] Editorial: use realm in HostPromiseRejectionTracker --- source | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source b/source index a1f6bf19bfd..a9012e5b304 100644 --- a/source +++ b/source @@ -109285,14 +109285,13 @@ dictionary PromiseRejectionEventInit : EventInit

      If script is a classic script and script's muted errors is true, then return.

    14. -
    15. Let settingsObject be the current settings object.

    16. +
    17. Let realm be the current realm.

    18. -
    19. If script is not null, then set settingsObject to - script's settings - object.

    20. +
    21. If script is not null, then set realm to script's + realm.

    22. -
    23. Let global be settingsObject's global object.

    24. +
    25. Let global be realm's + global object.

    26. If operation is "reject", then:

      From 061e5e51e036c86250f99abe54bf8ecae5b3fb87 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 17:54:42 +0200 Subject: [PATCH 14/27] JavaScript ShadowRealm proposal integration This patch gives the TC39 JavaScript ShadowRealm proposal semantics in HTML. ShadowRealms are given an environment settings object; in general, ShadowRealms inherit their settings from the outer environment. When modules are used in ShadowRealms, module specifiers are interpreted with respect to the base URL of the surrounding environment, but when a module is imported within a ShadowRealm, it is a separate copy from what may be loaded in the surrounding environment or other ShadowRealms. This patch implements the plan described earlier at . The ShadowRealm proposal is currently at Stage 2. Once this PR has been approved, it should be able to advance to Stage 3. --- source | 640 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 503 insertions(+), 137 deletions(-) diff --git a/source b/source index a9012e5b304..70398c96996 100644 --- a/source +++ b/source @@ -2856,6 +2856,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    27. frozen array and creating a frozen array
    28. create a new object implementing the interface
    29. +
    30. define the global property references
    31. callback this value
    32. converting between Web IDL types and JS types
    33. invoking and @@ -3065,6 +3066,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    34. The RunJobs abstract operation
    35. The SameValue abstract operation
    36. The ScriptEvaluation abstract operation
    37. +
    38. The SetDefaultGlobalBindings abstract operation
    39. The SetImmutablePrototype abstract operation
    40. The ToBoolean abstract operation
    41. The ToString abstract operation
    42. @@ -3142,6 +3144,16 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    43. The nsMaxInstant and nsMinInstant values
    44. + +

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

      + +
      WebAssembly
      @@ -3453,6 +3465,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    45. current wall time
    46. Unix epoch
    47. DOMHighResTimeStamp
    48. +
    49. Performance
    50. @@ -9601,7 +9614,7 @@ interface DOMStringList {
      1. -

        If the current settings object's If the current principal settings object's cross-origin isolated capability is false, then throw a "DataCloneError" DOMException.

        @@ -11924,7 +11937,7 @@ console.assert(el.constructor === Element); overridden constructor steps:

          -
        1. Let registry be the current global object's +

        2. Let registry be the current principal global object's CustomElementRegistry object.

        3. @@ -12026,11 +12039,11 @@ document.createElement("bad-1"); // (2)
          1. Let element be the result of internally creating a new object implementing the interface - to which the active function object corresponds, given the current + to which the active function object corresponds, given the current principal realm and NewTarget.

          2. -
          3. Set element's node document to the current global - object's associated +

          4. Set element's node document to the current principal + global object's associated Document.

          5. Set element's namespace to @@ -29775,7 +29788,7 @@ img.decode().then(() => { the legacy factory function must perform the following steps:

              -
            1. Let document be the current global object's

              Let document be the current principal global object's associated Document.

            2. Let img be the result of creating an @@ -35311,7 +35324,7 @@ interface HTMLAudioElement : HTMLMediaElement must perform the following steps:

                -
              1. Let document be the current global object's

                Let document be the current principal global object's associated Document.

              2. Let audio be the result of creating an @@ -54301,7 +54314,7 @@ interface HTMLOptionElement : HTMLElement { function must perform the following steps:

                  -
                1. Let document be the current global object's

                  Let document be the current principal global object's associated Document.

                2. Let option be the result of creating an @@ -88937,7 +88950,7 @@ dictionary DragEventInit : MouseEventInit {

                  IsPlatformObjectSameOrigin ( O )
                    -
                  1. Return true if the current settings object's

                    Return true if the current principal settings object's origin is same origin-domain with O's relevant settings object's origin, and false otherwise.

                  2. @@ -88945,13 +88958,13 @@ dictionary DragEventInit : MouseEventInit {

                    This abstract operation does not return a Completion Record.

                    -

                    Here the current settings object roughly corresponds to the "caller", - because this check occurs before the execution - context for the getter/setter/method in question makes its way onto the JavaScript - execution context stack. For example, in the code w.document, this - step is invoked before the document getter is reached as part - of the [[Get]] algorithm for the WindowProxy - w.

                    +

                    Here the current principal settings object roughly corresponds to the + "caller", because this check occurs before the execution context for the getter/setter/method in question makes its way onto the + JavaScript execution context stack. For example, in the code w.document, this step is invoked before the document getter is reached as part of the [[Get]] algorithm for the WindowProxy w.

                    CrossOriginGetOwnPropertyHelper ( O, P )
                    @@ -88960,8 +88973,9 @@ dictionary DragEventInit : MouseEventInit { practice this is handled by the caller calling CrossOriginPropertyFallback.

                      -
                    1. Let crossOriginKey be a tuple consisting of the current settings - object, O's relevant settings object, and P.

                    2. +
                    3. Let crossOriginKey be a tuple consisting of the current principal + settings object, O's relevant settings object, and + P.

                    4. For each e of CrossOriginProperties(O):

                      @@ -88987,8 +89001,8 @@ dictionary DragEventInit : MouseEventInit {
                    5. Let value be originalDesc.[[Value]].

                    6. If IsCallable(value) is true, then set value to - an anonymous built-in function, created in the current realm, that performs - the same steps as the IDL operation P on object O.

                    7. + an anonymous built-in function, created in the current principal realm, that + performs the same steps as the IDL operation P on object O.

                    8. Set crossOriginDesc to PropertyDescriptor{ [[Value]]: value, @@ -89005,15 +89019,15 @@ dictionary DragEventInit : MouseEventInit {

                    9. Let crossOriginGet be undefined.

                    10. If e.[[NeedsGet]] is true, then set crossOriginGet to an - anonymous built-in function, created in the current realm, that performs the - same steps as the getter of the IDL attribute P on object + anonymous built-in function, created in the current principal realm, that + performs the same steps as the getter of the IDL attribute P on object O.

                    11. Let crossOriginSet be undefined.

                    12. If e.[[NeedsSet]] is true, then set crossOriginSet to an - anonymous built-in function, created in the current realm, that performs the - same steps as the setter of the IDL attribute P on object + anonymous built-in function, created in the current principal realm, that + performs the same steps as the setter of the IDL attribute P on object O.

                    13. Set crossOriginDesc to PropertyDescriptor{ @@ -90028,7 +90042,7 @@ dictionary WindowPostMessageOptions : StructuredSeri

                    14. If container's node document's origin is not same origin-domain with the - current settings object's current principal settings object's origin, then return null.

                    15. Return container.

                    16. @@ -90467,10 +90481,10 @@ interface BarProp { this.

                    17. Check if an access between two browsing contexts - should be reported, given the current global object's + should be reported, given the current principal global object's browsing context, W's browsing context, P, and the current settings - object.

                    18. + data-x="window bc">browsing context, P, and the current principal + settings object.

                    19. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).

                    20. @@ -90491,9 +90505,10 @@ interface BarProp { this.

                    21. Check if an access between two browsing contexts - should be reported, given the current global object's browsing - context, W's browsing context, P, - and the current settings object.

                    22. + should be reported, given the current principal global object's + browsing context, W's browsing context, P, and the current principal + settings object.

                    23. If IsPlatformObjectSameOrigin(W) is true, then:

                      @@ -105279,8 +105294,8 @@ new PaymentRequest(…); // Allowed to use data-x="concept-relevant-realm">relevant realm's agent.

                      -

                      The agent equivalent of the current realm is the surrounding - agent.

                      +

                      The agent equivalent of the current principal realm is the + surrounding agent.

                      @@ -105499,16 +105514,32 @@ new PaymentRequest(…); // Allowed to use

                      Realms and their counterparts

                      The JavaScript specification introduces the realm concept, representing a global - environment in which script is run. Each realm comes with an implementation-defined - global object; much of this specification is devoted to defining that global object - and its properties.

                      + environment in which script is run.

                      + +

                      In the context of the JavaScript ShadowRealm API proposal, there are two kinds of realms: + JSSHADOWREALM

                      + +
                        +
                      • A principal realm comes with an implementation-defined + global object; much of this specification is devoted to defining that global object + and its properties.

                      • + +
                      • A synthetic realm is created by the ShadowRealm API and includes a reduced set + of properties.

                      • +

                      For web specifications, it is often useful to associate values or algorithms with a - realm/global object pair. When the values are specific to a particular type of realm, they are - associated directly with the global object in question, e.g., in the definition of the + principal realm/global object pair. When the values are specific to a particular type of realm, + they are associated directly with the global object in question, e.g., in the definition of the Window or WorkerGlobalScope interfaces. When the values have utility across multiple realms, we use the environment settings object concept.

                      +

                      Each synthetic realm originates from a principal realm + (its settings object's + principal realm). + Generally, in contexts where the associated values or algorithms of a realm are needed, + the associated values and algorithms of this associated principal realm are used.

                      +

                      Finally, in some cases it is necessary to track associated values before a realm/global object/environment settings object even comes into existence (for example, during navigation). These values are tracked in the @@ -105655,8 +105686,17 @@ new PaymentRequest(…); // Allowed to use

                      A global object is a JavaScript object that is the [[GlobalObject]] field of a realm.

                      -

                      In this specification, all realms are created with global +

                      A realm's global object is found in its [[GlobalObject]] field. A global + object's realm is the unique + realm whose global object is that object.

                      + +

                      A principal global object is a global object of a principal + realm. Similarly, a synthetic global object is a global object of a + synthetic realm.

                      + +

                      In this specification, all principal realms + are created with global objects that are either Window, WorkerGlobalScope, or WorkletGlobalScope objects.

                      @@ -105674,27 +105714,26 @@ new PaymentRequest(…); // Allowed to use
                      -

                      There is always a 1-to-1-to-1 mapping between realms, global objects, and environment settings objects:

                      +

                      There is always a 1-to-1-to-1 mapping between principal + realms, principal global objects, and environment settings objects:

                        -
                      • A realm has a [[HostDefined]] field, which contains the realm's - settings object.

                      • +
                      • A principal realm has a [[HostDefined]] field, which contains the + principal realm's settings object.

                      • -
                      • A realm has a [[GlobalObject]] field, which contains the realm's global - object.

                      • +
                      • A principal realm has a global + object.

                      • -
                      • Each global object in this specification is created during the creation of a corresponding realm, known as - the global - object's realm.

                      • +
                      • Each principal global object in this specification is created during the + creation of a corresponding principal + realm, which is the global object's + realm.

                      • -
                      • Each global object in this - specification is created alongside a corresponding environment settings object, - known as its relevant settings object.

                        +
                      • Each principal global object + in this specification is created alongside a corresponding environment settings + object, known as its relevant settings object.

                      • An environment settings object's realm execution context's Realm component is

                        Return realm execution context.

                    +
                    Synthetic realm settings objects
                    + +

                    Each synthetic realm has an associated synthetic realm settings object + with the following fields:

                    + +
                    +

                    An execution context

                    + +

                    The JavaScript execution context for the scripts within this realm.

                    + +

                    A principal realm

                    + +

                    The principal realm which this synthetic realm exists within.

                    + +

                    An underlying realm

                    + +

                    The synthetic realm which this settings object represents.

                    + +

                    A module map

                    + +
                    +

                    A module map that is used when importing JavaScript modules.

                    + +

                    Synthetic realm settings objects' module map entries are copies of successfully + fetched modules found in the principal realm's module map, so this map never contains entries + which are null or "fetching".

                    +
                    +
                    + +

                    Synthetic realms are created with global objects which are initialized by the JavaScript specification's + SetDefaultGlobalBindings algorithm. Synthetic + global objects implement only certain specifically exposed interfaces.

                    + +

                    Analogously, there is always a 1-to-1-to-1 mapping between synthetic realms, synthetic global + objects, and synthetic realm settings + objects:

                    + +
                      +
                    • A synthetic realm has a [[HostDefined]] field, which contains the synthetic realm's settings + object.

                    • + +
                    • A synthetic realm has a global + object.

                    • + +
                    • Each synthetic global object in this specification is created as part of the + ShadowRealm constructor, which creates the global object's realm.

                    • + +
                    • Each synthetic global object in this specification is created alongside a + corresponding synthetic realm settings object, known as its relevant synthetic + realm settings object.

                    • + +
                    • A synthetic realm settings object's realm execution context's + Realm component is the synthetic realm settings object's realm.

                    • + +
                    • A synthetic realm settings object's synthetic realm settings object's global object is its + realm's + global.

                    • +
                    + +

                    The principal realm of any + realm realm is defined by the following algorithm:

                    + +
                      +
                    1. +

                      If realm.[[HostDefined]] is a synthetic realm settings object, + then:

                      + +
                        +
                      1. Assert: realm is a synthetic realm.

                      2. + +
                      3. Set realm to the principal realm of + realm.[[HostDefined]].

                      4. +
                      +
                    2. + +
                    3. Assert: realm.[[HostDefined]] is an environment settings + object and realm is a principal realm.

                    4. + +
                    5. Return realm.

                    6. +
                    +

                    The execution context of a - realm realm is the realm execution context of the - environment settings object of - realm.

                    + realm realm is defined by the following algorithm:

                    + +
                      +
                    1. If realm is a principal realm, then return the + realm execution context of the + environment settings object of + realm.

                    2. + +
                    3. Assert: realm is a synthetic realm.

                    4. + +
                    5. Return the execution context + of the synthetic realm settings + object of realm.

                    6. +
                    + +

                    The module map of a realm + realm is defined by the following algorithm:

                    + +
                      +
                    1. If realm is a principal realm, then return the module map of the + environment settings object of + realm.

                    2. + +
                    3. Assert: realm is a synthetic realm.

                    4. + +
                    5. Return the module map + of the synthetic realm settings + object of realm.

                    6. +

                    When defining algorithm steps throughout this specification, it is often important to indicate - what realm is to be used—or, equivalently, what global object or - environment settings object is to be used. In general, there are at least four - possibilities:

                    + what principal realm is to be used—or, equivalently, what principal global + object or environment settings object is to be used. In general, there are at + least four possibilities:

                    Entry
                    @@ -105854,9 +106014,9 @@ new PaymentRequest(…); // Allowed to use data-x="">a.html.

                  3. The incumbent realm is that of b.html.

                  4. -
                  5. The current realm is that of c.html (since it is the - print() method from c.html whose code is - running).

                  6. +
                  7. The current principal realm is that of c.html (since it is the print() method from + c.html whose code is running).

                  8. The relevant realm of the object on which the print() method is being called is that of d.html.

                  9. @@ -105902,13 +106062,13 @@ new PaymentRequest(…); // Allowed to use </script>

                    If the algorithm for the getBattery() method - had instead used the current realm, all the results would be reversed. That is, - after the first call to getBattery() in outer.html, the Navigator object in current principal realm, all the results would be reversed. + That is, after the first call to getBattery() in + outer.html, the Navigator object in inner.html would be permanently storing a Promise object created in outer.html's realm, and calls like that inside the - hello() function would thus return a promise from the "wrong" realm. Since - this is undesirable, the algorithm instead uses the hello() function would thus return a promise from the "wrong" realm. + Since this is undesirable, the algorithm instead uses the relevant realm, giving the sensible results indicated in the comments above.

                    @@ -105931,7 +106091,8 @@ new PaymentRequest(…); // Allowed to use

                    With this in hand, we define the entry execution context to be the most recently pushed item in the JavaScript execution context stack that is a realm execution context. The entry - realm is the entry execution context's Realm component.

                    + realm is the principal realm of the + entry execution context's Realm component.

                    Then, the entry settings object is the environment settings object of the Then, the incumbent settings object is the incumbent realm's + principal realm's settings object.

                    Similarly, the incumbent global object is @@ -106211,12 +106373,23 @@ document.querySelector("button").addEventListener("click", bound);

                    The JavaScript specification defines the current realm, also known as the "current Realm Record". JAVASCRIPT

                    -

                    Then, the current settings object is the environment settings object of the current +

                    The current principal realm is the principal realm of the current realm.

                    -

                    Similarly, the current global object is the global object of the current realm.

                    +

                    Note that the current realm, unlike the entry, incumbent and + relevant concepts, can refer to a synthetic realm. Almost all uses of the "current" + concept in this document and other Web specifications need to refer to the current principal + realm as well. One exception is JavaScript module processing, as synthetic realms have a separate set of module instances (derived from a common + module map across the shared environment settings object).

                    + +

                    Then, the current principal settings object is the environment settings object of the current + principal realm.

                    + +

                    Similarly, the current principal global object is the global object of the current principal realm.

                    Relevant
                    @@ -106341,7 +106514,10 @@ document.querySelector("button").addEventListener("click", bound);
                    A realm

                    A realm where the script is evaluated, which is shared with other - scripts in the same context.

                    + scripts in the same context. Note that, in the case of + module scripts (but not classic scripts), this realm can be a synthetic + realm.

                    A record
                    @@ -106411,7 +106587,8 @@ document.querySelector("button").addEventListener("click", bound);

                    The settings object of a script is the - settings object of the script's + settings object of the + principal realm of the script's realm.

                    A classic script is a type of script @@ -106943,7 +107120,8 @@ document.querySelector("button").addEventListener("click", bound);

                  10. Fetch a single module script given url, settingsObject, - "script", options, settingsObject, "script", options, settingsObject's + realm, "client", true, and with the following steps given result:

                      @@ -106970,7 +107148,8 @@ document.querySelector("button").addEventListener("click", bound);
                    1. Fetch a single module script given url, settingsObject, - destination, options, settingsObject, "destination, options, settingsObject's + realm, "client", true, and with the following steps given result:

                        @@ -107171,7 +107350,8 @@ document.querySelector("button").addEventListener("click", bound);
                      1. Fetch a single module script given url, - fetchClient, destination, options, settingsObject, + fetchClient, destination, options, settingsObject's + realm, "client", true, and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.

                        @@ -107270,10 +107450,10 @@ document.querySelector("button").addEventListener("click", bound);

                        To fetch a single module script, given a URL url, an environment settings object fetchClient, a destination destination, a script - fetch options options, an environment settings object - settingsObject, a referrer - referrer, an optional ModuleRequest Record moduleRequest, a - boolean isTopLevel, an algorithm + fetch options options, a realm moduleMapRealm, + a referrer referrer, + an optional ModuleRequest Record moduleRequest, + a boolean isTopLevel, an algorithm onComplete, and an optional perform the fetch hook performFetch, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

                        @@ -107286,14 +107466,14 @@ document.querySelector("button").addEventListener("click", bound); moduleRequest.

                      2. Assert: the result of running the module type allowed steps - given moduleType and settingsObject's realm is true. Otherwise, we would not have reached this point because a - failure would have been raised when inspecting moduleRequest.[[Attributes]] in + given moduleType and moduleMapRealm is true. + Otherwise, we would not have reached this point because a failure would have been raised when + inspecting moduleRequest.[[Attributes]] in HostLoadImportedModule or fetch a single imported module script.

                      3. -
                      4. Let moduleMap be settingsObject's module map.

                      5. +
                      6. Let moduleMap be moduleMapRealm's module map.

                      7. If moduleMap[(url, moduleType)] is "fetching", wait in parallel until that entry's value @@ -107304,6 +107484,23 @@ document.querySelector("button").addEventListener("click", bound); data-x="map exists">exists, run onComplete given moduleMap[(url, moduleType)], and return.

                      8. +
                      9. +

                        If moduleMapRealm is a synthetic realm, then:

                        + +
                          +
                        1. Let script be the result of + cloning a module + given url, moduleType and moduleMapRealm.

                        2. + +
                        3. Set moduleMap[(url, + moduleType)] to script.

                        4. + +
                        5. Run onComplete given script.

                        6. + +
                        7. Return.

                        8. +
                        +
                      10. +
                      11. Set moduleMap[(url, moduleType)] to "fetching".

                      12. @@ -107382,9 +107579,8 @@ document.querySelector("button").addEventListener("click", bound); "application/wasm" and moduleType is "javascript-or-wasm", then set moduleScript to the result of creating a WebAssembly module script given bodyBytes, - settingsObject's realm, - response's URL, and - options.

                        + moduleMapRealm, response's + URL, and options.

                      13. Otherwise:

                        @@ -107395,21 +107591,18 @@ document.querySelector("button").addEventListener("click", bound);
                      14. 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, - settingsObjects realm, - response's URL, and - options.

                      15. + moduleMapRealm, response's URL, and options.

                      16. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to the result of creating a CSS module script given sourceText and - settingsObject's realm.

                      17. + moduleMapRealm.

                      18. If mimeType is a JSON MIME type and moduleType is "json", then set moduleScript to the result of creating a JSON module script given sourceText and - settingsObject's realm.

                      19. + moduleMapRealm.

                    2. @@ -107428,13 +107621,92 @@ document.querySelector("button").addEventListener("click", bound);
                    +

                    To clone a module given a URL, moduleType, and + moduleMapRealm, perform the following steps.

                    + +
                      +
                    1. Assert: moduleMapRealm is a synthetic realm.

                    2. + +
                    3. Let parentModuleMap be moduleMapRealm's + principal realm's settings object's module map.

                    4. + +
                    5. Assert: parentModuleMap[(url, moduleType)] + exists.

                    6. + +
                    7. Let parentModule be parentModuleMap[(url, + moduleType)].

                    8. + +
                    9. Let childModule be a new module script that this algorithm will + subsequently initialize.

                    10. + +
                    11. Set childModule's realm to + moduleMapRealm.

                    12. + +
                    13. Set childModule's base URL to + parentModule's base URL.

                    14. + +
                    15. Set childModule's fetch + options to parentModule's fetch options.

                    16. + +
                    17. Set childModule's error to + rethrow to parentModule's error + to rethrow.

                      Should this be cloned? Can this be an arbitrary + value?
                    18. + +
                    19. Let parentRecord be parentModule's record.

                    20. + +
                    21. +

                      If parentRecord is null, then:

                      + +
                        +
                      1. Let parentParseError be parentModule's parse error.

                      2. +
                      3. Assert: parentParseError is a SyntaxError + instance.

                      4. + +
                      5. Set childModule's parse + error to a new SyntaxError in moduleMapRealm with the same + message as parentParseError.

                      6. + +
                      7. Set childModule's record to + null.

                      8. + +
                      9. Return childModule.

                      10. +
                      +
                    22. + +
                    23. Set childModule's error to + rethrow to null.

                    24. + +
                    25. Can parentModule be a CSS or JSON module?

                    26. + +
                    27. Set childModule's record to + a new Source Text Module Record { [[Realm]]: moduleMapRealm, + [[Environment]]: undefined, [[Namespace]]: undefined, [[Status]]: unlinked, [[EvaluationError]]: + undefined, [[HostDefined]]: childModule, [[ECMAScriptCode]]: + parentRecord.[[ECMAScriptCode]], [[Context]]: empty, [[ImportMeta]]: empty, + [[RequestedModules]]: parentRecord.[[RequestedModules]], + [[ImportEntries]]: parentRecord.[[ImportEntries]], + [[LocalExportEntries]]: parentRecord.[[LocalImportEntries]], + [[IndirectExportEntries]]: parentRecord.[[IndirectImportEntries]], + [[StarExportEntries]]: parentRecord.[[StarImportEntries]], [[DFSIndex]]: undefined, + [[DFSAncestorIndex]]: undefined }. Is 'unlinked' correct?

                    28. + +
                    29. Return childModule.

                    30. +
                    + +

                    To fetch a single imported module script, given a URL url, an environment settings object fetchClient, a destination destination, a script - fetch options options, environment settings object - settingsObject, a referrer - referrer, a ModuleRequest Record moduleRequest, an - algorithm onComplete, and an optional options, a realm moduleMapRealm, + a referrer referrer, + a ModuleRequest Record moduleRequest, + an algorithm onComplete, and an optional perform the fetch hook performFetch, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

                    @@ -107449,11 +107721,11 @@ document.querySelector("button").addEventListener("click", bound); request steps given moduleRequest.

                  11. If the result of running the module type allowed steps given - moduleType and settingsObject's realm is false, then run onComplete given null, and return.

                  12. + moduleType and moduleMapRealm is false, then + run onComplete given null, and return.

                  13. Fetch a single module script given url, fetchClient, - destination, options, settingsObject, referrer, + destination, options, moduleMapRealm, referrer, moduleRequest, false, and onComplete. If performFetch was given, pass it along as well.

                  @@ -107923,12 +108195,18 @@ document.querySelector("button").addEventListener("click", bound); context onto the JavaScript execution context stack; it is now the running JavaScript execution context.

                3. -
                4. Let settings be realm's settings object.

                5. +
                6. +

                  If realm is a principal realm, then:

                  + +
                    +
                  1. Let settings be realm's settings object.

                  2. -
                  3. Add settings to the surrounding agent's event loop's currently running task's - script evaluation environment settings object set.

                  4. +
                  5. Add settings to the surrounding agent's event loop's currently running task's + script evaluation environment settings object set.

                  6. +
                  +

                The steps to clean up after running script with a realm @@ -108399,9 +108677,10 @@ dictionary PromiseRejectionEventInit : EventInitOtherwise:

                  -
                1. Assert: there is a current settings object.

                2. +
                3. Assert: there is a current principal settings object.

                4. -
                5. Set settingsObject to the current settings object.

                6. +
                7. Set settingsObject to the current principal settings + object.

                8. Set baseURL to settingsObject's API base URL.

                9. @@ -109588,7 +109867,8 @@ dictionary PromiseRejectionEventInit : EventInitJAVASCRIPT

                    -
                  1. Let incumbent realm be the incumbent realm.

                  2. +
                  3. Let incumbent realm be the incumbent + realm.

                  4. Let active script be the active script.

                  5. @@ -109635,7 +109915,7 @@ dictionary PromiseRejectionEventInit : EventInitAs a consequence, this means that when the import() expression is evaluated, there will still be no active script. Fortunately that is handled by our implementation of HostLoadImportedModule by falling back to using the - current settings object's API base URL.

                    + current principal settings object's API base URL.

                    @@ -109850,11 +110130,18 @@ import "https://example.com/foo/../module2.mjs";
                    must use the following implementation: JAVASCRIPT

                      -
                    1. Let settingsObject be the current settings object.

                    2. +
                    3. +

                      Let moduleMapRealm be the current realm.

                      + +

                      In the case of the ShadowRealm.prototype.importValue API the + current realm is set to the appropriate synthetic realm.

                      +
                    4. -

                      If settingsObject's global - object implements WorkletGlobalScope or ServiceWorkerGlobalScope +

                      If moduleMapRealm's principal + realm's (can we check moduleMapRealm directly?) + global object implements + WorkletGlobalScope or ServiceWorkerGlobalScope and loadState is undefined, then:

                      loadState is undefined when the current fetching process has been @@ -109886,14 +110173,20 @@ import "https://example.com/foo/../module2.mjs";

                      1. Set referencingScript to referrer.[[HostDefined]].

                        -
                      2. Set settingsObject to referencingScript's settings object.

                      3. -
                      4. Set fetchReferrer to referencingScript's base URL.

                      5. Set originalFetchOptions to referencingScript's fetch options.

                      6. + +
                      7. +

                        Set moduleMapRealm to referencing script's realm

                        + +

                        In the case of a dynamic import nested within a module loaded through the + ShadowRealm.prototype.importValue API, the realm of the script is set to the + appropriate synthetic realm.

                        +
                      @@ -109962,8 +110255,7 @@ import "https://example.com/foo/../module2.mjs";
                    5. If the result of running the module type allowed steps given - moduleType and settingsObject's realm is false, then:

                      + moduleType and moduleMapRealm is false, then:

                      1. Let completion be Completion Record { [[Type]]: throw, @@ -109987,8 +110279,7 @@ import "https://example.com/foo/../module2.mjs";

                    6. -
                    7. Disallow further import maps given settingsObject's - realm.

                    8. +
                    9. Disallow further import maps given moduleMapRealm.

                    10. Let url be the result of resolving a module specifier given referencingScript and @@ -110009,6 +110300,10 @@ import "https://example.com/foo/../module2.mjs";

                    +
                  6. Let settingsObject be moduleMapRealm's + principal realm's + settings object.

                  7. +
                  8. Let fetchOptions be the result of getting the descendant script fetch options given originalFetchOptions, url, and settingsObject.

                  9. @@ -110030,7 +110325,7 @@ import "https://example.com/foo/../module2.mjs";
                  10. Fetch a single imported module script given url, fetchClient, destination, fetchOptions, - settingsObject, fetchReferrer, moduleRequest, and + moduleMapRealm, fetchReferrer, moduleRequest, and onSingleFetchComplete as defined below. If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.

                    @@ -110071,6 +110366,71 @@ import "https://example.com/foo/../module2.mjs";
                  +
                  HostInitializeShadowRealm(realm)
                  + +

                  JavaScript contains an implementation-defined HostInitializeShadowRealm(realm) + abstract operation. User agents must use the following implementation: + JSSHADOWREALM

                  + +
                    +
                  1. Let settings be a new synthetic realm settings object that this + algorithm will subsequently initialize.

                  2. + +
                  3. Set settings's principal realm to the + current principal realm.

                  4. + +
                  5. Set settings's underlying realm to + realm.

                  6. + +
                  7. Set settings's module + map to a new module map, initially empty.

                  8. + +
                  9. Set realm.[[HostDefined]] to settings.

                  10. + +
                  11. Define the global property references on realm.[[GlobalObject]], + given realm.

                  12. + +
                  13. +

                    Let selfSteps be the following series of steps:

                    + +
                      +
                    1. Let thisValue be the result of getting the ShadowRealm global object with realm and the this + value.

                    2. +
                    3. Return thisValue.

                    4. +
                    +
                  14. + +
                  15. Let selfGetter be CreateBuiltinFunction(selfSteps, 0, + "get self", « », realm).

                  16. + +
                  17. Let selfDescriptor be the PropertyDescriptor{[[Get]]: + selfGetter, [[Set]]: undefined, [[Enumerable]]: true, [[Configurable]]: + true}.

                  18. + +
                  19. Perform ! DefinePropertyOrThrow(realm.[[GlobalObject]], "self", + selfDescriptor).

                  20. +
                  + + To get the ShadowRealm global object given calleeRealm and + thisValue, perform the following steps: + +
                    +
                  1. Assert: calleeRealm is a synthetic realm

                  2. +
                  3. If thisValue is null or undefined, return + calleeRealm.[[GlobalObject]].

                  4. +
                  5. If Type(thisValue) is not Object, then throw a + TypeError.

                  6. +
                  7. If thisValue is not a global object, then throw a + TypeError.

                  8. +
                  9. Assert: thisValue is + calleeRealm.[[GlobalObject]].

                  10. +
                  11. Return thisValue.

                  12. +
                  +

                  Event loops

                  @@ -111129,7 +111489,7 @@ import "https://example.com/foo/../module2.mjs"; goal is met. This means running the following steps:

                    -
                  1. Let global be the current global object.

                  2. +
                  3. Let global be the current principal global object.

                  4. Let timeBeforePause be the current high resolution time given global.

                  5. @@ -111302,7 +111662,7 @@ import "https://example.com/foo/../module2.mjs";
                    1. Let parsed be the result of encoding-parsing a URL given - string, relative to the current settings object.

                    2. + string, relative to the current principal settings object.

                    3. If parsed is failure, then return a promise rejected with a "SyntaxError" DOMException.

                    4. @@ -111314,7 +111674,7 @@ import "https://example.com/foo/../module2.mjs";
                    -
                  6. Let realm be the current realm.

                  7. +
                  8. Let realm be the current principal realm.

                  9. Let p be a new promise.

                  10. @@ -111363,15 +111723,15 @@ import "https://example.com/foo/../module2.mjs";
                    • It does its URL parsing up front, on the event loop, before going to the in parallel steps. This is necessary, since parsing depends on the current - settings object, which would no longer be current after going in + principal settings object, which would no longer be current after going in parallel.

                    • -
                    • Alternately, it could have saved a reference to the current settings +

                    • Alternately, it could have saved a reference to the current principal settings object's API base URL and used it during the in parallel steps; that would have been equivalent. However, we recommend instead doing as much work as possible up front, as this example does. Attempting to save the correct values can be error prone; for - example, if we'd saved just the current settings object, instead of its API - base URL, there would have been a potential race.

                    • + example, if we'd saved just the current principal settings object, instead of its + API base URL, there would have been a potential race.

                    • It implicitly passes a list of strings from the initial steps to the in parallel steps. This is OK, as both OnBeforeUnloadEventHandlerNonNull? OnBeforeUnl

                      In practice, this only affects the resolution of relative URLs via import(), which consult the base URL of the associated script. Nulling out [[ScriptOrModule]] means that HostLoadImportedModule will - fall back to the current settings object's API base URL.

                      + fall back to the current principal settings object's + API base URL.

                    • @@ -119872,7 +120233,7 @@ enum WorkerType { "classic", "module" }; object, scriptURL, "Worker constructor", and "script".

                      -
                    • Let outside settings be the current settings object.

                      +
                    • Let outside settings be the current principal settings object.

                    • Let worker URL be the result of encoding-parsing a URL given @@ -119973,7 +120334,8 @@ interface SharedWorker : EventTarget { data-x="">name member is set to the value of options and whose other members are set to their default values.

                    • -
                    • Let outside settings be the current settings object.

                    • +
                    • Let outside settings be the current principal settings + object.

                    • Let urlRecord be the result of encoding-parsing a URL given @@ -120193,7 +120555,8 @@ interface SharedWorker : EventTarget { data-x="concept-WorkerGlobalScope-type">type is "module", throw a TypeError exception.

                    • -
                    • Let settings object be the current settings object.

                    • +
                    • Let settings object be the current principal settings + object.

                    • If urls is empty, return.

                    • @@ -143680,6 +144043,9 @@ INSERT INTERFACES HERE
                      [JSON]
                      The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
                      +
                      [JSSHADOWREALM]
                      +
                      ShadowRealm API. Ecma International.
                      +
                      [JSTEMPORAL]
                      Temporal. Ecma International.
                      From a379dbdf492b104a8356e7166d71258053e54be7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:04:31 +0100 Subject: [PATCH 15/27] Fetch modules directly for ShadowRealms This avoids issues with ShadowRealms importing modules that the principal realm hasn't cached (yet). --- source | 115 ++++----------------------------------------------------- 1 file changed, 7 insertions(+), 108 deletions(-) diff --git a/source b/source index 70398c96996..4814fd1b564 100644 --- a/source +++ b/source @@ -105815,13 +105815,7 @@ new PaymentRequest(…); // Allowed to use

                      A module map

                      -
                      -

                      A module map that is used when importing JavaScript modules.

                      - -

                      Synthetic realm settings objects' module map entries are copies of successfully - fetched modules found in the principal realm's module map, so this map never contains entries - which are null or "fetching".

                      -
                      +

                      A module map that is used when importing JavaScript modules.

                      Synthetic realms are created with exists, run onComplete given moduleMap[(url, moduleType)], and return.

                      -
                    • -

                      If moduleMapRealm is a synthetic realm, then:

                      - -
                        -
                      1. Let script be the result of - cloning a module - given url, moduleType and moduleMapRealm.

                      2. - -
                      3. Set moduleMap[(url, - moduleType)] to script.

                      4. - -
                      5. Run onComplete given script.

                      6. - -
                      7. Return.

                      8. -
                      -
                    • -
                    • Set moduleMap[(url, moduleType)] to "fetching".

                    • @@ -107621,85 +107598,6 @@ document.querySelector("button").addEventListener("click", bound);
                  -

                  To clone a module given a URL, moduleType, and - moduleMapRealm, perform the following steps.

                  - -
                    -
                  1. Assert: moduleMapRealm is a synthetic realm.

                  2. - -
                  3. Let parentModuleMap be moduleMapRealm's - principal realm's settings object's module map.

                  4. - -
                  5. Assert: parentModuleMap[(url, moduleType)] - exists.

                  6. - -
                  7. Let parentModule be parentModuleMap[(url, - moduleType)].

                  8. - -
                  9. Let childModule be a new module script that this algorithm will - subsequently initialize.

                  10. - -
                  11. Set childModule's realm to - moduleMapRealm.

                  12. - -
                  13. Set childModule's base URL to - parentModule's base URL.

                  14. - -
                  15. Set childModule's fetch - options to parentModule's fetch options.

                  16. - -
                  17. Set childModule's error to - rethrow to parentModule's error - to rethrow.

                    Should this be cloned? Can this be an arbitrary - value?
                  18. - -
                  19. Let parentRecord be parentModule's record.

                  20. - -
                  21. -

                    If parentRecord is null, then:

                    - -
                      -
                    1. Let parentParseError be parentModule's parse error.

                    2. -
                    3. Assert: parentParseError is a SyntaxError - instance.

                    4. - -
                    5. Set childModule's parse - error to a new SyntaxError in moduleMapRealm with the same - message as parentParseError.

                    6. - -
                    7. Set childModule's record to - null.

                    8. - -
                    9. Return childModule.

                    10. -
                    -
                  22. - -
                  23. Set childModule's error to - rethrow to null.

                  24. - -
                  25. Can parentModule be a CSS or JSON module?

                  26. - -
                  27. Set childModule's record to - a new Source Text Module Record { [[Realm]]: moduleMapRealm, - [[Environment]]: undefined, [[Namespace]]: undefined, [[Status]]: unlinked, [[EvaluationError]]: - undefined, [[HostDefined]]: childModule, [[ECMAScriptCode]]: - parentRecord.[[ECMAScriptCode]], [[Context]]: empty, [[ImportMeta]]: empty, - [[RequestedModules]]: parentRecord.[[RequestedModules]], - [[ImportEntries]]: parentRecord.[[ImportEntries]], - [[LocalExportEntries]]: parentRecord.[[LocalImportEntries]], - [[IndirectExportEntries]]: parentRecord.[[IndirectImportEntries]], - [[StarExportEntries]]: parentRecord.[[StarImportEntries]], [[DFSIndex]]: undefined, - [[DFSAncestorIndex]]: undefined }. Is 'unlinked' correct?

                  28. - -
                  29. Return childModule.

                  30. -
                  - -

                  To fetch a single imported module script, given a URL url, an environment settings object fetchClient, a destination destination, a script @@ -110139,8 +110037,7 @@ import "https://example.com/foo/../module2.mjs";

                10. If moduleMapRealm's principal - realm's (can we check moduleMapRealm directly?) - global object implements + realm's global object implements WorkletGlobalScope or ServiceWorkerGlobalScope and loadState is undefined, then:

                  @@ -110180,8 +110077,8 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-script-script-fetch-options">fetch options.

                11. -

                  Set moduleMapRealm to referencing script's realm

                  +

                  Set moduleMapRealm to referencingScript's realm.

                  In the case of a dynamic import nested within a module loaded through the ShadowRealm.prototype.importValue API, the realm of the script is set to the @@ -110310,7 +110207,9 @@ import "https://example.com/foo/../module2.mjs";

                12. Let destination be "script".

                13. -
                14. Let fetchClient be settingsObject.

                15. +
                16. Let fetchClient be moduleMapRealm's + principal realm's + settings object.

                17. If loadState is not undefined, then:

                  From da2c8fd9578584f91006242d2a93d8cc32199f58 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 13 Dec 2023 10:05:44 +0100 Subject: [PATCH 16/27] Start defining ShadowRealmGlobalObject --- source | 82 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/source b/source index 4814fd1b564..a144d38490c 100644 --- a/source +++ b/source @@ -2856,7 +2856,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
                18. frozen array and creating a frozen array
                19. create a new object implementing the interface
                20. -
                21. define the global property references
                22. callback this value
                23. converting between Web IDL types and JS types
                24. invoking and @@ -3037,6 +3036,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
                25. The HostMakeJobCallback abstract operation
                26. The HostPromiseRejectionTracker abstract operation
                27. The InitializeHostDefinedRealm abstract operation
                28. +
                29. The SetRealmGlobalObject abstract operation
                30. The IsAccessorDescriptor abstract operation
                31. The IsCallable abstract operation
                32. The IsConstructor abstract operation
                33. @@ -3150,7 +3150,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute JSSHADOWREALM

                    -
                  • The HostInitializeShadowRealm abstract operation
                  • +
                  • The HostInitializeShadowRealm abstract operation
                  • The ShadowRealm constructor
                  • The ShadowRealm.prototype.importValue method
                  @@ -110265,6 +110265,34 @@ import "https://example.com/foo/../module2.mjs";
                +
                The ShadowRealmGlobalObject interface
                + +

                Move this!

                + +
                [Global]
                +interface ShadowRealmGlobalObject : EventTarget {
                +  readonly attribute ShadowRealmGlobalObject self;
                +};
                + +

                The self getter steps are to return + this.

                + +

                The [[SetPrototypeOf]] internal method of a platform object O that + implements ShadowRealmGlobalObject, when called with ECMAScript language + value V, must perform the following step:

                + +
                  +
                1. Return OrdinarySetPrototypeOf(O, V).

                2. +
                + +

                This overrides the [[SetPrototypeOf]] + section in WebIDL. WEBIDL

                + +

                Do EventTarget.prototype and + ShadowRealmGlobalObject.prototype need a similar change?

                +
                HostInitializeShadowRealm(realm)

                JavaScript contains an implementation-defined JSSHADOWREALM

                  +
                1. Let globalObject be a new ShadowRealmGlobalObject + object with realm.

                2. + +
                3. Perform SetRealmGlobalObject(realm, + globalObject, undefined). (Should this use + InitializeHostDefinedRealm?)

                4. + +
                5. Perform ? SetDefaultGlobalBindings(realm).

                6. +
                7. Let settings be a new synthetic realm settings object that this algorithm will subsequently initialize.

                8. @@ -110289,45 +110327,7 @@ import "https://example.com/foo/../module2.mjs";
                9. Set realm.[[HostDefined]] to settings.

                10. -
                11. Define the global property references on realm.[[GlobalObject]], - given realm.

                12. - -
                13. -

                  Let selfSteps be the following series of steps:

                  - -
                    -
                  1. Let thisValue be the result of getting the ShadowRealm global object with realm and the this - value.

                  2. -
                  3. Return thisValue.

                  4. -
                  -
                14. - -
                15. Let selfGetter be CreateBuiltinFunction(selfSteps, 0, - "get self", « », realm).

                16. - -
                17. Let selfDescriptor be the PropertyDescriptor{[[Get]]: - selfGetter, [[Set]]: undefined, [[Enumerable]]: true, [[Configurable]]: - true}.

                18. - -
                19. Perform ! DefinePropertyOrThrow(realm.[[GlobalObject]], "self", - selfDescriptor).

                20. -
                - - To get the ShadowRealm global object given calleeRealm and - thisValue, perform the following steps: - -
                  -
                1. Assert: calleeRealm is a synthetic realm

                2. -
                3. If thisValue is null or undefined, return - calleeRealm.[[GlobalObject]].

                4. -
                5. If Type(thisValue) is not Object, then throw a - TypeError.

                6. -
                7. If thisValue is not a global object, then throw a - TypeError.

                8. -
                9. Assert: thisValue is - calleeRealm.[[GlobalObject]].

                10. -
                11. Return thisValue.

                12. +
                13. Return unused.

                From 0c40ecb5d4523549c697e372e32468003112dff6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 15 Dec 2023 15:32:04 +0100 Subject: [PATCH 17/27] Add link --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index a144d38490c..9038c06bcf6 100644 --- a/source +++ b/source @@ -110290,8 +110290,9 @@ interface ShadowRealmGlobalObject : EventTarget[[SetPrototypeOf]] section in WebIDL. WEBIDL

                -

                Do EventTarget.prototype and - ShadowRealmGlobalObject.prototype need a similar change?

                +

                TODO: override step 8 of "create an interface + prototype object.

                HostInitializeShadowRealm(realm)
                From 01f7e45dfdeb141e572e86d60e6ba5b4f60ee0a1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 18 Jan 2024 15:52:44 +0100 Subject: [PATCH 18/27] Review --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index 9038c06bcf6..63928604dce 100644 --- a/source +++ b/source @@ -110031,8 +110031,9 @@ import "https://example.com/foo/../module2.mjs";
              3. Let moduleMapRealm be the current realm.

                -

                In the case of the ShadowRealm.prototype.importValue API the - current realm is set to the appropriate synthetic realm.

                +

                In the case of the ShadowRealm.prototype.importValue API both the + current realm and referrer are set to the corresponding + synthetic realm.

              4. From 7273e1b36e0489086a256ede8ae9b6ef5ea52454 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 20 Dec 2023 17:12:45 +0100 Subject: [PATCH 19/27] Better layering for the mutable global prototype chain --- source | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/source b/source index 63928604dce..4aa48986f52 100644 --- a/source +++ b/source @@ -2868,6 +2868,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
              5. upon rejection
              6. upon fulfillment
              7. mark as handled
              8. +
              9. has a mutable global prototype chain
              10. [Global]
              11. [LegacyFactoryFunction]
              12. [LegacyLenientThis]
              13. @@ -110279,22 +110280,6 @@ interface ShadowRealmGlobalObject : EventTargetself getter steps are to return this.

                -

                The [[SetPrototypeOf]] internal method of a platform object O that - implements ShadowRealmGlobalObject, when called with ECMAScript language - value V, must perform the following step:

                - -
                  -
                1. Return OrdinarySetPrototypeOf(O, V).

                2. -
                - -

                This overrides the [[SetPrototypeOf]] - section in WebIDL. WEBIDL

                - -

                TODO: override step 8 of "create an interface - prototype object.

                -
                HostInitializeShadowRealm(realm)

                JavaScript contains an implementation-defined ShadowRealmGlobalObject : EventTargetJSSHADOWREALM

                  +
                1. Mark realm as having a + mutable global prototype chain.

                  +
                2. Let globalObject be a new ShadowRealmGlobalObject object with realm.

                3. From 04cd64be95887fa18a0de3ade53cb4facf86dd08 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 11 Jan 2024 16:43:27 +0100 Subject: [PATCH 20/27] Rephrase --- source | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source b/source index 4aa48986f52..a702e7c9c65 100644 --- a/source +++ b/source @@ -2868,7 +2868,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
                4. upon rejection
                5. upon fulfillment
                6. mark as handled
                7. -
                8. has a mutable global prototype chain
                9. +
                10. is global prototype chain mutable
                11. [Global]
                12. [LegacyFactoryFunction]
                13. [LegacyLenientThis]
                14. @@ -110288,8 +110288,7 @@ interface ShadowRealmGlobalObject : EventTargetJSSHADOWREALM

                    -
                  1. Mark realm as having a - mutable global prototype chain.

                    +
                  2. Set realm's is global prototype chain mutable to true.

                  3. Let globalObject be a new ShadowRealmGlobalObject object with realm.

                  4. From 3029971f3c9f4c541aebaf8adf7c16339555b4fb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 31 Jan 2024 17:41:56 +0100 Subject: [PATCH 21/27] Add context argument to HostInitializeShadowRealm --- source | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source b/source index a702e7c9c65..a8dfca45d1d 100644 --- a/source +++ b/source @@ -110280,11 +110280,11 @@ interface ShadowRealmGlobalObject : EventTargetself getter steps are to return this.

                    -
                    HostInitializeShadowRealm(realm)
                    +
                    HostInitializeShadowRealm(realm, context)

                    JavaScript contains an implementation-defined HostInitializeShadowRealm(realm) - abstract operation. User agents must use the following implementation: + data-x="js-HostInitializeShadowRealm">HostInitializeShadowRealm(realm, + context) abstract operation. User agents must use the following implementation: JSSHADOWREALM

                      @@ -110303,6 +110303,10 @@ interface ShadowRealmGlobalObject : EventTarget

                      Let settings be a new synthetic realm settings object that this algorithm will subsequently initialize.

                      +
                    1. Set settings's execution context to + context.

                    2. +
                    3. Set settings's principal realm to the current principal realm.

                    4. From 842a6258059ffd2c43bcbfb567e3bf0a997b5dbb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 18 Jan 2024 14:30:56 +0100 Subject: [PATCH 22/27] Rename ShadowRealmGlobalObject --- source | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source b/source index a8dfca45d1d..5c6a6df14cf 100644 --- a/source +++ b/source @@ -110267,17 +110267,17 @@ import "https://example.com/foo/../module2.mjs";
                    -
                    The ShadowRealmGlobalObject interface
                    +
                    The ShadowRealmGlobalScope interface

                    Move this!

                    [Global]
                    -interface ShadowRealmGlobalObject : EventTarget {
                    -  readonly attribute ShadowRealmGlobalObject self;
                    +interface ShadowRealmGlobalScope : EventTarget {
                    +  readonly attribute ShadowRealmGlobalScope self;
                     };
                    -

                    The self getter steps are to return +

                    The self getter steps are to return this.

                    HostInitializeShadowRealm(realm, context)
                    @@ -110290,7 +110290,7 @@ interface ShadowRealmGlobalObject : EventTarget
                  5. Set realm's is global prototype chain mutable to true.

                    -
                  6. Let globalObject be a new ShadowRealmGlobalObject +

                  7. Let globalObject be a new ShadowRealmGlobalScope object with realm.

                  8. Perform Date: Thu, 18 Jan 2024 14:31:22 +0100 Subject: [PATCH 23/27] Add atob, btoa, structuredClone to shadow realms --- source | 150 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 82 insertions(+), 68 deletions(-) diff --git a/source b/source index 5c6a6df14cf..b213fd454cf 100644 --- a/source +++ b/source @@ -10661,7 +10661,7 @@ o.myself = o;

                    -

                    The The structuredClone(value, options) method steps are:

                    @@ -112755,6 +112755,87 @@ interface mixin WindowEventHandlers {
                    +

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin

                    + +

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin is for use of APIs that are to be exposed on + Window and WorkerGlobalScope objects.

                    + +

                    Other standards are encouraged to further extend it using partial + interface mixin WindowOrWorkerOrShadowRealmGlobalScope { … }; along with an + appropriate reference.

                    + +
                    interface mixin WindowOrWorkerOrShadowRealmGlobalScope {
                    +    // base64 utility methods
                    +    DOMString btoa(DOMString data);
                    +    ByteString atob(DOMString data);
                    +
                    +    // structured cloning
                    +    any structuredClone(any value, optional StructuredSerializeOptions options = {});
                    +  };
                    +  Window includes WindowOrWorkerGlobalScope;
                    +  WorkerGlobalScope includes WindowOrWorkerGlobalScope;
                    +  ShadowRealmGlobalScope includes WindowOrWorkerGlobalScope;
                    + +

                    Base64 utility methods

                    + +

                    The atob() and btoa() methods + allow developers to transform content to and from the base64 encoding.

                    + +

                    In these APIs, for mnemonic purposes, the "b" can be considered to stand for + "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the + input and output of these functions are Unicode strings.

                    + +
                    +
                    result = self.btoa(data)
                    + +
                    +

                    Takes the input data, in the form of a Unicode string containing only characters in the range + U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF respectively, and + converts it to its base64 representation, which it returns.

                    + +

                    Throws an "InvalidCharacterError" DOMException + exception if the input string contains any out-of-range characters.

                    +
                    + +
                    result = self.atob(data)
                    + +
                    +

                    Takes the input data, in the form of a Unicode string containing base64-encoded binary data, + decodes it, and returns a string consisting of characters in the range U+0000 to U+00FF, each + representing a binary byte with values 0x00 to 0xFF respectively, corresponding to that binary + data.

                    + +

                    Throws an "InvalidCharacterError" DOMException if the + input string is not valid base64 data.

                    +
                    +
                    + +
                    + +

                    The btoa(data) method must throw an + "InvalidCharacterError" DOMException if data + contains any character whose code point is greater than U+00FF. Otherwise, the user agent must + convert data to a byte sequence whose nth byte is the eight-bit + representation of the nth code point of data, and then must apply + forgiving-base64 encode to that byte sequence and return the result.

                    + +

                    The atob(data) method steps are:

                    + +
                      +
                    1. Let decodedData be the result of running forgiving-base64 decode + on data.

                    2. + +
                    3. If decodedData is failure, then throw an + "InvalidCharacterError" DOMException.

                    4. + +
                    5. Return decodedData.

                    6. +
                    + +
                    + +

                    The WindowOrWorkerGlobalScope mixin

                    The WindowOrWorkerGlobalScope mixin is for use of APIs that are to be exposed on @@ -112773,10 +112854,6 @@ interface mixin WindowOrWorkerGlobalScope { undefined reportError(any e); - // base64 utility methods - DOMString btoa(DOMString data); - ByteString atob(DOMString data); - // timers long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments); undefined clearTimeout(optional long id = 0); @@ -112789,9 +112866,6 @@ interface mixin WindowOrWorkerGlobalScope { // ImageBitmap Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options = {}); Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options = {}); - - // structured cloning - any structuredClone(any value, optional StructuredSerializeOptions options = {}); }; Window includes WindowOrWorkerGlobalScope; WorkerGlobalScope includes WindowOrWorkerGlobalScope; @@ -112850,66 +112924,6 @@ document.body.appendChild(frame) -

                    Base64 utility methods

                    - -

                    The atob() and btoa() methods - allow developers to transform content to and from the base64 encoding.

                    - -

                    In these APIs, for mnemonic purposes, the "b" can be considered to stand for - "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the - input and output of these functions are Unicode strings.

                    - -
                    -
                    result = self.btoa(data)
                    - -
                    -

                    Takes the input data, in the form of a Unicode string containing only characters in the range - U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF respectively, and - converts it to its base64 representation, which it returns.

                    - -

                    Throws an "InvalidCharacterError" DOMException - exception if the input string contains any out-of-range characters.

                    -
                    - -
                    result = self.atob(data)
                    - -
                    -

                    Takes the input data, in the form of a Unicode string containing base64-encoded binary data, - decodes it, and returns a string consisting of characters in the range U+0000 to U+00FF, each - representing a binary byte with values 0x00 to 0xFF respectively, corresponding to that binary - data.

                    - -

                    Throws an "InvalidCharacterError" DOMException if the - input string is not valid base64 data.

                    -
                    -
                    - -
                    - -

                    The btoa(data) method must throw an - "InvalidCharacterError" DOMException if data - contains any character whose code point is greater than U+00FF. Otherwise, the user agent must - convert data to a byte sequence whose nth byte is the eight-bit - representation of the nth code point of data, and then must apply - forgiving-base64 encode to that byte sequence and return the result.

                    - -

                    The atob(data) method steps are:

                    - -
                      -
                    1. Let decodedData be the result of running forgiving-base64 decode - on data.

                    2. - -
                    3. If decodedData is failure, then throw an - "InvalidCharacterError" DOMException.

                    4. - -
                    5. Return decodedData.

                    6. -
                    - -
                    - -

                    Dynamic markup insertion

                    APIs for dynamically inserting markup into the document interact with the parser, From 8b4da8f1c86a04db8566c035bcb3f8efe9ab1936 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 14:09:39 +0100 Subject: [PATCH 24/27] Add queueMicrotask --- source | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source b/source index b213fd454cf..14e2f8c4300 100644 --- a/source +++ b/source @@ -112769,6 +112769,9 @@ interface mixin WindowEventHandlers { DOMString btoa(DOMString data); ByteString atob(DOMString data); + // microtask queuing + undefined queueMicrotask(VoidFunction callback); + // structured cloning any structuredClone(any value, optional StructuredSerializeOptions options = {}); }; @@ -112860,9 +112863,6 @@ interface mixin WindowOrWorkerGlobalScope { long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments); undefined clearInterval(optional long id = 0); - // microtask queuing - undefined queueMicrotask(VoidFunction callback); - // ImageBitmap Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options = {}); Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options = {}); From 48011ad006499cb416eb7e9e7ac68e9f46bf1999 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 14:09:56 +0100 Subject: [PATCH 25/27] Indentation --- source | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/source b/source index 14e2f8c4300..480c5720dbf 100644 --- a/source +++ b/source @@ -112758,26 +112758,26 @@ interface mixin WindowEventHandlers {

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin is for use of APIs that are to be exposed on - Window and WorkerGlobalScope objects.

                    + Window and WorkerGlobalScope objects.

                    -

                    Other standards are encouraged to further extend it using partial - interface mixin WindowOrWorkerOrShadowRealmGlobalScope { … }; along with an - appropriate reference.

                    +

                    Other standards are encouraged to further extend it using partial + interface mixin WindowOrWorkerOrShadowRealmGlobalScope { … }; along with an + appropriate reference.

                    -
                    interface mixin WindowOrWorkerOrShadowRealmGlobalScope {
                    -    // base64 utility methods
                    -    DOMString btoa(DOMString data);
                    -    ByteString atob(DOMString data);
                    +  
                    interface mixin WindowOrWorkerOrShadowRealmGlobalScope {
                    +  // base64 utility methods
                    +  DOMString btoa(DOMString data);
                    +  ByteString atob(DOMString data);
                     
                    -    // microtask queuing
                    -    undefined queueMicrotask(VoidFunction callback);
                    +  // microtask queuing
                    +  undefined queueMicrotask(VoidFunction callback);
                     
                    -    // structured cloning
                    -    any structuredClone(any value, optional StructuredSerializeOptions options = {});
                    -  };
                    -  Window includes WindowOrWorkerGlobalScope;
                    -  WorkerGlobalScope includes WindowOrWorkerGlobalScope;
                    -  ShadowRealmGlobalScope includes WindowOrWorkerGlobalScope;
                    + // structured cloning + any structuredClone(any value, optional StructuredSerializeOptions options = {}); +}; +Window includes WindowOrWorkerGlobalScope; +WorkerGlobalScope includes WindowOrWorkerGlobalScope; +ShadowRealmGlobalScope includes WindowOrWorkerGlobalScope;

                    Base64 utility methods

                    From c0acec53b729686dced3acd12269862026162620 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 24 Sep 2024 15:04:48 +0200 Subject: [PATCH 26/27] Rename WindowOrWorkerOrShadowRealmGlobalScope to UniversalGlobalScope --- source | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source b/source index 480c5720dbf..029e7213a39 100644 --- a/source +++ b/source @@ -10661,7 +10661,7 @@ o.myself = o;
                    -

                    The The structuredClone(value, options) method steps are:

                    @@ -112755,16 +112755,16 @@ interface mixin WindowEventHandlers {
                    -

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin

                    +

                    The UniversalGlobalScope mixin

                    -

                    The WindowOrWorkerOrShadowRealmGlobalScope mixin is for use of APIs that are to be exposed on - Window and WorkerGlobalScope objects.

                    +

                    The UniversalGlobalScope mixin is for use of APIs that are to be exposed on all + global objects.

                    Other standards are encouraged to further extend it using partial - interface mixin WindowOrWorkerOrShadowRealmGlobalScope { … }; along with an + interface mixin UniversalGlobalScope { … }; along with an appropriate reference.

                    -
                    interface mixin WindowOrWorkerOrShadowRealmGlobalScope {
                    +  
                    interface mixin UniversalGlobalScope {
                       // base64 utility methods
                       DOMString btoa(DOMString data);
                       ByteString atob(DOMString data);
                    @@ -112815,7 +112815,7 @@ interface mixin WindowEventHandlers {
                     
                       
                    -

                    The The btoa(data) method must throw an "InvalidCharacterError" DOMException if data contains any character whose code point is greater than U+00FF. Otherwise, the user agent must @@ -112823,7 +112823,7 @@ interface mixin WindowEventHandlers { representation of the nth code point of data, and then must apply forgiving-base64 encode to that byte sequence and return the result.

                    -

                    The The atob(data) method steps are:

                      From df5706b2a31252dc768de8956d4a9439c9073216 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 8 Oct 2024 17:48:01 +0200 Subject: [PATCH 27/27] review --- source | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/source b/source index 029e7213a39..4aa64c3d3dd 100644 --- a/source +++ b/source @@ -110267,19 +110267,6 @@ import "https://example.com/foo/../module2.mjs";
                  -
                  The ShadowRealmGlobalScope interface
                  - -

                  Move this!

                  - -
                  [Global]
                  -interface ShadowRealmGlobalScope : EventTarget {
                  -  readonly attribute ShadowRealmGlobalScope self;
                  -};
                  - -

                  The self getter steps are to return - this.

                  -
                  HostInitializeShadowRealm(realm, context)

                  JavaScript contains an implementation-defined ShadowRealmGlobalScope : EventTarget

                15. Let globalObject be a new ShadowRealmGlobalScope object with realm.

                16. -
                17. Perform SetRealmGlobalObject(realm, - globalObject, undefined). (Should this use - InitializeHostDefinedRealm?)

                18. - -
                19. Perform ? SetDefaultGlobalBindings(realm).

                20. -
                21. Let settings be a new synthetic realm settings object that this algorithm will subsequently initialize.

                22. @@ -110320,10 +110300,21 @@ interface ShadowRealmGlobalScope : EventTarget
                23. Set realm.[[HostDefined]] to settings.

                24. -
                25. Return unused.

                26. +
                27. Return globalObject.

                - +
                The ShadowRealmGlobalScope interface
                + +
                [Global]
                +interface ShadowRealmGlobalScope : EventTarget {
                +  readonly attribute ShadowRealmGlobalScope self;
                +};
                + +

                The self getter steps are to return + this.

                + +

                Event loops

                @@ -112775,9 +112766,10 @@ interface mixin WindowEventHandlers { // structured cloning any structuredClone(any value, optional StructuredSerializeOptions options = {}); }; -Window includes WindowOrWorkerGlobalScope; -WorkerGlobalScope includes WindowOrWorkerGlobalScope; -ShadowRealmGlobalScope includes WindowOrWorkerGlobalScope;
                +Window includes UniversalGlobalScope; +WorkerGlobalScope includes UniversalGlobalScope; +ShadowRealmGlobalScope includes UniversalGlobalScope; +WorkletGlobalScope includes UniversalGlobalScope;

                Base64 utility methods