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: Allow initializers in ForInStatement heads #614

Merged
merged 1 commit into from
Aug 5, 2016

Conversation

bakkot
Copy link
Contributor

@bakkot bakkot commented Jun 20, 2016

Fixes #260.

Per discussion, this adds a section in Annex B with a production for for ( var BindingIdentifier Initializer in Expression) Statement with its original semantics, in light of the usage statistics collected by V8 and the fact that implementers have had to allow this production.

Edit (July 27, 2016): This comment was slightly wrong; it was only added to non-strict code.

@jugglinmike
Copy link
Contributor

We may also want to amend the line-item in Annex E which describes this production.

13.7: Prior to ECMAScript 2015, an initialization expression could appear as
part of the VariableDeclaration that precedes the in keyword. The value of
that expression was always discarded. In ECMAScript 2015, the ForBinding in
that same position does not allow the occurrence of such an initializer.

@bakkot
Copy link
Contributor Author

bakkot commented Jun 20, 2016

The current note in Annex E is actually wrong; the value was not discarded and was observable if the object had no properties or if the rhs Expression referred to the variable declared in the head.

I'm not sure if Annex E is maintaining a running list of changes between all version, or only changes between the current version and previous versions. If the former, I propose we append "In ECMAScript 2017, this is only disallowed in strict mode code." If the latter, it should instead read

Prior to ECMAScript 2015, an initialization expression could appear as part of the VariableDeclaration that precedes the in keyword. In ECMAScript 2017, in strict-mode code the ForBinding in that same position does not allow the occurrence of such an initializer.

@jugglinmike
Copy link
Contributor

Oh, also: it would be helpful if the section that this extension concerns included a reference, like in Runtime Semantics: PropertyDefinitionEvaluation

@bakkot
Copy link
Contributor Author

bakkot commented Jun 20, 2016

@jugglinmike, this extension augments 8 different sections, mostly in trivial ways (i.e. adding the new production to the list of possible IterationStatement productions) and always strictly additively. Should there be a note in all of them?

@jugglinmike
Copy link
Contributor

It may be sufficient to document the extension in a NOTE for The for-in and for-of Statements. Personally, I think duplicating the note in relevant sections would be preferable, though.

Still a third option would be to write all of this text in the main specification itself, and then introduce an early SyntaxError for it that could be disabled by Annex B. I think there is some precedent for disabled grammar like this; the ArrowParameters supports yield so that a SyntaxError can be unilaterally applied to its presence, strict mode or no.

Whatever the case, my motivation is discoverability. I've been surprised by annex B extensions in the past, and I think an explicit reference from the "mainline" text is helpful in avoiding this (I'm proposing an unrelated one in gh-607). I'm sure @bterlson and @allenwb have a much clearer idea of how this ought to be executed.

@littledan
Copy link
Member

I like @jugglinmike 's idea of a NOTE. For tc39/ecma402#84 , the plan is to make a new facility in 402 to write the compatibilty fix in-line, but still marked as normative-optional. Maybe we should consider doing something like that in 262 as well if it works well for that change. This would be a purely editorial and not semantic change.

@jugglinmike
Copy link
Contributor

LabelledStatement has a better example of the "restricted grammar" approach I suggested above:

LabelledItem : FunctionDeclaration

  • It is a Syntax Error if any source text matches this rule.

NOTE An alternative definition for this rule is provided in B.3.2.

@bakkot
Copy link
Contributor Author

bakkot commented Jun 30, 2016

That seems reasonable, though I find it a little odd to give static and runtime semantics in the main text for a production which is forbidden unless Annex B is applied. This is how labelled function declarations are done.

I'm going to hold off rewriting it pending more feedback. It'll be fairly straightforward either way.

@bterlson
Copy link
Member

bterlson commented Jul 1, 2016

I am not sure what the intent of Annex E is either. I think there is value in keeping a running list, though, so unless there are objections, let's go with that! Should update the Annex E copy to be more accurate. @bakkot I like your copy, want to add it to this PR?

