Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we attach a getter/setter to the object? #1

Open
mgaudet opened this issue Dec 2, 2024 · 1 comment
Open

Do we attach a getter/setter to the object? #1

mgaudet opened this issue Dec 2, 2024 · 1 comment

Comments

@mgaudet
Copy link
Collaborator

mgaudet commented Dec 2, 2024

It's simpler and more straightforward to not use a getter.

In principle with a getter you could defer the work of formatting a stack trace until it's finally consumed.

Bug 1886820 has some discussion around this. Particularly, Matthieu Hoffman has some opinions against getters

@mhofman
Copy link
Member

mhofman commented Dec 3, 2024

I am not opposed to an accessor own property but given these would interact with private state associated with potentially arbitrary objects I would want us to be careful in order limit its abuse as a WeakMap equivalent.

Here is potentially a way it could work:

  • Error.captureStackTrace would attempt to define the stack property on the target. If it fails no private field would be added. Depending on timing of the stabilize proposal, if the object is fixed, no private field would be added either.
  • the getter returns the value of the private field if it exists, or undefined otherwise
  • the setter would delete the private field and define a data property on the object with the value provided.

I believe this would allow using shared accessor without making them a generic global WeakMap instance or other kind of hidden communication channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants