Closed Bug 417568 Opened 16 years ago Closed 5 years ago

Incorrect destructuring assignment

Categories

(Rhino Graveyard :: Compiler, defect)

1.7R1
x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INACTIVE

People

(Reporter: norrisboyd, Assigned: norrisboyd)

Details

Attachments

(2 files)

Steve Yegge wrote:

js> [[x, y].toSource() for ([x, y] in {foo: 'bar', hi: 'there'})]
["f", "o"],["h", "i"]

Seems like it ought to print:

["foo", "bar"], ["hi", "there"]

doesn't it?
It's also bugged for destructuring over an array:

js> [[x, y].toSource() for ([x, y] in [[1, 2], [3, 4], [5, 6]])]
["0", , ],["1", , ],["2", , ]

Assignee: nobody → norrisboyd
Attached file 417568.doctest
Doctest for failure
I changed array comprehension parsing to handle destructuring assignments in the same way ordinary for loops do. I guess I was lucky :-)
A few observations: 

With JavaScript 1.8, spidermonkey behaviour changes back to destructuring the key strings:

js> version(170)                                                  
180
js> [[x, y].toSource() for ([x, y] in {foo: 'bar', hi: 'there'})]
["foo", "bar"],["hi", "there"]
js> version(180)                                                  
170
js> [[x, y].toSource() for ([x, y] in {foo: 'bar', hi: 'there'})]
["f", "o"],["h", "i"]
js> 

Also see the last paragraph in the "what's new in js 1.8" page:
https://developer.mozilla.org/en/New_in_JavaScript_1.8#Changes_in_destructuring_for..in

I also noticed that my patch breaks test case js1_7/regress/regress-428706.js, complaining about more than 2 elements in the destructuring left hand side, which spidermonkey seems to accept if the third element is actually empty. Spidermonkey JS 1.8 seems to accept indefinite destructuring array elements, but only in ordinary loops, not array comprehension.  

IMO the question is whether array comprehension should follow the same rules as for loops. If the answer is yes, I think my patch is correct after all.

Closing. Bug management is now done here:
https://github.com/mozilla/rhino

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: