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

Annex B 3: FunctionDeclaration in LabelledStatement in, e.g., IterationStatement? #480

Closed
littledan opened this issue Mar 17, 2016 · 4 comments

Comments

@littledan
Copy link
Member

With all of Annex B 3 in effect, it seems like the syntax permits statements like this in sloppy mode:

for (a in b) x: function y() {}

This is based on Annex B 3.2 https://tc39.github.io/ecma262/#sec-functiondeclarations-in-ifstatement-statement-clauses, which permits FunctionDeclarations as the LabelledItem in a LabelledStatement in sloppy mode. LabelledStatements are Statements, so they are permitted as the body of an IterationStatement.

What are the semantics of such a usage? The only guide I see is Annex B 3.4 https://tc39.github.io/ecma262/#sec-functiondeclarations-in-ifstatement-statement-clauses which says that FunctionDeclarations as the body of an IfStatement act like they are enclosed in a block. But I don't see any of this logic for LabelledStatements.

I see a couple possibilities:

  • Annex B 3.2 could be made more strict by making a second type of LabelledStatement, which is only permitted as a StatementListItem and not as a Statement, which allows FunctionDeclaration as the LabelledItem, and the ordinary LabelledStatement could be left alone
  • The spec could explicitly give Annex B 3.4-style semantics to a whole bunch more constructs.

Based on the general design of Annex B, trying to be minimal, I think we might want to go with the first option. Thoughts?

@bterlson @allenwb @jugglinmike

@allenwb
Copy link
Member

allenwb commented Mar 17, 2016

See 13.7.1.1 and 13.6.1 which make usage of a labelled function illegal in those contexts.

Perhaps there should be a NOTE in B.3.2 that references back to those restrictions.

@littledan
Copy link
Member Author

Thanks @allenwb ! That resolves it; I guess this is the same as my first option.

@syg
Copy link
Contributor

syg commented Sep 26, 2017

All of Firefox, Chrome, Safari, and Edge currently still allow labelled function declarations under if, with, and loop statements in sloppy mode.

Do we know for sure if this is web compatible? I strongly suspect yes, but it seems like we still don't know.

Please re-close if there is an actual shipping implementation of this.

@syg syg reopened this Sep 26, 2017
@syg
Copy link
Contributor

syg commented Sep 28, 2017

I completely tested the wrong thing, and I am sorry for alerting people.

@syg syg closed this as completed Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants