diff --git a/source b/source index 0d819eccb96..b09e547904a 100644 --- a/source +++ b/source @@ -2868,6 +2868,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • upon rejection
  • upon fulfillment
  • mark as handled
  • +
  • is global prototype chain mutable
  • [Global]
  • [LegacyFactoryFunction]
  • [LegacyLenientThis]
  • @@ -3071,6 +3072,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The RunJobs abstract operation
  • The SameValue abstract operation
  • The ScriptEvaluation abstract operation
  • +
  • The SetDefaultGlobalBindings abstract operation
  • +
  • The NewGlobalEnvironment abstract operation
  • The SetImmutablePrototype abstract operation
  • The ToBoolean abstract operation
  • The ToString abstract operation
  • @@ -3148,6 +3151,16 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The nsMaxInstant and nsMinInstant values
  • + +

    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 +3472,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • current wall time
  • Unix epoch
  • DOMHighResTimeStamp
  • +
  • Performance
  • @@ -9708,7 +9722,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.

      @@ -10754,7 +10768,7 @@ o.myself = o;
      -

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

      @@ -12039,7 +12053,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 +12155,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 +29927,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 +35463,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 +54669,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 @@ -63265,8 +63279,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.

                @@ -63809,7 +63823,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 @@ -89499,7 +89513,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 +89521,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 +89536,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):

                    @@ -89574,8 +89589,8 @@ dictionary DragEventInit : MouseEventInit {
                  5. Let crossOriginSet be undefined.

                  6. 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 realm, that + performs the same steps as the setter of the IDL attribute P on object O.

                  7. Set crossOriginDesc to PropertyDescriptor{ @@ -90602,7 +90617,7 @@ dictionary WindowPostMessageOptions : StructuredSeri

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

                  9. Return container.

                  10. @@ -91041,10 +91056,10 @@ interface BarProp { this.

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

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

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

                  14. @@ -91065,9 +91080,10 @@ interface BarProp { this.

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

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

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

                    @@ -93118,8 +93134,8 @@ enum NavigationHistoryBehavior {
                  18. -

                    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 +93159,8 @@ enum NavigationHistoryBehavior {
                  -
                3. Clean up after running script given navigation's relevant - settings object.

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

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

              3. -

                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 +95849,8 @@ interface NavigationDestination { apiMethodTracker.

              4. -

                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 @@ -100323,8 +100339,9 @@ location.href = '#foo';

              5. Let baseURL be settings's API base URL.

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

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

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

              9. @@ -104096,12 +104113,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 @@ -106075,8 +106092,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 realm or + current principal realm is the surrounding agent.

      @@ -106295,16 +106312,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

      + +

      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 @@ -106446,13 +106479,44 @@ 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 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.

      @@ -106489,27 +106553,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:

    @@ -107645,9 +107831,9 @@ document.querySelector("button").addEventListener("click", bound); decoding bodyBytes.

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

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

  • Run onComplete given script.

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

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

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

  • Return script.

  • @@ -107742,7 +107928,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:

        @@ -107766,7 +107953,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:

            @@ -107799,7 +107987,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 @@ -107967,7 +108156,8 @@ document.querySelector("button").addEventListener("click", bound);

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

              @@ -108065,10 +108255,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).

              @@ -108081,13 +108271,14 @@ document.querySelector("button").addEventListener("click", bound); moduleRequest.

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

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

              -
            6. Let moduleMap be settingsObject's module map.

            7. +
            8. Let moduleMap be moduleMapRealm's module map.

            9. If moduleMap[(url, moduleType)] is "fetching", wait in parallel until that entry's value @@ -108176,8 +108367,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, response's URL, and options.

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

            11. Otherwise:

              @@ -108188,18 +108379,18 @@ document.querySelector("button").addEventListener("click", bound);
            12. 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 moduleMapRealm, response's URL, and options.

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

            14. + moduleMapRealm.

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

            16. + moduleMapRealm.

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

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

            @@ -108239,11 +108430,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 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.

          @@ -108251,9 +108442,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):

            @@ -108267,14 +108458,14 @@ document.querySelector("button").addEventListener("click", bound); baseURL is sanitized here.

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

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

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

          5. -
          6. Set script's settings - object to settings.

          7. +
          8. Set script's realm to + realm.

          9. Set script's base URL to baseURL.

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

            + realm, script).

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

            @@ -108318,19 +108508,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, then set source to the empty string.

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

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

          5. -
          6. Set script's settings - object to settings.

          7. +
          8. Set script's realm to + realm.

          9. Set script's base URL to baseURL.

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

            + realm, script).

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

            @@ -108368,15 +108557,14 @@ 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, then set bodyBytes to the byte sequence 0x00 0x61 0x73 0x6d 0x01 - 0x00 0x00 0x00.

            +

            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 bytes and version number provided.

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

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

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

          7. Set script's base URL to baseURL.

          8. @@ -108399,8 +108587,7 @@ document.querySelector("button").addEventListener("click", bound);
          9. 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 @@ -108430,14 +108617,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. -
            3. Set script's settings - object to settings.

            4. +
            5. Set script's realm to + realm.

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

            7. @@ -108470,14 +108657,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. -
            3. Set script's settings - object to settings.

            4. +
            5. Set script's realm to + realm.

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

            7. @@ -108530,7 +108717,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.

            @@ -108564,15 +108750,15 @@ 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.

            12. Let evaluationStatus be null.

            13. @@ -108601,7 +108787,7 @@ 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.

              4. Rethrow evaluationStatus.[[Value]].

              @@ -108611,7 +108797,7 @@ 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.

              4. Throw a "NetworkError" DOMException.

              @@ -108622,10 +108808,9 @@ 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 settings.

              4. +
              5. Clean up after running script with realm.

              6. Return evaluationStatus.

              @@ -108633,7 +108818,7 @@ document.querySelector("button").addEventListener("click", bound);
          10. -
          11. Clean up after running script with settings.

          12. +
          13. Clean up after running script with realm.

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

          15. @@ -108649,15 +108834,15 @@ 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.

            12. Let evaluationPromise be null.

            13. @@ -108689,50 +108874,60 @@ document.querySelector("button").addEventListener("click", bound);
            14. 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.

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

              -
            16. Clean up after running script with settings.

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

            19. 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, then return "do not run".

              +
            4. If scripting is disabled for + realm, then return "do not run".

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

              If realm is a principal realm:

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

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

            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 @@ -108944,7 +109139,7 @@ document.querySelector("button").addEventListener("click", bound);


              -

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

              @@ -109171,14 +109366,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. @@ -109189,20 +109384,22 @@ 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 + principal 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.

                  @@ -109421,6 +109619,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:

                  @@ -109708,14 +109909,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. @@ -110449,14 +110651,13 @@ dictionary PromiseRejectionEventInit : EventInit

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

                    -
                  6. Let settingsObject be the current settings object.

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

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

                  11. +
                  12. If script is not null, then set realm to script's + realm.

                  13. -
                  14. Let global be settingsObject's global object.

                  15. +
                  16. Let global be realm's + global object.

                  17. If operation is "reject", then:

                    @@ -110535,14 +110736,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.

                      @@ -110563,8 +110764,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.

                    @@ -110601,8 +110801,7 @@ dictionary PromiseRejectionEventInit : EventInit
                  18. Let entry be - finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object.

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

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

                  21. @@ -110654,42 +110853,16 @@ 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:

                        -
                      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 - job settings.

                        +

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

                        This affects the entry concept while the job runs.

                        @@ -110708,8 +110881,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 @@ -110730,6 +110903,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)
                      @@ -110760,7 +110954,8 @@ 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. @@ -110769,8 +110964,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.

                        @@ -110808,12 +111002,12 @@ 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.

                11. Return the JobCallback Record { [[Callback]]: callable, - [[HostDefined]]: { [[IncumbentSettings]]: incumbent settings, [[ActiveScriptContext]]: + [[HostDefined]]: { [[IncumbentRealm]]: incumbent realm, [[ActiveScriptContext]]: script execution context } }.

                @@ -111024,11 +111218,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 both the + current realm and referrer are set to the corresponding + synthetic realm.

                  +
                4. -

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

                  If moduleMapRealm's principal + realm's global object implements + WorkletGlobalScope or ServiceWorkerGlobalScope and loadState is undefined, then:

                  loadState is undefined when the current fetching process has been @@ -111060,14 +111261,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 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 + appropriate synthetic realm.

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

                  + moduleType and moduleMapRealm is false, then:

                  1. Let completion be Completion Record { [[Type]]: throw, @@ -111179,14 +111386,16 @@ import "https://example.com/foo/../module2.mjs";

                6. +
                7. Let fetchClient 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. + originalFetchOptions, url, and fetchClient.

                11. Let destination be "script".

                12. -
                13. Let fetchClient be settingsObject.

                14. -
                15. If loadState is not undefined, then:

                  @@ -111200,7 +111409,7 @@ import "https://example.com/foo/../module2.mjs";
                16. 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.

                  @@ -111241,6 +111450,83 @@ import "https://example.com/foo/../module2.mjs";
                +
                Shadow Realms
                + +
                The ShadowRealmGlobalScope interface
                + +
                [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 + 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. + +
                5. Set settings's execution context to + context.

                6. + +
                7. Set settings's principal realm to O's + associated realm's + principal realm.

                8. + +
                9. Set settings's module + map to a new module map, initially empty.

                10. + +
                11. Set realm.[[HostDefined]] to settings.

                12. + +
                13. Return NormalCompletion(unused).

                14. +
                +

                Event loops

                @@ -111430,9 +111716,14 @@ import "https://example.com/foo/../module2.mjs";
              5. Let event loop be global's relevant agent's event loop.

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

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

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

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

              12. @@ -112299,7 +112590,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. @@ -112472,7 +112763,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. @@ -112533,15 +112824,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

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

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

                    • Process the Event object event as follows:

                      @@ -113324,7 +113615,8 @@ typedef 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.

                    • @@ -113672,6 +113964,95 @@ interface mixin WindowEventHandlers { +

                      The UniversalGlobalScope mixin

                      + +

                      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 UniversalGlobalScope { … }; along with an + appropriate reference.

                      + +
                      interface mixin UniversalGlobalScope {
                      +  readonly attribute boolean isSecureContext;
                      +
                      +  undefined reportError(any e);
                      +
                      +  // base64 utility methods
                      +  DOMString btoa(DOMString data);
                      +  ByteString atob(DOMString data);
                      +
                      +  // microtask queuing
                      +  undefined queueMicrotask(VoidFunction callback);
                      +
                      +  // structured cloning
                      +  any structuredClone(any value, optional StructuredSerializeOptions options = {});
                      +};
                      +Window includes UniversalGlobalScope;
                      +WorkerGlobalScope includes UniversalGlobalScope;
                      +ShadowRealmGlobalScope includes UniversalGlobalScope;
                      +WorkletGlobalScope includes UniversalGlobalScope;
                      + +

                      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 @@ -113685,30 +114066,17 @@ interface mixin WindowEventHandlers { interface mixin WindowOrWorkerGlobalScope { [Replaceable] readonly attribute USVString origin; - readonly attribute boolean isSecureContext; readonly attribute boolean crossOriginIsolated; - 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); 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 = {}); - - // structured cloning - any structuredClone(any value, optional StructuredSerializeOptions options = {}); }; Window includes WindowOrWorkerGlobalScope; WorkerGlobalScope includes WindowOrWorkerGlobalScope; @@ -113747,10 +114115,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 @@ -113767,66 +114137,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, @@ -115258,7 +115568,7 @@ enum DOMParserSupportedType {

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

                    • Run the classic script @@ -121042,7 +121352,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 @@ -121143,7 +121453,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 @@ -121363,7 +121674,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.

                    • @@ -144869,6 +145181,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.