In terms of whether to do a note in all the relevant sections, write the spec text inline, or use the nascent 402 convention for normative-optional, I'm ok with just doing the notes (in all the relevant places). I don't mind the labeled function declaration convention for small things, but I'm not much a fan of adding a ton of semantics that aren't used unless an annex B extension is in play. @bakkot want to just add the notes? Then this should be good to go.

@bakkot bakkot force-pushed the forin-initializers branch from d006120 to b482c98 Compare July 6, 2016 17:08
@bakkot
Copy link
Contributor Author

bakkot commented Jul 6, 2016

@bterlson, I've added notes to all affected sections and updated the note in Annex E (with a slightly different wording than proposed above).

@bakkot
Copy link
Contributor Author

bakkot commented Jul 23, 2016

We can maybe get away with doing this only in sloppy mode, since that's what Chrome's currently shipping.

@concavelenz
Copy link

I'm never really seen the need to drop it at all. It seems like a lot of
effort over nothing.

On Jul 22, 2016 5:54 PM, "Kevin Gibbons" [email protected] wrote:

We can maybe get away with doing this only in sloppy mode, since that's
what Chrome's currently shipping.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#614 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABMDKkLxwu6pO3J0zE893OfU9Bhz9MoUks5qYWZEgaJpZM4I5-2I
.

@bterlson bterlson added the needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 label Jul 26, 2016
@bterlson
Copy link
Member

We have consensus for this, modulo: should only be allowed in strict mode, needs test262 collateral.

ianwjhalliday pushed a commit to ianwjhalliday/ChakraCore that referenced this pull request Jul 26, 2016
bakkot added a commit to bakkot/test262 that referenced this pull request Jul 27, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
bakkot added a commit to bakkot/test262 that referenced this pull request Jul 27, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
@bakkot
Copy link
Contributor Author

bakkot commented Jul 27, 2016

I've added tests. The spec text as written only adds the new production in non-strict code (although I invite people who have written more spec text to review that).

@saambarati
Copy link

saambarati commented Jul 28, 2016

I haven't looked at the spec text (so maybe this is in there), but want to emphasize that we should also disallow let/const and destructuring for var. That is, we should only allow
for (var {ident} = {expr} in ...)

@saambarati
Copy link

I think we can get away with this restriction because this has been JSC's behavior for a long time.

@bakkot
Copy link
Contributor Author

bakkot commented Jul 28, 2016

saambarati, that is indeed the case - see slides.

bakkot added a commit to bakkot/test262 that referenced this pull request Jul 28, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
bakkot added a commit to bakkot/test262 that referenced this pull request Aug 1, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
bakkot added a commit to bakkot/test262 that referenced this pull request Aug 1, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
leobalter pushed a commit to tc39/test262 that referenced this pull request Aug 2, 2016
These were re-introduced in sloppy mode per
tc39/ecma262#614
@leobalter
Copy link
Member

The tests are merged.

