Closed Bug 664528 Opened 13 years ago Closed 11 years ago

array.sort bug with arrays containing only undefined values

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla21

People

(Reporter: jandem, Assigned: Waldo)

References

Details

Attachments

(1 file)

--
var a = [, , , undefined];
a.sort();
for (var i=0; i<a.length; i++) {
    if (!(i in a)) {
        print("Hole: " + i);
    } else if (a[i] === undefined) {
        print("Undefined: " + i);
    }
}
--
This prints:
--
Hole: 0
Hole: 1
Hole: 2
Undefined: 3
--
This is incorrect. Quoting ES5: "non-­existent property values always compare greater than undefined property values". Works correctly if I add a value other than undefined to the array.
Blocks: es5
Attached patch Patch and testSplinter Review
I happened to notice this in a skim through all JS bugs today, searching for a substring in the summaries.  Having just reviewed bug 715419, this code's super-fresh in memory, so I looked and found the easy fix.  Haven't run JS tests yet, but I'm 99% sure this is a complete fix.
Assignee: general → jwalden+bmo
Status: NEW → ASSIGNED
Attachment #713700 - Flags: review?(jdemooij)
Comment on attachment 713700 [details] [diff] [review]
Patch and test

Review of attachment 713700 [details] [diff] [review]:
-----------------------------------------------------------------

Heh, thanks, completely forgot about this bug.
Attachment #713700 - Flags: review?(jdemooij) → review+
https://hg.mozilla.org/mozilla-central/rev/a1310b986ebe
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: