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: Treat IterationStatements uniformly in Annex B.3.5. #1393

Merged
merged 1 commit into from Feb 7, 2019

Conversation

Projects
None yet
7 participants
@rkirsling
Copy link
Member

rkirsling commented Jan 4, 2019

Resolves #1392.

@bakkot

This comment has been minimized.

Copy link
Contributor

bakkot commented Jan 4, 2019

It is a Syntax Error if any element of the BoundNames of |CatchParameter| also occurs in the VarDeclaredNames of |Block| unless |CatchParameter| is CatchParameter : BindingIdentifier and that element is only bound by a |VariableStatement|, or the |VariableDeclarationList|, |ForBinding|, or |BindingIdentifier| of an |IterationStatement|.

Are there any other cases? I'm not sure the bolded part of this rule is ever unsatisfied.

@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 4, 2019

I think you're right, since function declarations add to a block's LexicallyDeclaredNames and not to its VarDeclaredNames.

I'm a bit confused about what this implies for the second instance though. Technically, what's written there is not exhaustive—if it read HoistableDeclaration instead of FunctionDeclaration, then we could delete the entire sentence, but as it stands it would not allow, e.g., GeneratorDeclaration.

However, it appears that not a single engine actually distinguishes among HoistableDeclarations here!

// SyntaxError in V8, SM, XS; permitted in JSC, CH
try {} catch (e) { function e() {} }
try {} catch (e) { function* e() {} }
try {} catch (e) { async function e() {} }
try {} catch (e) { async function* e() {} }

// permitted in V8, SM, CH; SyntaxError in JSC, XS
try { throw 1; } catch (e) { eval('function e() {}'); }
try { throw 1; } catch (e) { eval('function* e() {}'); }
try { throw 1; } catch (e) { eval('async function e() {}'); }
try { throw 1; } catch (e) { eval('async function* e() {}'); }

// (Side note: CH doesn't actually have async generators right now.)

So perhaps web reality suggests that we could do away with that whole sentence after all? 🤔

@syg

This comment has been minimized.

Copy link
Member

syg commented Jan 4, 2019

Your example gives rise to another piece of esoterica: currently Annex B.3.3 interaction with B.3.5 means the following, which may or may not be surprising to you depending on how long you've stared at the abyss:

function foo() { try { throw 1; } catch (e) { { function e() {} } } print(e); }
foo() // prints "function e() {}"

but

function bar() { try { throw 1; } catch (e) { function e() {} } print(e); } // SyntaxError
@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 4, 2019

@syg Thankfully though, that too applies equally to the four HoistableDeclaration types. 😄

@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 5, 2019

Made @bakkot's suggested simplification as well as the web reality simplification from #1393 (comment).

@ljharb ljharb requested review from bterlson , zenparsing , ljharb and tc39/ecma262-editors Jan 29, 2019

@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 30, 2019

@mathiasbynens

This comment has been minimized.

Copy link
Member

mathiasbynens commented Jan 30, 2019

@rkirsling Are you gonna patch Test262 as well?

@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 30, 2019

@mathiasbynens tc39/test262#2023 is just awaiting the green button. 😄

@rkirsling

This comment has been minimized.

Copy link
Member Author

rkirsling commented Jan 30, 2019

Tests merged, two implementations landed. 🎊
(Thanks @mathiasbynens!)

@ljharb ljharb added has tests and removed needs tests labels Jan 30, 2019

@ljharb

ljharb approved these changes Jan 30, 2019

@ljharb ljharb requested a review from tc39/ecma262-editors Jan 30, 2019

aperezdc pushed a commit to aperezdc/webkit that referenced this pull request Jan 31, 2019

ross.kirsling@sony.com
Remove FIXME for Annex B.3.5's "for-of var" subcase.
Rubber-stamped by Yusuke Suzuki.

This subcase is removed from the spec in tc39/ecma262#1393.

* parser/Parser.h:
(JSC::Parser::declareHoistedVariable):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@240686 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@mathiasbynens

This comment has been minimized.

Copy link
Member

mathiasbynens commented Feb 1, 2019

…and now it landed in SpiderMonkey as well!

@ljharb ljharb removed the needs data label Feb 1, 2019

joyeecheung pushed a commit to joyeecheung/v8 that referenced this pull request Feb 4, 2019

[parser] Allow try {} catch (e) { for (var e of x) {} }
This patch changes the parser to allow for-of initializer
var-redeclaration of non-destructured catch parameters.

Previously, the spec allowed var-redeclaration of a
non-destructured catch parameter…

    try {} catch (e) { var e; }

…except in the particular case where the var declaration is
a for-of initializer:

    try {} catch (e) { for (var e of whatever) {} }

tc39/ecma262#1393 removes this strange
exceptional case. This patch implements that change.

BUG=v8:8759

Change-Id: Ia4e33ac1eab89085f8a5fdb547f479cfa38bbee5
Reviewed-on: https://chromium-review.googlesource.com/c/1444954
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59209}

@ljharb ljharb assigned ljharb and unassigned bterlson Feb 6, 2019

@ljharb ljharb force-pushed the rkirsling:simplify-annex-b.3.5 branch from 7c64563 to 8a16cb8 Feb 7, 2019

@ljharb ljharb merged commit 8a16cb8 into tc39:master Feb 7, 2019

1 check was pending

continuous-integration/travis-ci/push The Travis CI build is in progress
Details

@rkirsling rkirsling deleted the rkirsling:simplify-annex-b.3.5 branch Feb 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment