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

VERIFIED FIXED in mozilla1.8.1beta2

Status

()

Core
JavaScript Engine
P1
normal
VERIFIED FIXED
12 years ago
12 years ago

People

(Reporter: nanto_vi (TOYAMA Nao), Assigned: brendan)

Tracking

({verified1.8.1})

Trunk
mozilla1.8.1beta2
verified1.8.1
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

12 years ago
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.
(Assignee)

Comment 1

12 years ago
Fast action needed for beta 2.

/be
Assignee: general → brendan
(Assignee)

Comment 2

12 years ago
Created attachment 232582 [details] [diff] [review]
fix

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

Updated

12 years ago
Status: NEW → ASSIGNED
OS: Windows XP → All
Priority: -- → P1
Hardware: PC → All
Target Milestone: --- → mozilla1.8.1beta2

Updated

12 years ago
Attachment #232582 - Flags: review?(igor.bukanov) → review+
(Assignee)

Comment 3

12 years ago
Fixed on trunk.

/be
Status: ASSIGNED → RESOLVED
Last Resolved: 12 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+
(Assignee)

Comment 6

12 years ago
Fixed on the 1.8 branch too.

/be
Flags: blocking1.8.1?
Keywords: fixed1.8.1

Updated

12 years ago
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.
Keywords: fixed1.8.1 → verified1.8.1
You need to log in before you can comment on or make changes to this bug.