Index: src/array.js |
diff --git a/src/array.js b/src/array.js |
index 71f86c80f3a90518181c2bc0941ebeb7988a899d..5da175261b056f54ba6536f8cdfedfce52e1ec7f 100644 |
--- a/src/array.js |
+++ b/src/array.js |
@@ -12,9 +12,12 @@ var $arraySplice; |
var $arrayUnshift; |
var $innerArrayForEach; |
var $innerArrayEvery; |
+var $innerArrayFilter; |
var $innerArrayIndexOf; |
var $innerArrayLastIndexOf; |
+var $innerArrayMap; |
var $innerArrayReverse; |
+var $innerArraySome; |
var $innerArraySort; |
(function(global, shared, exports) { |
@@ -1164,14 +1167,7 @@ function ArraySort(comparefn) { |
// 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 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); |
- |
+function InnerArrayFilter(f, receiver, array, length) { |
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
var needs_wrapper = false; |
if (IS_NULL(receiver)) { |
@@ -1200,6 +1196,17 @@ function ArrayFilter(f, receiver) { |
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; |
@@ -1233,16 +1240,7 @@ function ArrayForEach(f, receiver) { |
} |
-// 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); |
- |
+function InnerArraySome(f, receiver, array, length) { |
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
var needs_wrapper = false; |
if (IS_NULL(receiver)) { |
@@ -1266,6 +1264,19 @@ function ArraySome(f, receiver) { |
} |
+// 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; |
@@ -1300,14 +1311,7 @@ function ArrayEvery(f, receiver) { |
} |
-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); |
- |
+function InnerArrayMap(f, receiver, array, length) { |
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
var needs_wrapper = false; |
if (IS_NULL(receiver)) { |
@@ -1334,6 +1338,17 @@ function ArrayMap(f, receiver) { |
} |
+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); |
+} |
+ |
+ |
// For .indexOf, we don't need to pass in the number of arguments |
// at the callsite since ToInteger(undefined) == 0; however, for |
// .lastIndexOf, we need to pass it, since the behavior for passing |
@@ -1636,11 +1651,14 @@ $arraySlice = ArraySlice; |
$arraySplice = ArraySplice; |
$arrayUnshift = ArrayUnshift; |
-$innerArrayForEach = InnerArrayForEach; |
$innerArrayEvery = InnerArrayEvery; |
+$innerArrayFilter = InnerArrayFilter; |
+$innerArrayForEach = InnerArrayForEach; |
$innerArrayIndexOf = InnerArrayIndexOf; |
$innerArrayLastIndexOf = InnerArrayLastIndexOf; |
+$innerArrayMap = InnerArrayMap; |
$innerArrayReverse = InnerArrayReverse; |
+$innerArraySome = InnerArraySome; |
$innerArraySort = InnerArraySort; |
}); |