Skip to content

Create new objects with a Realm #793

Description

@a-sully

From #787 (comment). For example, we need to do this everywhere:

-Let p be a new promise.
+Let p be a new promise in |realm|.

Activity

  1. inexorabletash commented on Nov 23, 2024

    @inexorabletash
    Contributor

    Any time we do "a new Thing" or implicitly create a new object (like "return a TypeError" or "reject promise with...") from "in parallel" steps, steps queued against another task source, or timeline, then we absolutely need to specify the realm. Examples in the current spec where that isn't done include:

    • createContext() - ".. .then queue an ML task with global to reject promise with a "NotSupportedError" DOMException ..."
    • build() - "... then queue an ML task with global to reject promise with an "OperationError" DOMException ..."

    I'm less clear about instances where an exception is thrown or promise is rejected with a new exception during synchronous steps of a method. e.g. in Web IDL it says "When an algorithm says to throw a SomethingError then this means to construct a new JavaScript SomethingError object in the current realm and to throw it, just as the algorithms in ECMA-262 do."

    That implies that we can infer the realm in simple cases. Certainly, lots and lots of specs use realms sparingly, even when they do use them for more interesting cases. Perhaps that's just a lack of rigor, though. We should ask around.

  2. changed the title [-]Create promises with a Realm[/-] [+]Create new objects with a Realm[/+] on Nov 23, 2024
  3. a-sully commented on Nov 23, 2024

    @a-sully
    ContributorAuthor

    Any time we do "a new Thing" or implicitly create a new object

    Updated the title and description to reflect this

  4. inexorabletash commented on Jan 27, 2025

    @inexorabletash
    Contributor
  5. inexorabletash commented on Jan 27, 2025

    @inexorabletash
    Contributor

    @jyasskin points out:

    https://webidl.spec.whatwg.org/#js-creating-throwing-exceptions says to use the "current realm" to create exceptions. https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task will set that via the "global's relevant agent's event loop", where "relevant agent" gets the global's realm.

  6. added a commit that references this issue on Jan 29, 2025
    2139976
  7. added 7 commits that reference this issue on Feb 6, 2025
    2d621f2
    a53ddb8
    f05c744
    c45aa3e
    4ade440
    ec42157
    94bd729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions