Closed
Bug 646820
Opened 14 years ago
Closed 14 years ago
Function in destructuring assignment can't see up to other variables in the assignment
Categories
(Core :: JavaScript Engine, defect, P1)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: jorendorff, Assigned: jorendorff)
References
Details
(Keywords: regression, testcase, Whiteboard: [fixed-in-tracemonkey])
Attachments
(1 file)
(deleted),
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
+++ This bug was initially created as a clone of Bug #496134 +++
We can still erroneously optimize some lambda-bindings into flat closure slots.
Case 1: The position of x is extended, but not far enough:
(function () {
var [x, y] = [1, function () x];
assertEq(y(), 1); // FAIL
})()
Case 2: UndominateInitializers quits too soon if it sees a syntactic mismatch between the rhs and the lhs.
(function () {
var obj = {prop: 1};
var [x, {prop: y}] = [function () y, obj];
assertEq(y, 1); // PASS
assertEq(x(), 1); // FAIL
})();
A silly instance of case 2:
(function () {
var [x, y] = {"0": function () y, "1": 13};
assertEq(x(), 13); // FAIL
})();
I think the fix is for UndominateInitializers to search the entire LHS regardless of whether it matches the RHS structurally, and extend the position of each declared variable to cover the entire RHS. This seems like a nice simplification. Taking.
Assignee | ||
Comment 1•14 years ago
|
||
-175 lines net (not counting the tests I added)
Attachment #523300 -
Flags: review?(brendan)
Comment 2•14 years ago
|
||
Comment on attachment 523300 [details] [diff] [review]
v1
Nice again! I wrote too much code back in the day, was a bit over-ambitious when destructuring went in. Learned my lesson,
/be
Attachment #523300 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 3•14 years ago
|
||
Whiteboard: [fixed-in-tracemonkey]
Comment 4•14 years ago
|
||
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•