Closed Bug 646820 Opened 9 years ago Closed 9 years ago

Function in destructuring assignment can't see up to other variables in the assignment

Categories

(Core :: JavaScript Engine, defect, P1, major)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: jorendorff, Assigned: jorendorff)

References

Details

(Keywords: regression, testcase, Whiteboard: [fixed-in-tracemonkey])

Attachments

(1 file)

+++ 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.
Attached patch v1Splinter Review
-175 lines net (not counting the tests I added)
Attachment #523300 - Flags: review?(brendan)
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+
http://hg.mozilla.org/tracemonkey/rev/bc0e295346e7
Whiteboard: [fixed-in-tracemonkey]
http://hg.mozilla.org/mozilla-central/rev/bc0e295346e7
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.