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

Lexical redeclarations in block- and switch-statements #1023

Merged
merged 4 commits into from May 5, 2017

Conversation

anba
Copy link
Contributor

@anba anba commented May 4, 2017

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

---*/


switch (0) { case 1: async function f() {} default: function f() {} }
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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

  1. 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.

Copy link
Member

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@leobalter leobalter merged commit 9481020 into tc39:master May 5, 2017
@anba anba deleted the redeclaration branch June 25, 2020 09:04
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

Successfully merging this pull request may close these issues.

None yet

2 participants