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
Lexical redeclarations in block- and switch-statements #1023
Conversation
---*/ | ||
|
||
|
||
switch (0) { case 1: async function f() {} default: function f() {} } |
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.
@anba, I'm having a hard time to find the spec parts saying the function (and async function) declaration names are added to the Lexical Scope.
Can you help me pointing to where I'm missing there? Thanks.
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.
I'm taking the table 27 as the only reference for it. The [[Environment]]
as the lexical environment where the function is bound to.
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 https://tc39.github.io/ecma262/#sec-switch-statement-static-semantics-lexicallydeclarednames, all lexically declared names from the different case clauses are combined.
For each case clause, the LexicallyDeclaredNames definition from https://tc39.github.io/ecma262/#sec-block-static-semantics-lexicallydeclarednames applies, which has:
StatementListItem : Declaration
- Return the BoundNames of Declaration.
And in https://tc39.github.io/ecma262/#prod-Declaration we've got:
Declaration[Yield, Await] : HoistableDeclaration[?Yield, ?Await, ~Default]
And in https://tc39.github.io/ecma262/#prod-HoistableDeclaration:
HoistableDeclaration[Yield, Await, Default] : FunctionDeclaration[?Yield, ?Await, ?Default]
And the BoundNames of a FunctionDeclaration is its BindingIdentifier https://tc39.github.io/ecma262/#sec-function-definitions-static-semantics-boundnames.
And there's also B3.3.5 (https://tc39.github.io/ecma262/#sec-switch-duplicates-allowed-static-semantics) which allows duplicate FunctionDeclarations in sloppy mode in switch-statements.
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.
Thank you very much! I really appreciate as this part has got tricky for me.
if len(includes): | ||
lines += ['includes: ' + yaml.dump(includes).strip()] | ||
|
||
if case_values['meta'].get('negative'): | ||
if self.attribs['meta'].get('negative'): | ||
raise Exception('Cannot specify negative in case and template file') |
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.
nice
Improves test coverage for lexical redeclarations in block- and switch-statements.
To reduce the number of case/template files, I've modified the test file generator to allow to specify the "negative" tag in template files.
Ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1359575