Closed Bug 347593 Opened 18 years ago Closed 18 years ago

For-each loop with destructuring assignment is performed as for loop

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.8.1beta2

People

(Reporter: nanto, Assigned: brendan)

Details

(Keywords: verified1.8.1)

Attachments

(1 file)

If destructuring assignment is used in for-each loop, the loop incorrectly iterates over the object as if it is for loop.

js> for (let [, { a: b }] in [{ a: 2 }, { a: 3 }]) print(b); // OK
2
3
js> for each (let { a: b } in [{ a: 2 }, { a: 3 }]) print(b); // Wrong
undefined
undefined
js> for each (let [, { a: b }] in [{ a: 2 }, { a: 3 }]) print(b); // Wrong
2
3

In the example above, the second loop should show 2 and 3 and the third loop should throw a TypeError exception.
Fast action needed for beta 2.

/be
Assignee: general → brendan
Attached patch fixSplinter Review
Small fix to get js1.7 semantics right regarding for (i in o) vs. for each (v in o) key (identifier) vs. property value enumeration, in combination with the new destructuring assignment support (for ([k,v] in o) to destructure key-value pairs vs. for each ({vp1:x, vp2:y} in o) to destructure properties of the value, vp1 and vp2 in this example).

/be
Attachment #232582 - Flags: superreview?(mrbkap)
Attachment #232582 - Flags: review?(igor.bukanov)
Attachment #232582 - Flags: approval1.8.1?
Status: NEW → ASSIGNED
OS: Windows XP → All
Priority: -- → P1
Hardware: PC → All
Target Milestone: --- → mozilla1.8.1beta2
Attachment #232582 - Flags: review?(igor.bukanov) → review+
Fixed on trunk.

/be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Flags: blocking1.8.1?
Resolution: --- → FIXED
Checking in regress-347593.js;
/cvsroot/mozilla/js/tests/js1_7/geniter/regress-347593.js,v  <--  regress-347593.js
initial revision: 1.1
Flags: in-testsuite+
Comment on attachment 232582 [details] [diff] [review]
fix

a=drivers
Attachment #232582 - Flags: approval1.8.1? → approval1.8.1+
Fixed on the 1.8 branch too.

/be
Flags: blocking1.8.1?
Keywords: fixed1.8.1
Attachment #232582 - Flags: superreview?(mrbkap) → superreview+
verified fixed 1.9 win/mac(ppc|tel)/linux 20060808
Status: RESOLVED → VERIFIED
verified fixed 1.8 20060809 mac(ppc|tel)/linux. Unfortunately I don't have
windows test results for 20060809 1.8, but verifying anyway.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: