Closed
Bug 1216623
Opened 9 years ago
Closed 9 years ago
ES6 scoping: In `for(let x=EXPR;;)`, x is not visible in EXPR
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla45
People
(Reporter: jorendorff, Assigned: jorendorff)
References
(Blocks 1 open bug)
Details
Attachments
(3 files)
42.61 KB,
patch
|
Waldo
:
review+
|
Details | Diff | Splinter Review |
5.28 KB,
patch
|
fitzgen
:
review+
ttaubert
:
review+
gps
:
review+
MattN
:
review+
|
Details | Diff | Splinter Review |
101.52 KB,
patch
|
Details | Diff | Splinter Review |
No description provided.
Assignee | ||
Updated•9 years ago
|
Assignee: nobody → jorendorff
Comment 1•9 years ago
|
||
Uh, I'd prefer to take this and deal with all the for-loop stuff at once. Do you mind? The monolith is not easily split up, and everything would benefit from correcter handling of for-loop scoping.
Comment 2•9 years ago
|
||
bug 1069480 contains this and other examples where for and for-in/of loop scoping does not match ES2015. See the "testForRhs()" function in bug 1069480.
Assignee | ||
Comment 3•9 years ago
|
||
Attachment #8677044 -
Flags: review?(jwalden+bmo)
Assignee | ||
Comment 4•9 years ago
|
||
This patch may not make any sense without the epic refactoring of BytecodeEmitter::emitVariables() in bug 1217001. (In reply to Jeff Walden [:Waldo] (remove +bmo to email) from comment #1) > Uh, I'd prefer to take this and deal with all the for-loop stuff at once. > Do you mind? The monolith is not easily split up, and everything would > benefit from correcter handling of for-loop scoping. I didn't see this until I had already uploaded the patch -- honest! The way I split it was to fix the scoping in this bug, across for(;;), for-in, and for-of loops. I left TDZ enforcement (bug 1069480) and fresh bindings in for-in/of loops (bug 449811) for another day.
Depends on: 1217001
Assignee | ||
Comment 5•9 years ago
|
||
$ hg diff -r .^ frontend | diffstat 8 files changed, 96 insertions(+), 150 deletions(-) I sure hope this patch doesn't break everything, because I'm awfully happy with how it turned out. Scope freshening is now entirely in the emitter. The parser doesn't know about it. Wrapping the whole for-loop in a LEXICALSCOPE node just worked.
Comment 6•9 years ago
|
||
Comment on attachment 8677044 [details] [diff] [review] In `for (let ...)` loops, evaluate initializers in the scope of the variables being initialized Review of attachment 8677044 [details] [diff] [review]: ----------------------------------------------------------------- This is surprisingly not bad, and tracking the stuff I'd already been doing pretty closely. Nice! ::: js/src/builtin/ReflectParse.cpp @@ +2641,5 @@ > RootedValue stmt(cx); > if (!statement(pn->pn_right, &stmt)) > return false; > > + if (head->isKind(PNK_FORIN) || head->isKind(PNK_FOROF)) { Wow, this all is, like, actually *readable* now. :-) ::: js/src/frontend/Parser.cpp @@ +5304,5 @@ > + // letStmt is the BLOCK StmtInfo for the implicit block. > + // > + // Caution: `letStmt.emplace()` creates some Rooted objects. Rooteds must > + // be created/destroyed in FIFO order. Therefore adding a Rooted between > + // this point and the .emplace() call below would trip assertions. Add something about "at top level in this function". @@ +5454,4 @@ > if (isForDecl) { > /* > * pn2 is part of a declaration. Make a copy that can be passed to > + * EmitAssignment. BytecodeEmitter::emitAssignment, presumably. ::: js/src/jit-test/tests/basic/bug646968-3.js @@ +1,1 @@ > +var s, v = 9; s/9/"NOPE"/ or something more glaringly wrong. ::: js/src/jit-test/tests/basic/bug646968-6.js @@ +3,5 @@ > + > +load(libdir + "asserts.js"); > + > +assertThrowsInstanceOf(() => { > + for (let x = x; x < 3; x++) {} Change the test/update parts to null.foo = 5 or something that'll throw not-a-ReferenceError. @@ +7,5 @@ > + for (let x = x; x < 3; x++) {} > +}, ReferenceError); > + > +assertThrowsInstanceOf(() => { > + for (let x = eval('x'); x < 3; x++) {} Likewise. @@ +11,5 @@ > + for (let x = eval('x'); x < 3; x++) {} > +}, ReferenceError); > + > +assertThrowsInstanceOf(() => { > + for (let x = function () { with ({}) return x; }(); x < 3; x++) {} .
Attachment #8677044 -
Flags: review?(jwalden+bmo) → review+
Assignee | ||
Comment 7•9 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=c95447823ba4
Assignee | ||
Comment 8•9 years ago
|
||
Assignee | ||
Comment 9•9 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=347bb1489506
Assignee | ||
Comment 10•9 years ago
|
||
Assignee | ||
Comment 11•9 years ago
|
||
Comment on attachment 8679117 [details] [diff] [review] Part 1: Rename some loop variables to avoid conflicts with ES6 scoping rules Requesting reviews from: fitzgen for CensusUtils.js rhelmer for UITour.jsm gps for dataprovider.jsm ttaubert for SessionStore.jsm
Attachment #8679117 -
Flags: review?(nfitzgerald)
Updated•9 years ago
|
Attachment #8679117 -
Flags: review?(nfitzgerald) → review+
Comment 12•9 years ago
|
||
(In reply to Jason Orendorff [:jorendorff] from comment #11) > Comment on attachment 8679117 [details] [diff] [review] > Part 1: Rename some loop variables to avoid conflicts with ES6 scoping rules > > Requesting reviews from: > fitzgen for CensusUtils.js > rhelmer for UITour.jsm > gps for dataprovider.jsm > ttaubert for SessionStore.jsm (You didn't flag anyone but me for review).
Assignee | ||
Updated•9 years ago
|
Attachment #8679117 -
Flags: review?(ttaubert)
Attachment #8679117 -
Flags: review?(rhelmer)
Attachment #8679117 -
Flags: review?(gps)
Updated•9 years ago
|
Attachment #8679117 -
Flags: review?(ttaubert) → review+
Assignee | ||
Comment 13•9 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=86c817a8729c
Comment 14•9 years ago
|
||
Comment on attachment 8679117 [details] [diff] [review] Part 1: Rename some loop variables to avoid conflicts with ES6 scoping rules UITour.jsm changes LGTM but I've barely touched that code, would be good to get someone who is more familiar to confirm.
Attachment #8679117 -
Flags: review?(rhelmer) → review?(MattN+bmo)
Comment 15•9 years ago
|
||
Comment on attachment 8679117 [details] [diff] [review] Part 1: Rename some loop variables to avoid conflicts with ES6 scoping rules Review of attachment 8679117 [details] [diff] [review]: ----------------------------------------------------------------- UITour.jsm is fine
Attachment #8679117 -
Flags: review?(MattN+bmo) → review+
Assignee | ||
Comment 16•9 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=5b8b3621fc20
Assignee | ||
Comment 17•9 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=83dfe46c9e01
Updated•9 years ago
|
Attachment #8679117 -
Flags: review?(gps) → review+
Assignee | ||
Comment 18•9 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/02922ca741fd7f1cb3a742b9afcc15c1f5e49083 Bug 1216623 - Part 1: Rename some loop variables to avoid conflicts with ES6 scoping rules. r=fitzgen, r=ttaubert, r=MattN, r=gps. https://hg.mozilla.org/integration/mozilla-inbound/rev/ce0741b494a70915a451fda9378a20816319ee3c Bug 1216623 - Part 2: In `for (let ...)` loops, evaluate initializers in the scope of the variables being initialized. r=Waldo.
Comment 19•9 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/02922ca741fd https://hg.mozilla.org/mozilla-central/rev/ce0741b494a7
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox45:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Comment 20•9 years ago
|
||
bugherder uplift |
https://hg.mozilla.org/releases/mozilla-b2g44_v2_5/rev/02922ca741fd https://hg.mozilla.org/releases/mozilla-b2g44_v2_5/rev/ce0741b494a7
status-b2g-v2.5:
--- → fixed
You need to log in
before you can comment on or make changes to this bug.
Description
•