Commit 6c9bab5c authored by wingo@igalia.com's avatar wingo@igalia.com

Array.prototype.{reduce, reduceRight}: Wrong order of operations when determining initial value.

BUG=v8:3534
LOG=
R=svenpanne@chromium.org, wingo@igalia.com

Review URL: https://codereview.chromium.org/614733002

Patch from Diego Pino <dpino@igalia.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24807 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5680786c
......@@ -1418,9 +1418,8 @@ function ArrayReduce(callback, current) {
var i = 0;
find_initial: if (%_ArgumentsLength() < 2) {
for (; i < length; i++) {
current = array[i];
if (!IS_UNDEFINED(current) || i in array) {
i++;
if (i in array) {
current = array[i++];
break find_initial;
}
}
......@@ -1455,9 +1454,8 @@ function ArrayReduceRight(callback, current) {
var i = length - 1;
find_initial: if (%_ArgumentsLength() < 2) {
for (; i >= 0; i--) {
current = array[i];
if (!IS_UNDEFINED(current) || i in array) {
i--;
if (i in array) {
current = array[i--];
break find_initial;
}
}
......
......@@ -521,3 +521,13 @@ testReduce("reduce", "ArrayManipulationExtender", 10,
[3, 3, 2, [1, 2, 3, 4, 4, 5], 6],
[6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10],
], arr, extender, 0);
var arr = [];
Object.defineProperty(arr, "0", { get: function() { delete this[0] },
configurable: true });
assertEquals(undefined, arr.reduce(function(val) { return val }));
var arr = [];
Object.defineProperty(arr, "0", { get: function() { delete this[0] },
configurable: true});
assertEquals(undefined, arr.reduceRight(function(val) { return val }));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment