diff --git a/source b/source index 56f8f352ac5..6b6e1e10955 100644 --- a/source +++ b/source @@ -2746,7 +2746,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute agent cluster
  • automatic semicolon insertion
  • candidate execution
  • -
  • The current Realm Record
  • +
  • The current Realm Record
  • early error
  • forward progress
  • invariants of the essential internal methods
  • @@ -2848,6 +2848,7 @@ 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 SetImmutablePrototype abstract operation
  • The ToBoolean abstract operation
  • The ToString abstract operation
  • @@ -2861,6 +2862,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The FinalizationRegistry class
  • The RegExp class
  • The SharedArrayBuffer class
  • +
  • The SyntaxError class
  • The TypeError class
  • The RangeError class
  • The WeakRef class
  • @@ -2897,6 +2899,16 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The Synthetic Module Record specification type
  • The ParseJSONModule abstract operation
  • + +

    User agents that support JavaScript must also implement the Realm + proposal. The following term is defined there, and used in this specification:

    + +
    WebAssembly
    @@ -10618,8 +10630,8 @@ 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 Realm - Record and NewTarget.

    2. + to which the active function object corresponds, given the current principal + realm and NewTarget.

    3. Set element's node document to the current global object's associated @@ -81532,7 +81544,7 @@ console.assert(iframeWindow.frameElement === null);

    4. Let value be originalDesc.[[Value]].

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

    6. Set crossOriginDesc to PropertyDescriptor{ @@ -81550,14 +81562,14 @@ console.assert(iframeWindow.frameElement === null);

    7. Let crossOriginGet be undefined.

    8. If e.[[NeedsGet]] is true, then set crossOriginGet to an - anonymous built-in function, created in the current Realm Record, that + 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.

    9. Let crossOriginSet be undefined.

    10. If e.[[NeedsSet]] is true, then set crossOriginSet to an - anonymous built-in function, created in the current Realm Record, that + 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.

    11. @@ -89747,7 +89759,7 @@ new PaymentRequest(…); // Allowed to use
    12. Set the current entry to entry.

    13. -
    14. Let targetRealm be the current Realm Record.

    15. +
    16. Let targetRealm be the current principal Realm.

    17. Let state be null.

    18. @@ -90721,7 +90733,7 @@ interface BeforeUnloadEvent : Event { data-x="">This pointer is not yet defined in the JavaScript specification; see tc39/ecma262#1357.

      -

      The agent equivalent of the current Realm Record is the +

      The agent equivalent of the current principal Realm is the surrounding agent.

      @@ -90943,16 +90955,29 @@ interface BeforeUnloadEvent : Event {

      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.

      + concept, representing a global environment in which script is run.

      + +

      In the context of the JavaScript Realms API proposal, there are two kinds of realms:

      + +

      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 has an associated principal Realm from which it + originated. In contexts where the associated values or algorithms of a synthetic Realm are needed, + refer instead to the associated principal Realm.

      +

      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 @@ -91123,32 +91148,40 @@ interface BeforeUnloadEvent : Event {

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

      -

      In this specification, all JavaScript - realms are created with global objects that are either Window or - WorkerGlobalScope objects.

      +

      A JavaScript realm's global object is found in its [[GlobalObject]] field. A global + object's Realm is the unique + JavaScript 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 JavaScript + Realms are created with global objects that are either Window, + WorkerGlobalScope or WorkletGlobalScope objects.

      -

      There is always a 1-to-1-to-1 mapping between JavaScript - 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:

    +
    Synthetic realm settings objects
    + +

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

    + +
    +

    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:

    + + + +

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

    + +
      +
    1. If realm.[[HostDefined]] is a synthetic realm settings object, then + realm is a synthetic Realm; set realm to the principal Realm of + realm.[[HostDefined]].

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

    4. + +
    5. Return realm.

    6. +
    + +

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

    + +
      +
    1. If realm is a principal Realm, 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 JavaScript 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
    @@ -91228,8 +91355,8 @@ interface BeforeUnloadEvent : Event {
    Current
    This corresponds to the currently-running function object, including built-in user-agent - functions which might not be implemented as JavaScript. (It is derived from the current JavaScript realm.)
    + functions which might not be implemented as JavaScript. (It is derived from the current + underlying Realm.)
    Relevant
    Every platform object has a relevant @@ -91308,7 +91435,7 @@ interface BeforeUnloadEvent : Event { data-x="">a.html.

  • The incumbent Realm is that of b.html.

  • -
  • The current Realm is that of

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

  • The relevant Realm of the object on which @@ -91356,7 +91483,7 @@ interface BeforeUnloadEvent : Event { </script>

    If the algorithm for the getBattery() method - had instead used the current Realm, all the results + 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 inner.html would be permanently storing @@ -91385,7 +91512,8 @@ interface BeforeUnloadEvent : Event {

    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 BeforeUnloadEvent : Event {

  • Return context's Realm component's principal realm's settings object.

  • @@ -91664,15 +91793,30 @@ document.querySelector("button").addEventListener("click", bound);
    Current
    -

    The JavaScript specification defines the current Realm Record, sometimes - abbreviated to the "current Realm".

    +

    The JavaScript specification defines the current underlying Realm algorithm, + referred to in that specification as the "current Realm Record".

    + +

    The current principal Realm is the principal Realm of the current underlying + Realm.

    + +

    This specification and other web specifications avoid the term "current + Realm", as it is ambiguous whether the intention is to refer to the current principal + realm or the current underlying Realm. By contrast, the entry, incumbent and + relevant concepts always refer to a principal Realm. Almost all uses of the "current" + concept need to refer to the current principal Realm as well, with the exception of + 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). If any reference to the "current Realm" exists + in another Web specification, the intention is likely to be to refer to the current + principal Realm.

    Then, the current settings object is the environment settings object of the current - Realm Record.

    + principal Realm
    .

    Similarly, the current global object is the global object of the current Realm Record.

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

    Relevant
    @@ -91793,10 +91937,12 @@ document.querySelector("button").addEventListener("click", bound); data-x="struct">structs. 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 JavaScript Realm where the script is evaluated, which is shared + with other scripts in the same context. Note that, + in the case of module scripts (but not classic scripts) this realm may be a synthetic Realm.

    A record
    @@ -91861,6 +92007,10 @@ document.querySelector("button").addEventListener("click", bound); scripts.

    +

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

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

    @@ -92300,15 +92450,16 @@ document.querySelector("button").addEventListener("click", bound);
  • Fetch the descendants of and link result given settings object, - destination, and visited set. When this asynchronously completes with - final result, asynchronously complete this algorithm with final + destination, visited set, and settings object's Realm. When this asynchronously completes + with final result, asynchronously complete this algorithm with final result.

  • To fetch an import() module script graph given a moduleRequest, a - base URL, a settings object, and some options, run these steps. - The algorithm will asynchronously complete with either null (on failure) or a module - script (on success).

    + base URL, a settings object, some fetch options options and a + module map realm, run these steps. The algorithm will asynchronously complete with + either null (on failure) or a module script (on success).

    1. Let url be the result of resolving a @@ -92343,9 +92494,9 @@ document.querySelector("button").addEventListener("click", bound);

    2. Fetch the descendants of and link result given settings object, - destination, and visited set. When this asynchronously completes with - final result, asynchronously complete this algorithm with final - result.

    3. + destination, visited set and module map realm. When this + asynchronously completes with final result, asynchronously complete this algorithm + with final result.

    To fetch a modulepreload module script graph given a url, a @@ -92371,7 +92522,8 @@ document.querySelector("button").addEventListener("click", bound);

  • Fetch the descendants of and link result given settings object, - destination, and visited set.

  • + destination, visited set, and settings object's Realm.

    Generally, performing these steps will be beneficial for performance, as it @@ -92399,9 +92551,10 @@ document.querySelector("button").addEventListener("click", bound);

  • Fetch the descendants of and link script, given settings object, the - destination "script", and visited set. When this asynchronously - completes with final result, asynchronously complete this algorithm with final - result.

  • + destination "script", visited set, and settings + object's Realm. When this + asynchronously completes with final result, asynchronously complete this algorithm + with final result.

    To fetch a module worker script graph @@ -92601,15 +92754,17 @@ document.querySelector("button").addEventListener("click", bound);

  • Fetch the descendants of and link result given fetch client settings - object, destination, and visited set. When this asynchronously - completes with final result, asynchronously complete this algorithm with final - result.

  • + object, destination, visited set, and settings + object's Realm. When this + asynchronously completes with final result, asynchronously complete this algorithm + with final result.

    To fetch the descendants of and link a module script module - script, given a fetch client settings object, a destination, and a - visited set, run these steps. The algorithm will asynchronously complete with either - null (on failure) or with module script (on success).

    + script, given a fetch client settings object, a destination, a + visited set and a module map realm, run these steps. The algorithm will + asynchronously complete with either null (on failure) or with module script (on + success).

    1. Fetch the descendants of @@ -92634,6 +92789,14 @@ document.querySelector("button").addEventListener("click", bound);

    2. If parse error is null, then:

        +
      1. Let settings object be module map realm's principal Realm's [[HostDefined]] + field.

      2. + +
      3. Set result to the result of finding and possibly cloning the module at url given settings + object and module map realm.

      4. +
      5. Let record be result's record.

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

      8. -
      9. Set script's settings object to settings.

      10. +
      11. Set script's Realm to + settings's Realm.

      12. Set script's base URL to baseURL.

      13. @@ -93047,7 +93211,8 @@ document.querySelector("button").addEventListener("click", bound);
      14. Let script be a new module script that this algorithm will subsequently initialize.

      15. -
      16. Set script's settings object to settings.

      17. +
      18. Set script's Realm to + settings's Realm.

      19. Set script's base URL to baseURL.

      20. @@ -93897,7 +94062,8 @@ dictionary PromiseRejectionEventInit : EventInit
      21. If realm is not null, then let job settings be the settings object for realm. Otherwise, + data-x="concept-realm-settings-object">settings object for the principal Realm of realm. Otherwise, let job settings be null.

        @@ -94288,6 +94454,13 @@ import "https://example.com/foo/../module2.mjs";
      22. Let fetch options be the default classic script fetch options.

      23. +
      24. +

        Let module map realm be the current underlying Realm.

        + +

        In the case of the Realm.prototype.import API the current + underlying Realm is set to the appropriate synthetic realm.

        +
      25. +
      26. If referencingScriptOrModule is not null, then:

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

      28. + +
      29. +

        Set module map realm to referencing script's Realm

        + +

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

        +

      As explained above for HostResolveImportedModule, in the common @@ -94315,8 +94497,8 @@ import "https://example.com/foo/../module2.mjs";

    3. Fetch an import() module script graph given moduleRequest, - base URL, settings object, and fetch options. Wait until the - algorithm asynchronously completes with result.

    4. + base URL, settings object, fetch options and module map + realm. Wait until the algorithm asynchronously completes with result.

    5. Let promise be null. @@ -94345,6 +94527,13 @@ import "https://example.com/foo/../module2.mjs";

    6. Let base URL be settings object's API base URL.

    7. +
    8. +

      Let module map realm be the current underlying Realm.

      + +

      Module map realm could be a synthetic realm in the case + of a call to Realm.prototype.import.

      +
    9. +
    10. If referencingScriptOrModule is not null, then:

      @@ -94360,6 +94549,14 @@ import "https://example.com/foo/../module2.mjs";
    11. Assert: base URL is not null, as referencing script is a classic script or a JavaScript module script.

    12. + +
    13. +

      Set module map realm to referencing script's Realm.

      + +

      Module map realm could be a synthetic realm in the + case of a dynamic import() expression evaluated within a synthetic realm.

      +
    @@ -94377,9 +94574,6 @@ import "https://example.com/foo/../module2.mjs";
    -
  • Let moduleMap be settings object's module map.

  • -
  • Let url be the result of resolving a module specifier given base URL and moduleRequest.[[Specifier]].

  • @@ -94392,6 +94586,83 @@ import "https://example.com/foo/../module2.mjs";
  • Let moduleType be the result of running the module type from module request steps given moduleRequest.

  • +
  • Let resolved module script be the result of finding and possibly cloning the module at url given + moduleType, settings object and module map realm.

  • + +
  • Return resolved module script's record.

  • + + +

    To find and possibly clone a module given a URL, moduleType, + settings object and module map realm, perform the following steps, returning + a module script:

    + +
      +
    1. Let moduleMap be module map realm's module map.

    2. + +
    3. +

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

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

      2. + +
      3. Let parent module map be settings object's module map.

      4. + +
      5. Assert: parent module map[(url, moduleType)] + exist.

      6. + +
      7. Let parent module be parent module map[(url, + moduleType)].

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

      10. + +
      11. Set child module's Realm to + module map realm.

      12. + +
      13. Set child module's base URL to + parent module's base URL.

      14. + +
      15. Set child module's fetch + options to parent module's fetch options.

      16. + +
      17. Let parent parse error be parent module's parse error.

      18. + +
      19. If parent parse error is null, then set child module's parse error null. Otherwise, assert parent + parse error is a SyntaxError instance; set child module's parse error to a new SyntaxError in + module map realm with the same message as parent parse error.

      20. + +
      21. Set child module's error to + rethrow to null.

      22. + +
      23. Let parent record be parent module's record.

      24. + +
      25. Set child module's record to + a new Source Text Module Record { [[Realm]]: module map realm, + [[Environment]]: undefined, [[Namespace]]: undefined, [[Status]]: unlinked, [[EvaluationError]]: + undefined, [[HostDefined]]: child module, [[ECMAScriptCode]]: parent + record.[[ECMAScriptCode]], [[Context]]: empty, [[ImportMeta]]: empty, + [[RequestedModules]]: parent record.[[RequestedModules]], [[ImportEntries]]: + parent record.[[ImportEntries]], [[LocalExportEntries]]: parent + record.[[LocalImportEntries]], [[IndirectExportEntries]]: parent + record.[[IndirectImportEntries]], [[StarExportEntries]]: parent + record.[[StarImportEntries]], [[DFSIndex]]: undefined, [[DFSAncestorIndex]]: undefined + }.

      26. + +
      27. Set moduleMap[(url, moduleType)] to child + module.

      28. +
      +
    4. +
    5. Let resolved module script be moduleMap[(url, moduleType)]. (This entry must exist for us to have gotten to this point.)

    6. @@ -94402,8 +94673,7 @@ import "https://example.com/foo/../module2.mjs";
    7. Assert: resolved module script's record is not null.

      -
    8. Return resolved module script's record.

    9. +
    10. Return resolved module script.

    HostGetSupportedImportAssertions()
    @@ -94417,6 +94687,33 @@ import "https://example.com/foo/../module2.mjs";
  • Return « "type" ».

  • +
    HostInitializeSyntheticRealm(realm)
    + +

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

    + +
      +
    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's [[HostDefined]] field to settings.

    10. +
    + +

    The above algorithm needs to also define the globals in the Realm which have + [Exposed=Realm].

    +

    Event loops

    @@ -95479,7 +95776,7 @@ import "https://example.com/foo/../module2.mjs"; -
  • Let realm be the current Realm Record.

  • +
  • Let realm be the current principal Realm.

  • Let p be a new promise.

  • @@ -97498,7 +97795,7 @@ enum DOMParserSupportedType {
  • If nesting level is greater than 5, and timeout is less than 4, then set timeout to 4.

  • -
  • Let callerRealm be the current Realm Record, and +

  • Let callerRealm be the current principal Realm, and calleeRealm be global's relevant Realm.

  • @@ -126458,6 +126755,9 @@ INSERT INTERFACES HERE
    [JSON]
    The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
    +
    [JSREALMS]
    +
    Realms. Ecma International.
    +
    [LONGTASKS]
    Long Tasks, D. Denicola, I. Grigorik, S. Panicker. W3C.