From afc1353841350673981da503b744f9013cad06b9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 Sep 2024 16:23:10 +0200 Subject: [PATCH 01/46] Editorial: make 'module type allowed' take a realm --- source | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source b/source index 0d819eccb96..4a083163620 100644 --- a/source +++ b/source @@ -108081,10 +108081,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.

  • @@ -108239,8 +108240,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, @@ -108530,7 +108531,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.

    @@ -111136,7 +111136,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 002d9fa3931906ebdb54078cd47df4c229a57cdd Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 Sep 2024 16:19:21 +0200 Subject: [PATCH 02/46] 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 4a083163620..a170885a80d 100644 --- a/source +++ b/source @@ -107151,11 +107151,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
      @@ -107223,6 +107222,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:

      @@ -108274,8 +108277,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. @@ -108330,8 +108333,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. @@ -108386,8 +108389,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. @@ -108437,8 +108440,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. @@ -108477,8 +108480,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. @@ -110769,8 +110772,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 3d1c1f25ad109e896d6131152ea2a817c3e49101 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:24:27 +0100 Subject: [PATCH 03/46] 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 a170885a80d..d44bc7c0409 100644 --- a/source +++ b/source @@ -63809,7 +63809,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 @@ -107049,45 +107049,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
      @@ -108271,8 +108271,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. @@ -108327,8 +108328,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. @@ -108378,9 +108380,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.

          @@ -108708,8 +108710,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 b49562c0c0763de64d4a5e37648f4df2de5f8dc6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:24:27 +0100 Subject: [PATCH 04/46] Editorial: create CSS/JSON modules with realm --- source | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source b/source index d44bc7c0409..2e4c25549db 100644 --- a/source +++ b/source @@ -108198,12 +108198,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.

      @@ -108436,14 +108438,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. @@ -108476,14 +108478,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 f1dbdc69be6507a86189781a42df22d48f169dc1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:42:23 +0100 Subject: [PATCH 05/46] Editorial: create JS modules with realm --- source | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source b/source index 2e4c25549db..fbbc03924aa 100644 --- a/source +++ b/source @@ -107802,7 +107802,8 @@ document.querySelector("button").addEventListener("click", bound);
        1. Let script be the result of creating a JavaScript module script - using sourceText, settingsObject, baseURL, and + using sourceText, settingsObject's + realm, baseURL, and options.

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

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

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

        5. If the MIME type essence of mimeType is "text/css" and moduleType is "css", then set moduleScript to @@ -108325,20 +108327,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. @@ -108351,8 +108352,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 50f5d5c82556a376a72fbe62cde7352838f0d9fc Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 20 Sep 2024 14:32:43 +0200 Subject: [PATCH 06/46] Editorial: create WebAssembly modules with realm --- source | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/source b/source index fbbc03924aa..69181fc21dd 100644 --- a/source +++ b/source @@ -108181,8 +108181,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:

          @@ -108376,14 +108377,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 @@ -108394,7 +108394,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. @@ -108407,8 +108407,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 e14e94d4cef93b861c04814c6c4bc6e860273b38 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 18 Nov 2024 14:42:51 +0100 Subject: [PATCH 07/46] Editorial: use a realm in resolve a module specifier --- source | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/source b/source index 69181fc21dd..a0fd143302c 100644 --- a/source +++ b/source @@ -109178,14 +109178,14 @@ dictionary PromiseRejectionEventInit : EventInitreferringScript and a string specifier:

            -
          1. Let settingsObject and baseURL be null.

          2. +
          3. Let realm and baseURL be null.

          4. If referringScript is not null, then:

              -
            1. Set settingsObject to referringScript's - settings object.

            2. +
            3. Set realm to referringScript's + realm.

            4. Set baseURL to referringScript's base URL.

            5. @@ -109196,20 +109196,21 @@ dictionary PromiseRejectionEventInit : EventInitOtherwise:

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

              2. +
              3. Assert: there is a current realm.

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

              6. +
              7. Set realm to the current realm.

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

              10. +
              11. Set baseURL to realm's + settings object's + API base URL.

            6. Let importMap be an empty import map.

            7. -
            8. If settingsObject's global - object implements Window, then set importMap to - settingsObject's global object's +

            9. If realm's global object implements + Window, then set importMap to realm's + global object's import map.

            10. Let serializedBaseURL be baseURL, PromiseRejectionEventInit : EventInitIf result is not null, then:

                -
              1. Add module to resolved module set given settingsObject, - serializedBaseURL, normalizedSpecifier, and asURL.

              2. +
              3. Add module to resolved module set given realm's + global object, serializedBaseURL, + normalizedSpecifier, and asURL.

              4. Return result.

              @@ -109715,14 +109717,15 @@ dictionary PromiseRejectionEventInit : EventInitspecifier as a URL with a boolean that indicates that the specifier is either bare or URL-like that is special.

              -

              To add module to resolved module set given an environment settings - object settingsObject, a string serializedBaseURL, a - string normalizedSpecifier, and a URL-or-null - asURL:

              +

              To add module to resolved module set given + a realm realm, + a string serializedBaseURL, + a string normalizedSpecifier, + and a URL-or-null asURL:

                -
              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. From d5286dca49349a221ba2838ec964848b8276be29 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 10:57:17 +0100 Subject: [PATCH 08/46] 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 a0fd143302c..0dbfad1f2d0 100644 --- a/source +++ b/source @@ -63265,8 +63265,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.

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

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

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

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

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

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

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

              13. Run onComplete given script.
              @@ -107648,9 +107649,9 @@ document.querySelector("button").addEventListener("click", bound); decoding bodyBytes.

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

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

            13. Run onComplete given script.

            @@ -107729,9 +107730,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.

          @@ -108260,9 +108261,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):

            @@ -108277,14 +108278,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. @@ -108302,8 +108302,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.

            @@ -115268,7 +115267,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 9e9543ba473821c167e441a99a11abf4f4c8dec7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 16:39:35 +0200 Subject: [PATCH 09/46] Editorial: use realms in check if we can run script --- source | 57 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/source b/source index 0dbfad1f2d0..73bd6b94757 100644 --- a/source +++ b/source @@ -108569,15 +108569,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. @@ -108606,7 +108607,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]].

              @@ -108616,7 +108618,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.

              @@ -108630,7 +108633,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.

            @@ -108638,7 +108642,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. @@ -108654,15 +108659,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 +

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

          7. Record module 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 evaluationPromise be null.

          13. @@ -108697,22 +108703,22 @@ document.querySelector("button").addEventListener("click", bound); reason for 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 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".

          @@ -110610,14 +110616,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.

          @@ -110626,7 +110632,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 @@ -110693,8 +110700,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 1beeb822bdc30477f4d42bdea72ac6f0248627ca Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 26 Sep 2024 13:37:28 +0200 Subject: [PATCH 10/46] 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 73bd6b94757..3392e2eb237 100644 --- a/source +++ b/source @@ -108630,8 +108630,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. @@ -108700,8 +108699,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 84c282f03aa66e47d5d1324c1b12be130b787138 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 16:32:43 +0200 Subject: [PATCH 11/46] 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 3392e2eb237..86168bab4f5 100644 --- a/source +++ b/source @@ -93118,8 +93118,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.

              @@ -93143,8 +93143,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 @@ -95833,8 +95833,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 @@ -104097,12 +104097,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 @@ -106568,6 +106568,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 @@ -108577,8 +108582,7 @@ document.querySelector("button").addEventListener("click", bound);

      6. Record classic script execution start time given script.

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

      9. +
      10. Prepare to run script given realm.

      11. Let evaluationStatus be null.

      12. @@ -108607,8 +108611,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]].

        @@ -108618,8 +108621,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.

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

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

      16. +
      17. Clean up after running script with realm.

      18. Return evaluationStatus.

      @@ -108641,8 +108642,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.

  • @@ -108666,8 +108666,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.

  • @@ -108702,8 +108701,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.

  • @@ -108722,28 +108720,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 @@ -110621,8 +110623,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.

      @@ -110631,8 +110632,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 @@ -110669,32 +110669,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:

        @@ -110703,8 +110677,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.

        @@ -110723,8 +110697,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 @@ -110745,6 +110719,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 698addf13c2287899c3bb466833c968373420fc4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 17:09:19 +0200 Subject: [PATCH 12/46] Editorial: use realms around 'incumbent' --- source | 154 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/source b/source index 86168bab4f5..a7277846971 100644 --- a/source +++ b/source @@ -106766,23 +106766,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. @@ -106791,8 +106791,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. @@ -106806,19 +106806,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 @@ -106830,31 +106829,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 @@ -106874,10 +106871,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 @@ -106927,15 +106924,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.

      @@ -106950,11 +106947,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.

      @@ -106979,21 +106977,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 @@ -110551,14 +110548,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.

        @@ -110579,8 +110576,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.

      @@ -110770,7 +110766,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. @@ -110822,7 +110818,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 eba56c6e6b4c717d98c2ffc5512b5cf9cc3bb04a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 26 Sep 2024 14:59:46 +0200 Subject: [PATCH 13/46] Editorial: use realm in HostPromiseRejectionTracker --- source | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source b/source index a7277846971..1ccf4c026a8 100644 --- a/source +++ b/source @@ -110462,14 +110462,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 dbd4eefb2ade08eff159e40255ad93f454721eeb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Sep 2024 17:54:42 +0200 Subject: [PATCH 14/46] 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 | 632 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 499 insertions(+), 133 deletions(-) diff --git a/source b/source index 1ccf4c026a8..7492c079186 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 @@ -3071,6 +3072,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. @@ -3148,6 +3150,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
      @@ -3459,6 +3471,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    45. current wall time
    46. Unix epoch
    47. DOMHighResTimeStamp
    48. +
    49. Performance
    50. @@ -9708,7 +9721,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.

        @@ -12039,7 +12052,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. @@ -12141,11 +12154,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 @@ -29913,7 +29926,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 @@ -35449,7 +35462,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 @@ -54655,7 +54668,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 @@ -89499,7 +89512,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. @@ -89507,13 +89520,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 )
                    @@ -89522,8 +89535,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):

                      @@ -89549,8 +89563,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, @@ -89567,15 +89581,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{ @@ -90602,7 +90616,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. @@ -91041,10 +91055,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. @@ -91065,9 +91079,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:

                      @@ -106076,8 +106091,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.

                      @@ -106296,16 +106311,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 @@ -106452,8 +106483,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.

                      @@ -106490,27 +106530,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
                    @@ -106670,9 +106830,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. @@ -106718,13 +106878,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.

                    @@ -106747,7 +106907,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 @@ -107027,12 +107189,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
                    @@ -107157,7 +107330,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
                    @@ -107227,7 +107403,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 @@ -107748,7 +107925,8 @@ document.querySelector("button").addEventListener("click", bound);

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

                        @@ -107772,7 +107950,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:

                            @@ -107974,7 +108153,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.

                            @@ -108072,10 +108252,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).

                            @@ -108088,14 +108268,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 @@ -108106,6 +108286,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. @@ -108184,9 +108381,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:

                            @@ -108197,21 +108393,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. @@ -108230,13 +108423,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).

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

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

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

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

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

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

                    4. +
                    5. +

                      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 @@ -110765,7 +111043,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. @@ -110812,7 +111091,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.

                      @@ -111028,11 +111307,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 @@ -111064,14 +111350,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.

                          +
                        @@ -111140,8 +111432,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, @@ -111184,6 +111475,10 @@ import "https://example.com/foo/../module2.mjs";

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

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

                      10. @@ -111205,7 +111500,7 @@ import "https://example.com/foo/../module2.mjs";
                      11. 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.

                        @@ -111246,6 +111541,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 thisValue is not an 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

                      @@ -112304,7 +112664,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. @@ -112477,7 +112837,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. @@ -112489,7 +112849,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. @@ -112538,15 +112898,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.

                        • @@ -121047,7 +121408,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 @@ -121148,7 +121509,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 @@ -121368,7 +121730,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.

                        • @@ -144874,6 +145237,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 e976653603476d072d5f64fdb22b142e3110ac79 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 16 Nov 2023 17:04:31 +0100 Subject: [PATCH 15/46] 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 7492c079186..5c7734a1759 100644 --- a/source +++ b/source @@ -106631,13 +106631,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.

                    -
                  10. -

                    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. -
                    -
                  11. -
                  12. Set moduleMap[(url, moduleType)] to "fetching".

                  13. @@ -108423,85 +108400,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 @@ -111316,8 +111214,7 @@ import "https://example.com/foo/../module2.mjs";

                3. 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:

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

                4. -

                  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 @@ -111485,7 +111382,9 @@ import "https://example.com/foo/../module2.mjs";

                5. Let destination be "script".

                6. -
                7. Let fetchClient be settingsObject.

                8. +
                9. Let fetchClient be moduleMapRealm's + principal realm's + settings object.

                10. If loadState is not undefined, then:

                  From 8131d2749cabf1096850eab7b4899b1498ef8fe8 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 13 Dec 2023 10:05:44 +0100 Subject: [PATCH 16/46] Start defining ShadowRealmGlobalObject --- source | 82 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/source b/source index 5c7734a1759..1a11491ef2d 100644 --- a/source +++ b/source @@ -2856,7 +2856,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
                11. frozen array and creating a frozen array
                12. create a new object implementing the interface
                13. -
                14. define the global property references
                15. callback this value
                16. converting between Web IDL types and JS types
                17. invoking and @@ -3043,6 +3042,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
                18. The HostMakeJobCallback abstract operation
                19. The HostPromiseRejectionTracker abstract operation
                20. The InitializeHostDefinedRealm abstract operation
                21. +
                22. The SetRealmGlobalObject abstract operation
                23. The IsAccessorDescriptor abstract operation
                24. The IsCallable abstract operation
                25. The IsConstructor abstract operation
                26. @@ -3156,7 +3156,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
                  @@ -111440,6 +111440,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. @@ -111464,45 +111502,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 thisValue is not an 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 4fc8be2511af8966b4ad638831c573c08b5175b9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 15 Dec 2023 15:32:04 +0100 Subject: [PATCH 17/46] Add link --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index 1a11491ef2d..ca563092ed6 100644 --- a/source +++ b/source @@ -111465,8 +111465,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 59904025093c3c6fb17eb20d2b9e52e3989a8b2c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 18 Jan 2024 15:52:44 +0100 Subject: [PATCH 18/46] Review --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index ca563092ed6..d72058872ca 100644 --- a/source +++ b/source @@ -111208,8 +111208,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 6e859ee8f5599720952d61de78c29436d5d21931 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 20 Dec 2023 17:12:45 +0100 Subject: [PATCH 19/46] Better layering for the mutable global prototype chain --- source | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/source b/source index d72058872ca..e0b0b622543 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. @@ -111454,22 +111455,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 06b190bf04b4dc05755f62ca92be08a279172b15 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 11 Jan 2024 16:43:27 +0100 Subject: [PATCH 20/46] Rephrase --- source | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source b/source index e0b0b622543..e71eb709e2c 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. @@ -111463,8 +111463,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 f788ca64af1d6adfab5ed108d569ec9a09719722 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 31 Jan 2024 17:41:56 +0100 Subject: [PATCH 21/46] Add context argument to HostInitializeShadowRealm --- source | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source b/source index e71eb709e2c..dc5893ae734 100644 --- a/source +++ b/source @@ -111455,11 +111455,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

                      @@ -111478,6 +111478,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 097b31b46305261b8188a971103583ebac328513 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 18 Jan 2024 14:30:56 +0100 Subject: [PATCH 22/46] Rename ShadowRealmGlobalObject --- source | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source b/source index dc5893ae734..e38cc3e5d12 100644 --- a/source +++ b/source @@ -111442,17 +111442,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)
                    @@ -111465,7 +111465,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/46] Add atob, btoa, structuredClone to shadow realms --- source | 150 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 82 insertions(+), 68 deletions(-) diff --git a/source b/source index e38cc3e5d12..beed7bc4d18 100644 --- a/source +++ b/source @@ -10768,7 +10768,7 @@ o.myself = o;

                    -

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

                    @@ -113930,6 +113930,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 @@ -113948,10 +114029,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); @@ -113964,9 +114041,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; @@ -114025,66 +114099,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 d8e159431033c4fb192ff98d1c2cf278a93f3089 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 14:09:39 +0100 Subject: [PATCH 24/46] Add queueMicrotask --- source | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source b/source index beed7bc4d18..e5487286037 100644 --- a/source +++ b/source @@ -113944,6 +113944,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 = {}); }; @@ -114035,9 +114038,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 20bae7965bf0b44f87e90cd0f0f6af17a7d3653e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Feb 2024 14:09:56 +0100 Subject: [PATCH 25/46] Indentation --- source | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/source b/source index e5487286037..a4fca8e7036 100644 --- a/source +++ b/source @@ -113933,26 +113933,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 b1021fef93d81f60fec5c6c20e277eff00d8a632 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 24 Sep 2024 15:04:48 +0200 Subject: [PATCH 26/46] Rename WindowOrWorkerOrShadowRealmGlobalScope to UniversalGlobalScope --- source | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source b/source index a4fca8e7036..afdcc0e7252 100644 --- a/source +++ b/source @@ -10768,7 +10768,7 @@ o.myself = o;
                    -

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

                    @@ -113930,16 +113930,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);
                    @@ -113990,7 +113990,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 @@ -113998,7 +113998,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 01e83bb244f3a6bb12bbfa92ce953b8f8652f626 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 8 Oct 2024 17:48:01 +0200 Subject: [PATCH 27/46] review --- source | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/source b/source index afdcc0e7252..2e59dcff754 100644 --- a/source +++ b/source @@ -111442,19 +111442,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. @@ -111495,10 +111475,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

                @@ -113950,9 +113941,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

                From 0dc0ee4ac01bb3c9fd2708487b9f1e973eec77d4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 22 Oct 2024 16:18:49 +0200 Subject: [PATCH 28/46] Review --- source | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source b/source index 2e59dcff754..17825edc468 100644 --- a/source +++ b/source @@ -111442,7 +111442,7 @@ import "https://example.com/foo/../module2.mjs";
              -
              HostInitializeShadowRealm(realm, context)
              +
              HostInitializeShadowRealm(realm, context, O)

              JavaScript contains an implementation-defined HostInitializeShadowRealm(realm, @@ -111463,8 +111463,8 @@ import "https://example.com/foo/../module2.mjs"; context.

            3. Set settings's principal realm to the - current principal realm.

            4. + data-x="synthetic-realm-settings-object-principal-realm">principal realm to O's + associated realm.

            5. Set settings's underlying realm to From 9e48745b351ba74115c9ea8527d735c274006386 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 22 Oct 2024 17:47:51 +0200 Subject: [PATCH 29/46] review --- source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source b/source index 17825edc468..620d36919d7 100644 --- a/source +++ b/source @@ -111446,8 +111446,8 @@ import "https://example.com/foo/../module2.mjs";

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

              + context, O) abstract operation. + User agents must use the following implementation: JSSHADOWREALM

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

                From ea3c573330b79c960fcbc6ff4d0c03dcc8707ddf Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 4 Nov 2024 13:17:02 +0100 Subject: [PATCH 30/46] Restructure HostInitializeShadowRealm --- source | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source b/source index 620d36919d7..f0c50d53027 100644 --- a/source +++ b/source @@ -3043,7 +3043,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
              2. The HostMakeJobCallback abstract operation
              3. The HostPromiseRejectionTracker abstract operation
              4. The InitializeHostDefinedRealm abstract operation
              5. -
              6. The SetRealmGlobalObject abstract operation
              7. The IsAccessorDescriptor abstract operation
              8. The IsCallable abstract operation
              9. The IsConstructor abstract operation
              10. @@ -3074,6 +3073,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
              11. The SameValue abstract operation
              12. The ScriptEvaluation abstract operation
              13. The SetDefaultGlobalBindings abstract operation
              14. +
              15. The NewGlobalEnvironment abstract operation
              16. The SetImmutablePrototype abstract operation
              17. The ToBoolean abstract operation
              18. The ToString abstract operation
              19. @@ -111475,7 +111475,14 @@ import "https://example.com/foo/../module2.mjs";
              20. Set realm.[[HostDefined]] to settings.

              21. -
              22. Return globalObject.

              23. +
              24. Set realm.[[GlobalObject]] to globalObject.

              25. + +
              26. Set realm.[[GlobalEnv]] to + NewGlobalEnvironment(globalObject, globalObject).

              27. + +
              28. Perform ? SetDefaultGlobalBindings(realm).

              29. + +
              30. Return NormalCompletion(unused).

              The ShadowRealmGlobalScope interface
              From 766020831335519029fb78c95391e73b27822f6c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 18 Nov 2024 15:12:42 +0100 Subject: [PATCH 31/46] Indentation --- source | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source b/source index f0c50d53027..eb1d280eb47 100644 --- a/source +++ b/source @@ -106318,12 +106318,12 @@ new PaymentRequest(…); // Allowed to use 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 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.

              • +
              • 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 From f5194b0bd9622cc8aba01c08e011aaf692076053 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 19 Nov 2024 15:36:33 +0100 Subject: [PATCH 32/46] Fix --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index eb1d280eb47..8ed79761010 100644 --- a/source +++ b/source @@ -108897,7 +108897,7 @@ document.querySelector("button").addEventListener("click", bound); running JavaScript execution context.

            6. -

              If realm is a principal realm, then:

              +

              If realm is a principal realm:

              1. Let settings be realm's Date: Tue, 19 Nov 2024 16:11:29 +0100 Subject: [PATCH 33/46] Remove unnecessary concept --- source | 9 --------- 1 file changed, 9 deletions(-) diff --git a/source b/source index 8ed79761010..2b453b2398b 100644 --- a/source +++ b/source @@ -106624,11 +106624,6 @@ new PaymentRequest(…); // Allowed to use

                The principal realm which this synthetic realm exists within.

                -

                An underlying realm

                - -

                The synthetic realm which this settings object represents.

                -

                A module map

                @@ -111466,10 +111461,6 @@ import "https://example.com/foo/../module2.mjs"; data-x="synthetic-realm-settings-object-principal-realm">principal realm to O's associated realm.

              2. -
              3. Set settings's underlying realm to - realm.

              4. -
              5. Set settings's module map to a new module map, initially empty.

              6. From f896319c0283b1e691a87f07e4005ff89143a8ec Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 20 Nov 2024 17:16:32 +0100 Subject: [PATCH 34/46] queueing --- source | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source b/source index 2b453b2398b..3bc951b106c 100644 --- a/source +++ b/source @@ -111676,9 +111676,14 @@ interface ShadowRealmGlobalScope : EventTarget
              7. Let event loop be global's relevant agent's event loop.

              8. -
              9. Let document be global's associated Document, if global is - a Window object; otherwise null.

                +
              10. Let principal global be global's + realm's + principal realm's + global.

              11. + +
              12. Let document be principal global's associated Document, + if principal global is a Window object; otherwise null.

              13. Queue a task given source, event loop, document, and steps.

              14. @@ -112730,7 +112735,7 @@ interface ShadowRealmGlobalScope : EventTarget
            7. -
            8. Let realm be the current principal realm.

            9. +
            10. Let realm be the current realm.

            11. Let p be a new promise.

            12. From eff546fb681378af63c4e04842b1f62495d2ca8d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 21 Nov 2024 14:36:55 +0100 Subject: [PATCH 35/46] Better guidance and sectioning --- source | 101 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/source b/source index 3bc951b106c..7f92362b4c1 100644 --- a/source +++ b/source @@ -89564,8 +89564,8 @@ dictionary DragEventInit : MouseEventInit {
            13. Let value be originalDesc.[[Value]].

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

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

            16. Set crossOriginDesc to PropertyDescriptor{ [[Value]]: value, @@ -89582,14 +89582,14 @@ dictionary DragEventInit : MouseEventInit {

            17. Let crossOriginGet be undefined.

            18. If e.[[NeedsGet]] is true, then set crossOriginGet to an - 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 + anonymous built-in function, created in the current realm, that performs the + same steps as the getter of the IDL attribute P on object O.

            19. Let crossOriginSet be undefined.

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

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

              -

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

              +

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

              @@ -106479,6 +106479,28 @@ new PaymentRequest(…); // Allowed to use object's relevant agent's event loop.

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

              + +

              A module map

              + +

              A module map that is used when importing JavaScript modules.

              +
              +
              Realms, settings objects, and global objects

              A global object is a JavaScript object that is the [[GlobalObject]] field of @@ -106608,32 +106630,7 @@ new PaymentRequest(…); // Allowed to use

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

            - -

            A module map

            - -

            A module map that is used when importing JavaScript modules.

            -
            - -

            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 @@ -106726,9 +106723,9 @@ new PaymentRequest(…); // Allowed to use


            When defining algorithm steps throughout this specification, it is often important to indicate - 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:

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

            Entry
            @@ -106820,7 +106817,7 @@ new PaymentRequest(…); // Allowed to use data-x="">a.html.

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

          7. -
          8. The current principal realm is that of

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

          9. The relevant realm of the object on which @@ -106868,13 +106865,13 @@ new PaymentRequest(…); // Allowed to use </script>

            If the algorithm for the getBattery() method - had instead used the current principal realm, all the results would be reversed. - That is, after the first call to getBattery() in - outer.html, the Navigator object in current 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.

            @@ -107183,19 +107180,23 @@ document.querySelector("button").addEventListener("click", bound); data-x="concept-principal-realm-of-realm">principal realm 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.

            + data-x="concept-realm-global">global object of the + current principal realm.

            + +

            Note that the current realm can refer to a synthetic realm. + Whether to use the "current" or "current principal" concept depends on the situation. + It appears to be the case that in most situations where a realm is needed, + the current realm is a better choice than the current principal realm, + while it is more likely that for a settings object, the current principal settings object + is to be used; notably the settings object for a synthetic realm contains much less + information. + Note that in the context of APIs that are not exposed in a synthetic realm, both + concepts coincide.

            Relevant
            From dc9fddce427df64544d0eb09c4de01295eeaf9ca Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 21 Nov 2024 14:57:37 +0100 Subject: [PATCH 36/46] Improve the global object creation --- source | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/source b/source index 7f92362b4c1..893cd1d3427 100644 --- a/source +++ b/source @@ -111438,19 +111438,46 @@ import "https://example.com/foo/../module2.mjs";
          -
          HostInitializeShadowRealm(realm, context, O)
          +
          Shadow Realms
          -

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

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

          The self getter steps are to return + this.

          + +
          Creating a Shadow Realm
          + +

          When performing InitializeHostDefinedRealm + in the ShadowRealm constructor, the steps to + create a global object created in a host-defined manner are the following:

            +
          1. Let realm be the current realm.

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

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

          4. +
          5. Return globalObject.

          6. +
          + +
          HostInitializeShadowRealm(realm, context, O)
          + +

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

          + +
            +
          1. Let globalObject be realm.[[GlobalObject]].

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

          4. @@ -111467,28 +111494,10 @@ import "https://example.com/foo/../module2.mjs";
          5. Set realm.[[HostDefined]] to settings.

          6. -
          7. Set realm.[[GlobalObject]] to globalObject.

          8. - -
          9. Set realm.[[GlobalEnv]] to - NewGlobalEnvironment(globalObject, globalObject).

          10. - -
          11. Perform ? SetDefaultGlobalBindings(realm).

          12. -
          13. Return NormalCompletion(unused).

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

          The self getter steps are to return - this.

          - - +

          Event loops

          From f0e4ee64d448df323dd49945b128f45bc910e0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 21 Nov 2024 15:43:55 +0100 Subject: [PATCH 37/46] Rephrase --- source | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source b/source index 893cd1d3427..1215688e863 100644 --- a/source +++ b/source @@ -107190,10 +107190,10 @@ document.querySelector("button").addEventListener("click", bound);

          Note that the current realm can refer to a synthetic realm. Whether to use the "current" or "current principal" concept depends on the situation. - It appears to be the case that in most situations where a realm is needed, - the current realm is a better choice than the current principal realm, - while it is more likely that for a settings object, the current principal settings object - is to be used; notably the settings object for a synthetic realm contains much less + For example, if you need a realm to create an object or a function you should probably + use the current realm, while if you are checking whether some operation is allowed or not + in the current context you are probably looking for the current principal settings + object; notably the settings object for a synthetic realm contains much less information. Note that in the context of APIs that are not exposed in a synthetic realm, both concepts coincide.

          From c8d1b45998094cfec01936a9d99fcbd97e00cd98 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 21 Nov 2024 15:53:35 +0100 Subject: [PATCH 38/46] address comment --- source | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source b/source index 1215688e863..df77eeef656 100644 --- a/source +++ b/source @@ -111370,20 +111370,16 @@ import "https://example.com/foo/../module2.mjs";
      2. -
      3. Let settingsObject be moduleMapRealm's +

      4. Let fetchClient be moduleMapRealm's principal realm's settings object.

      5. Let fetchOptions be the result of getting the descendant script fetch options given - originalFetchOptions, url, and settingsObject.

      6. + originalFetchOptions, url, and fetchClient.

      7. Let destination be "script".

      8. -
      9. Let fetchClient be moduleMapRealm's - principal realm's - settings object.

      10. -
      11. If loadState is not undefined, then:

        From a12d85ec35d35b15d77cb49e5367474ae362674f Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 21 Nov 2024 16:33:02 +0100 Subject: [PATCH 39/46] Note --- source | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source b/source index df77eeef656..55c08571ed5 100644 --- a/source +++ b/source @@ -109606,6 +109606,9 @@ dictionary PromiseRejectionEventInit : EventInit +

        Import maps are not currently supported in + synthetic realms. This could change in the future.

        +

        The simplest use of import maps is to globally remap a bare module specifier:

        From 2039fa1bafb6d95830bff09985c2ed1c35aed977 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 26 Nov 2024 10:17:49 +0100 Subject: [PATCH 40/46] link ShadowRealmGlobalScope --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 55c08571ed5..5aa96236701 100644 --- a/source +++ b/source @@ -111443,7 +111443,7 @@ import "https://example.com/foo/../module2.mjs";
        [Global]
         interface ShadowRealmGlobalScope : EventTarget {
        -  readonly attribute ShadowRealmGlobalScope self;
        +  readonly attribute ShadowRealmGlobalScope self;
         };

        The Date: Tue, 26 Nov 2024 10:17:59 +0100 Subject: [PATCH 41/46] event handlers --- source | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/source b/source index 5aa96236701..47513fea021 100644 --- a/source +++ b/source @@ -111444,12 +111444,29 @@ import "https://example.com/foo/../module2.mjs";

        [Global]
         interface ShadowRealmGlobalScope : EventTarget {
           readonly attribute ShadowRealmGlobalScope self;
        +  attribute OnErrorEventHandler onerror;
        +  attribute EventHandler onrejectionhandled;
        +  attribute EventHandler onunhandledrejection;
         };

        The self getter steps are to return this.

        +

        The following are the event handlers (and their corresponding event handler event types) that must be supported, + as event handler IDL attributes, by objects implementing the + ShadowRealmGlobalScope interface:

        + + + + +
        Event handler Event handler event type +
        onerror error +
        onrejectionhandled rejectionhandled +
        onunhandledrejection unhandledrejection +
        +
        Creating a Shadow Realm

        When performing InitializeHostDefinedRealm @@ -113240,9 +113257,9 @@ interface ShadowRealmGlobalScope : EventTarget

      12. Let special error event handling be true if event is an ErrorEvent object, event's type is "error", and event's currentTarget implements the - WindowOrWorkerGlobalScope mixin. Otherwise, let special error event - handling be false.

      13. + data-x="dom-Event-currentTarget">currentTarget implements either the + WindowOrWorkerGlobalScope mixin or the ShadowRealmGlobalScope + interface. Otherwise, let special error event handling be false.

      14. Process the Event object event as follows:

        From 9aece76459e314cc3e5dd627b62edf1db0c2b3c0 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 26 Nov 2024 10:58:41 +0100 Subject: [PATCH 42/46] Add reportError --- source | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source b/source index 47513fea021..1ad5765a67c 100644 --- a/source +++ b/source @@ -109127,7 +109127,7 @@ document.querySelector("button").addEventListener("click", bound);
        -

        The The reportError(e) method steps are to report an exception e for this.

        @@ -113960,6 +113960,8 @@ interface mixin WindowEventHandlers { appropriate reference.

        interface mixin UniversalGlobalScope {
        +  undefined reportError(any e);
        +
           // base64 utility methods
           DOMString btoa(DOMString data);
           ByteString atob(DOMString data);
        @@ -114051,8 +114053,6 @@ interface mixin WindowOrWorkerGlobalScope {
           readonly attribute boolean isSecureContext;
           readonly attribute boolean crossOriginIsolated;
         
        -  undefined reportError(any e);
        -
           // timers
           long setTimeout(TimerHandler handler, optional long timeout = 0, any... arguments);
           undefined clearTimeout(optional long id = 0);
        
        From 8cf315000bd72a87b30731780a118b5a6e1de139 Mon Sep 17 00:00:00 2001
        From: Ms2ger 
        Date: Tue, 26 Nov 2024 11:09:46 +0100
        Subject: [PATCH 43/46] isSecureContext
        
        ---
         source | 11 +++++++----
         1 file changed, 7 insertions(+), 4 deletions(-)
        
        diff --git a/source b/source
        index 1ad5765a67c..7c890c4b8c8 100644
        --- a/source
        +++ b/source
        @@ -113960,6 +113960,8 @@ interface mixin WindowEventHandlers {
           appropriate reference.

        interface mixin UniversalGlobalScope {
        +  readonly attribute boolean isSecureContext;
        +
           undefined reportError(any e);
         
           // base64 utility methods
        @@ -114050,7 +114052,6 @@ interface mixin WindowEventHandlers {
         
         interface mixin WindowOrWorkerGlobalScope {
           [Replaceable] readonly attribute USVString origin;
        -  readonly attribute boolean isSecureContext;
           readonly attribute boolean crossOriginIsolated;
         
           // timers
        @@ -114100,10 +114101,12 @@ document.body.appendChild(frame)
        -

        The The isSecureContext getter steps are to return true if - this's relevant settings object is a secure context, or - false otherwise.

        + this's realm's + principal realm's + settings object is a + secure context, or false otherwise.

        The origin getter steps are to return this's From acb7665a9a520095eb17c0926684bc99e4b2f5c1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 27 Nov 2024 09:31:05 +0100 Subject: [PATCH 44/46] Fix base url in module specifier resolution --- source | 1 + 1 file changed, 1 insertion(+) diff --git a/source b/source index 7c890c4b8c8..0a78222ca1c 100644 --- a/source +++ b/source @@ -109377,6 +109377,7 @@ dictionary PromiseRejectionEventInit : EventInit

        Set realm to the current realm.

      15. Set baseURL to realm's + principal realm's settings object's API base URL.

      From 7449ee076f55c4c95d9143c712c49261f6425ea6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 27 Nov 2024 11:24:30 +0100 Subject: [PATCH 45/46] Fix HostInitializeShadowRealm --- source | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source b/source index 0a78222ca1c..7194eac5540 100644 --- a/source +++ b/source @@ -111504,7 +111504,8 @@ interface ShadowRealmGlobalScope : EventTarget
    51. Set settings's principal realm to O's - associated realm.

    52. + associated realm's + principal realm.

    53. Set settings's module map to a new module map, initially empty.

    54. From a2fe477c75d0e1fedf0b6853b9b96d38ceb1ee9a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 27 Nov 2024 14:22:52 +0100 Subject: [PATCH 46/46] relevant principal * --- source | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source b/source index 7194eac5540..b09e547904a 100644 --- a/source +++ b/source @@ -107214,6 +107214,18 @@ document.querySelector("button").addEventListener("click", bound); object of the relevant realm for o.

      +

      The relevant principal realm for a platform object o + is o's relevant realm's + principal realm.

      + +

      The relevant principal settings object for a platform object + o is o's relevant principal realm's + environment settings object.

      + +

      The relevant principal global object for a platform object + o is o's relevant principal realm's + global object.

      +
      Enabling and disabling scripting