Skip to content

Using a set/get accessor causes a runtime error if the descriptor is not yet initialized #12905

@dragomirtitian

Description

@dragomirtitian

Bug Report

Current behavior
When accessing a get /set accessor before it's descriptor is created by the emitted code causes the error TypeError Cannot read property 'get' of undefined

REPL

Input Code

class AA {
  static #x = new AA();
  static get #y() { return 0; }
  static set #y(value) {  }
  constructor() {
    // Either will cause the error
    console.log(AA.#y);
    //AA.#y = 10 
  }
}

Expected behavior
This should work. It works in node.

Possible Solution
Reorder the emit to put private static accessors before fields. Accessor declarations do not have side effects so it is safe to execute them first. After, we can emit static fields, which can have side effects, safely, and any dependency on the static private accessors will work correctly.

Metadata

Metadata

Assignees

Labels

Spec: Private MethodsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions