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

Normative: Remove class decorator access to private names #151

Merged
merged 1 commit into from
Sep 26, 2018

Conversation

littledan
Copy link
Member

@littledan littledan commented Sep 16, 2018

This patch makes it so that class decorators do not see private
class elements. With this patch, only element decorators have
the ability to do metaprogramming on private class elements.

For field/method decorators, granting access to the private name
seems syntactically clear and implied by the construct. There
are also several critical use cases, including:

  • Limited-capability accessors (@reader)
  • Observation pattern (@tracked)
  • Friends/testable (@testable)

For access from class decorators to private, different people
have had different intuitions: Some expect access, while others
say it violates privacy. A workaround here, under this patch,
is to use an element decorator for each private element, rather
than a class decorator, to accomplish the same thing. This
may be ugly, but it works for all the use cases I'm aware of.

As a possible follow-on proposal, a specifically "trusted"
type of decorator could be created, though the details are unclear.

See #133

This patch makes it so that class decorators do not see private
class elements. With this patch, only element decorators have
the ability to do metaprogramming on private class elements.

For field/method decorators, granting access to the private name
seems syntactically clear and implied by the construct. There
are also several critical use cases, including:
- Limited-capability accessors (@reader)
- Observation pattern (@Tracked)
- Friends/testable (@testable)

For access from class decorators to private, different people
have had different intuitions: Some expect access, while others
say it violates privacy. A workaround here, under this patch,
is to use an element decorator for each private element, rather
than a class decorator, to accomplish the same thing. This
may be ugly, but it works for all the use cases I'm aware of.

As a possible follow-on proposal, a specifically "trusted"
type of decorator could be created, though the details are unclear.

See #133
@littledan
Copy link
Member Author

@erights Is this what you were picturing for the limitations on the use of private names?

@erights
Copy link

erights commented Sep 16, 2018

From your description in your comment above, yes, thanks!!

Regarding the actual PR, I do not have, or do not remember, enough understanding of the surrounding context to check that it corresponds to your description. For lack of time, I must leave that to you and other reviewers.

@littledan
Copy link
Member Author

OK, note that we still don't have internal consensus on this PR; Yehuda was pretty concerned about it when we discussed it. I just put this up to make the discussion more concrete.

@littledan
Copy link
Member Author

Achieved consensus at the September 2018 TC39 meeting.

@littledan littledan merged commit 2d8ef3f into master Sep 26, 2018
littledan added a commit that referenced this pull request Jan 9, 2019
littledan added a commit that referenced this pull request Jan 9, 2019
littledan added a commit that referenced this pull request Jan 11, 2019
Initially, the decorators proposal had class descriptors which
contained an elements array with public and private elements.
Later, concerns were raised about exposing this private information
unexpectedly (#133), and this access was removed (#151).

However, this patch caused a problem: private field initializers
were accidentally sorted after public field initializers, an observable
and counterintuitive change (#183). Halfway solutions (#184) did
not really work out; we added back the full element support
in #133 (comment) .

Although we believe that it makes sense for decorators to be able
to see into class bodies, including private, and there are many
important use cases (for both public and private, #192), this support
doesn't have strict consensus in committee, so this patch serves
as a conservative option in case including elements is unacceptable.

This is not the preferred alternative, but it's a well-articulated
backup plan. I'm writing this out in advance in the interest of time,
to ensure that we have a path to Stage 3 and that this does not block
things.
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

Successfully merging this pull request may close these issues.

3 participants