Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Field named "constructor" #19

Closed
waldemarhorwat opened this issue Jul 12, 2017 · 9 comments
Closed

Field named "constructor" #19

waldemarhorwat opened this issue Jul 12, 2017 · 9 comments

Comments

@waldemarhorwat
Copy link

What is supposed to happen when a field with the name "constructor" is present? The property seems to be silently dropped.

Furthermore, this area of the proposal is currently ill-formed. PropName is applied to things on which it's not well-defined.

@littledan
Copy link
Member

I don't see why a field named constructor (whether it's static or instance) would need any special treatment. We talked about special treatment for fields named __proto__ in the past, but really, there's no particular interaction in either case. If there's a public instance field named constructor, then a constructor property is simply added to the instance with [[DefineOwnProperty]] at the appropriate time in the [[Construct]] sequence. You can still get at the "real" constructor through instance.__proto__.constructor. Do you think we should ban this, though, to avoid confusion?

There's definitely a bug about PropName being misapplied, which I see in one place: when prohibiting static fields named prototype. I'll fix that up; thanks for the catch.

@littledan
Copy link
Member

What do you think of this fix?

@waldemarhorwat
Copy link
Author

It's not fixed. The PropName call and disallowance of "constructor" I was referring to are coming from NonConstructorMethodDefinitions, which is called by ClassDefinitionEvaluation.

@waldemarhorwat
Copy link
Author

Huh?

https://tc39.github.io/proposal-class-fields/#runtime-semantics-class-definition-evaluation
calls NonConstructorMethodDefinitions, which calls PropName on something on which it's not defined. And it will silently drop any fields named constructor.

@rwaldron
Copy link
Contributor

I was providing links to the sections you mentioned in your comment, for others that might read this thread.

@littledan
Copy link
Member

@waldemarhorwat Thanks, I wasn't thinking about that path (but I believe the other one was a bug as well); will fix.

littledan added a commit that referenced this issue Jul 14, 2017
Fields named "constructor" should not be omitted from processing. There
were previously a couple spec text bugs that led to this occurring (or
rather, reaching undefined spec algorithms).

Addresses the remaining point in #19
@waldemarhorwat
Copy link
Author

NonConstructorElementDefinitions currently starts with:
If ClassElement is any of ClassElement:; , FieldDefinition:; or , return a new empty List.
I don't know what that is referring to; that doesn't parse and there are no such grammar productions.

@littledan
Copy link
Member

@waldemarhorwat Thanks for pointing this out; I should've checked the generated output more closely (the colon doesn't appear in the source but was inserted by grammardown). Uploading a fix in a minute.

littledan added a commit that referenced this issue Jul 19, 2017
Previously, messy wording and grammardown syntax was used.

Addresses an issue in #19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants