tc39 / proposal-static-class-features

The static parts of new class features, in a separate proposal
https://arai-a.github.io/ecma262-compare/?pr=1668
127 stars 27 forks source link

Missing changes for ClassFieldDefinitionEvaluation #38

Closed leobalter closed 3 years ago

leobalter commented 6 years ago

Runtime Semantics: ClassElementEvaluation calls ClassFieldDefinitionEvaluation with "static" and homeObject as parameters. Although, this proposal is not showing the diff of ClassFieldDefinitionEvaluation here or in the class fields proposal text.

This was probably lost in the previous changes splitting the proposal.

leobalter commented 6 years ago

same for DefineField/DefineClassElement

bergus commented 4 years ago

Do I understand correctly that this is about the behaviour discussed here

[…] static field initializer use class scope with this bound to the constructor object. super, arguments, and new.target should be disallowed as early errors in those initializers. Also, no yield or await.

[Yes, I am] saying that static field initializers are currently spec'ed to evaluate as-if they were static methods that have their [[HomeObject]] set to the constructor?

Or should I create a separate issue abut the missing early error specification?

rbuckton commented 3 years ago

Note that the current v8 implementation of static fields does not treat new.target as an early error, and returns undefined instead.

rbuckton commented 3 years ago

The behavior of new.target for static field initializers is also important to the static {} initializers proposal. We should ensure we have consistent semantics here.

littledan commented 3 years ago

Apologies for my delay in responding to this thread. My intention was always that new.target be undefined in this case, and I believe that's what the current specification text does (since it simply acts like a method, and in methods, new.target is undefined), even if @allenwb had a different opinion.

littledan commented 3 years ago

In the rebased, unified PR https://github.com/tc39/ecma262/pull/1668 (diff) it is clear that new.target is undefined, see ClassFieldDefinitionEvaluation where initializers are created as a method, and DefineField where it is called as such. In methods, new.target is undefined. There is no special early error for new.target in field initializers.