Closed leobalter closed 3 years ago
same for DefineField/DefineClassElement
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
, andnew.target
should be disallowed as early errors in those initializers. Also, noyield
orawait
.[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?
Note that the current v8 implementation of static fields does not treat new.target
as an early error, and returns undefined
instead.
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.
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.
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.
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.