Closed
Bug 386030
Opened 17 years ago
Closed 17 years ago
Array.reduce should ignore holes
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
FIXED
People
(Reporter: nanto, Assigned: mrbkap)
Details
Attachments
(2 files)
1.32 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
585 bytes,
text/plain
|
Details |
Array extra methods that are introduced in JS 1.6 ignore hole elements. But reduce/reduceRight don't if the initial value isn't given and the hole element is the first element (reduce) or the last element (reduceRight). To keep consitency, reduce/reduceRight should start iteration from the first non-hole element or throw "reduce of empty array with no initial value" error if no such element exists. Actual: js> function add(a, b) { return a + b; } js> // Non-first hole elements are ignored. js> a = new Array(2); a[0] = 3; a.reduce(add); 3 js> // If initial is given, the first hole is ignored. js> a = new Array(2); a[1] = 3; a.reduce(add, 0); 3 js> a = new Array(2); a[1] = 3; a.reduce(add); NaN js> a = new Array(2); a[0] = 3; a.reduceRight(add); NaN js> uneval(new Array(2).reduce(add)) (void 0) Expected: js> a = new Array(2); a[1] = 3; a.reduce(add); 3 js> a = new Array(2); a[0] = 3; a.reduceRight(add); 3 js> uneval(new Array(2).reduce(add)) TypeError: reduce of empty array with no initial value
Assignee | ||
Comment 1•17 years ago
|
||
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Assignee | ||
Updated•17 years ago
|
Attachment #270081 -
Flags: review?(brendan)
Assignee | ||
Comment 2•17 years ago
|
||
This is the interesting subset of testcases, I think.
Updated•17 years ago
|
Attachment #270081 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 3•17 years ago
|
||
Fix checked into trunk.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Comment 4•17 years ago
|
||
I updated the MDC implementations for this. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:reduce http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:reduceRight
Comment 5•17 years ago
|
||
/cvsroot/mozilla/js/tests/js1_6/Array/regress-386030.js,v <-- regress-386030.js initial revision: 1.1
Flags: in-testsuite? → in-testsuite+
Comment 6•17 years ago
|
||
this should have been in js1_7. I'll move it when I add reduce* object detection to skip the reduce tests on the 1.8 branch.
You need to log in
before you can comment on or make changes to this bug.
Description
•