Note: There are a few cases of duplicates in user autocompletion which are being worked on.

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

RESOLVED FIXED

Status

()

Core
JavaScript Engine
P1
major
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: jorendorff, Assigned: jorendorff)

Tracking

({regression, testcase})

Trunk
regression, testcase
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [fixed-in-tracemonkey])

Attachments

(1 attachment)

(Assignee)

Description

6 years ago
+++ 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

6 years ago
Created attachment 523300 [details] [diff] [review]
v1

-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+
(Assignee)

Comment 3

6 years ago
http://hg.mozilla.org/tracemonkey/rev/bc0e295346e7
Whiteboard: [fixed-in-tracemonkey]
http://hg.mozilla.org/mozilla-central/rev/bc0e295346e7
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.