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

Merged
merged 1 commit into from
Feb 7, 2019

Conversation

rkirsling
Copy link
Member

Resolves #1392.

@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text needs consensus This needs committee consensus before it can be eligible to be merged. needs data This PR needs more information; such as web compatibility data, “web reality” (what all engines do)… needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Jan 4, 2019
@bakkot
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
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
Copy link
Contributor

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
Copy link
Member Author

rkirsling commented Jan 4, 2019

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

@rkirsling
Copy link
Member Author

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

@ljharb ljharb added has consensus This has committee consensus. and removed needs consensus This needs committee consensus before it can be eligible to be merged. labels Jan 29, 2019
@ljharb ljharb requested review from bterlson, zenparsing, ljharb and a team January 29, 2019 19:01
@rkirsling
Copy link
Member Author

rkirsling commented Jan 30, 2019

Implementation status, just for the record:

@mathiasbynens
Copy link
Member

@rkirsling Are you gonna patch Test262 as well?

@rkirsling
Copy link
Member Author

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

@rkirsling
Copy link
Member Author

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

@ljharb ljharb added has test262 tests and removed needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Jan 30, 2019
@ljharb ljharb requested a review from a team January 30, 2019 20:20
@mathiasbynens
Copy link
Member

…and now it landed in SpiderMonkey as well!

@ljharb ljharb removed the needs data This PR needs more information; such as web compatibility data, “web reality” (what all engines do)… label Feb 1, 2019
joyeecheung pushed a commit to joyeecheung/v8 that referenced this pull request Feb 4, 2019
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 merged commit 8a16cb8 into tc39:master Feb 7, 2019
@rkirsling rkirsling deleted the simplify-annex-b.3.5 branch February 7, 2019 00:07
graalvmbot pushed a commit to oracle/graaljs that referenced this pull request Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants