| Index: src/array.js
|
| diff --git a/src/array.js b/src/array.js
|
| index 55c59eb4a12ec9aa3af47ecc232bcce2df901b94..d24d52ff2bf3839298f98aa48a625d16e1c75f11 100644
|
| --- a/src/array.js
|
| +++ b/src/array.js
|
| @@ -1481,21 +1481,14 @@ function ArrayLastIndexOf(element, index) {
|
| }
|
|
|
|
|
| -function ArrayReduce(callback, current) {
|
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
|
| -
|
| - // Pull out the length so that modifications to the length in the
|
| - // loop will not affect the looping and side effects are visible.
|
| - var array = $toObject(this);
|
| - var length = $toUint32(array.length);
|
| -
|
| +function InnerArrayReduce(callback, current, array, length, argumentsLength) {
|
| if (!IS_SPEC_FUNCTION(callback)) {
|
| throw MakeTypeError(kCalledNonCallable, callback);
|
| }
|
|
|
| var is_array = IS_ARRAY(array);
|
| var i = 0;
|
| - find_initial: if (%_ArgumentsLength() < 2) {
|
| + find_initial: if (argumentsLength < 2) {
|
| for (; i < length; i++) {
|
| if (HAS_INDEX(array, i, is_array)) {
|
| current = array[i++];
|
| @@ -1518,21 +1511,27 @@ function ArrayReduce(callback, current) {
|
| }
|
|
|
|
|
| -function ArrayReduceRight(callback, current) {
|
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
|
| +function ArrayReduce(callback, current) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
|
|
|
| - // Pull out the length so that side effects are visible before the
|
| - // callback function is checked.
|
| + // Pull out the length so that modifications to the length in the
|
| + // loop will not affect the looping and side effects are visible.
|
| var array = $toObject(this);
|
| var length = $toUint32(array.length);
|
| + return InnerArrayReduce(callback, current, array, length,
|
| + %_ArgumentsLength());
|
| +}
|
| +
|
|
|
| +function InnerArrayReduceRight(callback, current, array, length,
|
| + argumentsLength) {
|
| if (!IS_SPEC_FUNCTION(callback)) {
|
| throw MakeTypeError(kCalledNonCallable, callback);
|
| }
|
|
|
| var is_array = IS_ARRAY(array);
|
| var i = length - 1;
|
| - find_initial: if (%_ArgumentsLength() < 2) {
|
| + find_initial: if (argumentsLength < 2) {
|
| for (; i >= 0; i--) {
|
| if (HAS_INDEX(array, i, is_array)) {
|
| current = array[i--];
|
| @@ -1554,6 +1553,18 @@ function ArrayReduceRight(callback, current) {
|
| return current;
|
| }
|
|
|
| +
|
| +function ArrayReduceRight(callback, current) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
|
| +
|
| + // Pull out the length so that side effects are visible before the
|
| + // callback function is checked.
|
| + var array = $toObject(this);
|
| + var length = $toUint32(array.length);
|
| + return InnerArrayReduceRight(callback, current, array, length,
|
| + %_ArgumentsLength());
|
| +}
|
| +
|
| // ES5, 15.4.3.2
|
| function ArrayIsArray(obj) {
|
| return IS_ARRAY(obj);
|
| @@ -1660,6 +1671,8 @@ utils.Export(function(to) {
|
| to.InnerArrayIndexOf = InnerArrayIndexOf;
|
| to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
|
| to.InnerArrayMap = InnerArrayMap;
|
| + to.InnerArrayReduce = InnerArrayReduce;
|
| + to.InnerArrayReduceRight = InnerArrayReduceRight;
|
| to.InnerArrayReverse = InnerArrayReverse;
|
| to.InnerArraySome = InnerArraySome;
|
| to.InnerArraySort = InnerArraySort;
|
|
|