Closed
Bug 388442
Opened 18 years ago
Closed 13 years ago
|let| with destructuring compiled incorrectly (decompiled too in for-in head)
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: jruderman, Unassigned)
Details
(Keywords: testcase)
A variable declared in "let" is normally not bound within the initial-value expression, but if the declaration uses destructuring, it is.
js> x = 3; let (x = x) { print(x) }
3
js> x = 3; let ([x] = [x]) { print(x) }
undefined
I'm guessing this is wrong; I'd expect to see "3" in both cases.
This leads to changes in behavior through decompilation when for..let hoisting comes in:
js> f = function() { x = 1; for (let [x] = print(x) in []) { } }
function () {
x = 1;
print(x);
for (let [x] in []) {
}
}
js> f()
undefined
js> eval(uneval(f))()
1
Comment 1•18 years ago
|
||
Quote:
"Note: In contrast with normal assignment expressions, the locations updated by destructuring assignment are not computed before the value that is to be stored. Destructuring assignment is simple syntactic sugar for a common compute-and-destructure pattern, and true to this pattern it computes the value prior to computing the locations. (See discussion below for more detail.)"
from
https://intranet.mozilla.org/ECMA/wiki/doku.php?id=proposals:destructuring_assignment
This works as designed and is independent of let vs. var.
/be
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
Comment 2•18 years ago
|
||
Public export of that wiki page:
http://developer.mozilla.org/es4/proposals/destructuring_assignment.html
/be
Comment 3•18 years ago
|
||
Sorry, missed the decompiler bug.
/be
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Summary: Variable declared using |let| with destructuring is incorrectly bound within the initial-value expression → for-in with |let| and destructuring decompiled incorrectly
Comment 4•18 years ago
|
||
I'm a complete idjit today (need more coffee). Jesse's right, this is indeed a destructuring bug, and the hoisting comment points to a decompiler issue to fix or keep working while fixing the compilation bug.
Blake, you interested in this bug?
/be
Summary: for-in with |let| and destructuring decompiled incorrectly → |let| with destructuring compiled incorrectly (decompiled too in for-in head)
Comment 5•13 years ago
|
||
js> x = 3; let (x = x) { print(x) }
3
js> x = 3; let ([x] = [x]) { print(x) }
3
Status: REOPENED → RESOLVED
Closed: 18 years ago → 13 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•