@bterlson bterlson removed the needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 label Aug 5, 2016
@bterlson bterlson merged commit 05b05f1 into tc39:master Aug 5, 2016
@bakkot bakkot deleted the forin-initializers branch August 5, 2016 17:47
jaychsu added a commit to jaychsu/ecma262 that referenced this pull request Sep 7, 2016
* upstream/master: (301 commits)
  Editorial: remove mistakenly committed change to eval-related super errors
  Normative: Point to the latest version of UTR15 (tc39#681)
  Meta: update ecmarkup version dependency (tc39#682)
  Editorial: Update a variable name in Annex B.3.3.1 to refer to the proper variable in FunctionDeclarationInstantiation's body, and add warning comments by all the spec algorithms monkey-patched by Annex B so that future refactoring doesn't create broken/dangling references in Annex B. (tc39#677)
  Meta: update ecmarkup version dependency
  Editorial: dfn-ify 'goal symbol'
  Editorial: TypeArray -> TypedArray (tc39#675)
  Editorial: Correct a wrong cross-reference in Annex C (tc39#674)
  Editorial: tweak whitespace and articles (tc39#667)
  Editorial: Tweak EnumerateObjectProperties informative definition (tc39#656)
  Editorial: Rename variable (indx --> index) (tc39#658)
  Editorial: Fix reference in ScriptEvaluation (tc39#659)
  Editorial: Consistent `undefined or null` order (tc39#660)
  Editorial: Refactor Array.prototype.toLocaleString (tc39#662)
  Editorial: Tweak Array.prototype.join (tc39#661)
  Simplify description of CreateImmutableBinding (tc39#654)
  Normative: Resolve template argument references (tc39#609)
  Editorial: Refactor Array.prototype.join (tc39#638)
  Editorial: contains --> Contains in ModuleListItem SS
  Normative: Allow initializers in ForInStatement heads (tc39#614)
  ...
donnagf referenced this pull request in pvdz/zeparser3 Apr 15, 2019
jmdyck added a commit to jmdyck/ecma262 that referenced this pull request May 9, 2021
PR tc39#614 defined (in Annex B) an additional form for ForInOfStatement.
Performing ForInOfLoopEvaluation on it ends with a call to ForIn/OfBodyEvaluation,
with |BindingIdentifier| as first arg, passed to the _lhs_ param.
ForIn/OfBodyEvaluation (at step 6.g.i.1) evaluates this param,
but there's no definition of Evaluation for |BindingIdentifier|.
This PR adds the necessary definition.

(The new definition basically just duplicates the one for ForBinding.
In fact, if this part of Annex B is merged into the main spec,
the definition for ForBinding can be dropped,
since it can just chain to this new definition.)
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Aug 25, 2021
PR tc39#614 defined (in Annex B) an additional form for ForInOfStatement.
Performing ForInOfLoopEvaluation on it ends with a call to ForIn/OfBodyEvaluation,
with |BindingIdentifier| as first arg, passed to the _lhs_ param.
ForIn/OfBodyEvaluation (at step 6.g.i.1) evaluates this param,
but there's no definition of Evaluation for |BindingIdentifier|.
This PR adds the necessary definition.

(The new definition basically just duplicates the one for ForBinding.
In fact, if this part of Annex B is merged into the main spec,
the definition for ForBinding can be dropped,
since it can just chain to this new definition.)
jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Sep 14, 2021
PR tc39#614 defined (in Annex B) an additional form for ForInOfStatement.
Performing ForInOfLoopEvaluation on it ends with a call to ForIn/OfBodyEvaluation,
with |BindingIdentifier| as first arg, passed to the _lhs_ param.
ForIn/OfBodyEvaluation (at step 6.g.i.1) evaluates this param,
but there's no definition of Evaluation for |BindingIdentifier|.
This PR adds the necessary definition.

Rather than add it to the annex that defines the additional form of ForInOfStatement,
this commit substitutes it for the (main body) definition of
`Evaluation` for `ForBinding : BindingIdentifier`,
allowing the latter to chain to the new definition,
since it has the same semantics.
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Sep 14, 2021
PR tc39#614 defined (in Annex B) an additional form for ForInOfStatement.
Performing ForInOfLoopEvaluation on it ends with a call to ForIn/OfBodyEvaluation,
with |BindingIdentifier| as first arg, passed to the _lhs_ param.
ForIn/OfBodyEvaluation (at step 6.g.i.1) evaluates this param,
but there's no definition of Evaluation for |BindingIdentifier|.
This PR adds the necessary definition.

Rather than add it to the annex that defines the additional form of ForInOfStatement,
this commit substitutes it for the (main body) definition of
`Evaluation` for `ForBinding : BindingIdentifier`,
allowing the latter to chain to the new definition,
since it has the same semantics.
mathiasbynens pushed a commit to mathiasbynens/ecma262 that referenced this pull request Oct 18, 2021
PR tc39#614 defined (in Annex B) an additional form for ForInOfStatement.
Performing ForInOfLoopEvaluation on it ends with a call to ForIn/OfBodyEvaluation,
with |BindingIdentifier| as first arg, passed to the _lhs_ param.
ForIn/OfBodyEvaluation (at step 6.g.i.1) evaluates this param,
but there's no definition of Evaluation for |BindingIdentifier|.
This PR adds the necessary definition.

Rather than add it to the annex that defines the additional form of ForInOfStatement,
this commit substitutes it for the (main body) definition of
`Evaluation` for `ForBinding : BindingIdentifier`,
allowing the latter to chain to the new definition,
since it has the same semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants