| Index: src/array.js
|
| diff --git a/src/array.js b/src/array.js
|
| index a7c37e1ef819a13907cea27f5da70a9937584359..93378cfb00b1b14c0150e5b179c6de5f6a8852a2 100644
|
| --- a/src/array.js
|
| +++ b/src/array.js
|
| @@ -12,11 +12,6 @@
|
| var $arrayUnshift;
|
| var $innerArrayForEach;
|
| var $innerArrayEvery;
|
| -var $innerArrayFilter;
|
| -var $innerArrayMap;
|
| -var $innerArrayReduce;
|
| -var $innerArrayReduceRight;
|
| -var $innerArraySome;
|
|
|
| (function(global, shared, exports) {
|
|
|
| @@ -1155,7 +1150,14 @@
|
| // The following functions cannot be made efficient on sparse arrays while
|
| // preserving the semantics, since the calls to the receiver function can add
|
| // or delete elements from the array.
|
| -function InnerArrayFilter(f, receiver, array, length) {
|
| +function ArrayFilter(f, receiver) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
|
| +
|
| + // 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);
|
| +
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
|
| var needs_wrapper = false;
|
| if (IS_NULL(receiver)) {
|
| @@ -1184,17 +1186,6 @@
|
| return result;
|
| }
|
|
|
| -function ArrayFilter(f, receiver) {
|
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
|
| -
|
| - // 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 InnerArrayFilter(f, receiver, array, length);
|
| -}
|
| -
|
| function InnerArrayForEach(f, receiver, array, length) {
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
|
| var needs_wrapper = false;
|
| @@ -1228,7 +1219,16 @@
|
| }
|
|
|
|
|
| -function InnerArraySome(f, receiver, array, length) {
|
| +// Executes the function once for each element present in the
|
| +// array until it finds one where callback returns true.
|
| +function ArraySome(f, receiver) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
|
| +
|
| + // 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 = TO_UINT32(array.length);
|
| +
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
|
| var needs_wrapper = false;
|
| if (IS_NULL(receiver)) {
|
| @@ -1252,19 +1252,6 @@
|
| }
|
|
|
|
|
| -// Executes the function once for each element present in the
|
| -// array until it finds one where callback returns true.
|
| -function ArraySome(f, receiver) {
|
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
|
| -
|
| - // 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 = TO_UINT32(array.length);
|
| - return InnerArraySome(f, receiver, array, length);
|
| -}
|
| -
|
| -
|
| function InnerArrayEvery(f, receiver, array, length) {
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
|
| var needs_wrapper = false;
|
| @@ -1299,7 +1286,14 @@
|
| }
|
|
|
|
|
| -function InnerArrayMap(f, receiver, array, length) {
|
| +function ArrayMap(f, receiver) {
|
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
|
| +
|
| + // 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 = TO_UINT32(array.length);
|
| +
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
|
| var needs_wrapper = false;
|
| if (IS_NULL(receiver)) {
|
| @@ -1323,17 +1317,6 @@
|
| }
|
| %MoveArrayContents(accumulator, result);
|
| return result;
|
| -}
|
| -
|
| -
|
| -function ArrayMap(f, receiver) {
|
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
|
| -
|
| - // 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 = TO_UINT32(array.length);
|
| - return InnerArrayMap(f, receiver, array, length);
|
| }
|
|
|
|
|
| @@ -1447,14 +1430,21 @@
|
| }
|
|
|
|
|
| -function InnerArrayReduce(callback, current, array, length, argumentsLength) {
|
| +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);
|
| +
|
| 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++];
|
| @@ -1477,27 +1467,21 @@
|
| }
|
|
|
|
|
| -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.
|
| +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 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--];
|
| @@ -1517,18 +1501,6 @@
|
| }
|
| }
|
| 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
|
| @@ -1635,12 +1607,7 @@
|
| $arraySplice = ArraySplice;
|
| $arrayUnshift = ArrayUnshift;
|
|
|
| +$innerArrayForEach = InnerArrayForEach;
|
| $innerArrayEvery = InnerArrayEvery;
|
| -$innerArrayFilter = InnerArrayFilter;
|
| -$innerArrayForEach = InnerArrayForEach;
|
| -$innerArrayMap = InnerArrayMap;
|
| -$innerArrayReduce = InnerArrayReduce;
|
| -$innerArrayReduceRight = InnerArrayReduceRight;
|
| -$innerArraySome = InnerArraySome;
|
|
|
| });
|
|
|