This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Ban new.target and arguments from initializers #41
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,18 @@ <h1>|PublicFieldDefinition|</h1> | |
</emu-grammar> | ||
</emu-clause> | ||
|
||
<emu-clause id="public-field-definition-early-errors"> | ||
<h1>Static Semantics: Early Errors</h1> | ||
PublicFieldDefinition : | ||
PropertyName[?Yield] Initializer? | ||
<emu-grammar> | ||
</emu-grammar> | ||
<emu-alg> | ||
1. It is a SyntaxError if |Initializer| contains |NewTarget|. | ||
1. It is a SyntaxError if |Initializer| contains an |Identifier| with the StringValue `"arguments"`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too, if that wasn't clear. |
||
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="static-semantics-class-public-fields"> | ||
<h1>Static Semantics: ClassPublicFields</h1> | ||
|
||
|
@@ -101,6 +113,8 @@ <h1>InitializePublicInstanceFields ( _O_, _constructor_ )</h1> | |
1. Assert: Assert _constructor_ is an ECMAScript function object. | ||
1. Let _lex_ be the Lexical Environment of the running execution context. | ||
1. Let _initializerEnv_ be NewFunctionEnvironment ( _constructor_, *undefined* ). | ||
1. Perform ! _envRec_.CreateImmutableBinding(`"arguments"`, ~false~). | ||
1. Perform ! _envRec_.InitializeBinding(`"arguments"`, ~undefined~). | ||
1. Let _initializerEnvRec_ be the value of _initializerEnv_'s EnvironmentRecord. | ||
1. Perform _initializerER_.BindThisValue ( _O_ ). | ||
1. Set the running execution context's LexicalEnvironment to _initializerEnv_. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to use
Contains
instead ofcontains
.Contains
is a formally defined spec algorithm.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean. The spec defines "contains" formally, but it's consistently used in lower case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the definition (and usage) of
Contains
in this section: https://tc39.github.io/ecma262/#sec-static-semantic-rulesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see there are a couple Contains usages, but it's mostly contains. It doesn't matter which one is used; probably the spec could use an editorial change to normalize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current state, this and the below line are poorly enough specified that I would object to the proposal's advancement. I legitimately do not know what is meant by each of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that advancement right now means Stage2 -- which doesn't require finalized spec text (i.e. spec text can have TODOS and require editorial work so long as the major aspects of it are in place)
But of course we should address your concerns: The purpose here is to specify that it is a static error if
new.target
orarguments
is syntactically present in the initializer position. Is there more context around your misunderstanding you can provide?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summarising the offline discussion I had with @jeffmo.
Contains
operation is different from the natural usage of "contains" in that it does not cross function boundaries.new.target
to be disallowed within the initialiser, regardless of function boundaries; I think this is not a great decision.arguments
to be disallowed only up to function boundaries (Contains
semantics); I think this is a good decision.arguments
restriction in terms ofContains
. We'll need a new spec operation (ContainsArguments
?) to do this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. I didn't realize that detail. Still, I think if we agree on what the semantics should be, we don't need to get every little detail like this worked out before Stage 2.