Skip to content

Normative updates to the spec, March 2023 #499

@pzuraq

Description

@pzuraq

This issue is a meta issue for tracking a number of normative updates that are being proposed to the spec in the upcoming March plenary.

  1. Remove the dynamic assignment of [[HomeObject]] from decorator method application/evaluation (PR, Issue)

    This dynamic assignment/update of a function's [[HomeObject]] is a new behavior that has not occurred before in the spec, and is even asserted against. It results in unexpected behavior and does not have an actual use-case. This decision was likely due to a misunderstanding of what the MakeMethods purpose was. This change removes the reassignment entirely.

  2. Call decorators with their natural this value instead of undefined (PR, Issue)

    Currently decorators are always called with an undefined this value, even when it might appear that they should have one (e.g. @foo.bar should be called with foo as the receiver). This change threads the receiver through so the decorator can be called with it.

  3. Throw an error if the value passed to addInitializer is not callable (PR)

    addInitializer expects to receive a function, and all of the spec text downstream from it assumes this as well, so this assertion is necessary to ensure that the value is actually callable.

  4. Set the name of the addInitializer function (PR)

    Sets the name of addInitializer, which is currently an empty string.

  5. Remove SetFunctionName from decoration (PR)

    Currently, SetFunctionName is called on the returned decorated methods. This two main problems:

    1. It messes up stack traces, because the actual function name will be different than the code, which would be confusing when trying to debug.
    2. SetFunctionName asserts against ever being called twice for the same method.
  6. "Bind" static accessors directly to the class itself. (PR pending, issue)

    Static accessors are implemented conceptually as a sugar on top of private fields. A getter and setter are generated which access private storage on the same class. For static accessors, this results in them not working when inherited by a child class, since static fields and accessors are not redefined on child classes.

The proposed update is to "bind" static accessors to their original class, e.g. instead of being sugar for:

class A {
  static #x = 42
  static get x() { return this.#x }
  static set x(v) { this.#x = v }
}

They would desugar to:

class A {
  static #x = 42
  static get x() { return A.#x }
  static set x(v) { A.#x = v }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions