Chromium Code Reviews| Index: src/array.js |
| diff --git a/src/array.js b/src/array.js |
| index bf24d16d11bd7da9fe48cade405f590c96c66243..d683f0b9bfa37dd2a0ffe9678008404f0d1537b8 100644 |
| --- a/src/array.js |
| +++ b/src/array.js |
| @@ -10,6 +10,8 @@ var $arrayShift; |
| var $arraySlice; |
| var $arraySplice; |
| var $arrayUnshift; |
| +var $innerArrayForEach; |
| +var $innerArrayEvery; |
| (function() { |
| @@ -1179,15 +1181,8 @@ function ArrayFilter(f, receiver) { |
| return result; |
| } |
| - |
| -function ArrayForEach(f, receiver) { |
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
| - |
| - // 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 InnerArrayForEach(f, receiver, array, length) |
| +{ |
|
adamk
2015/05/11 22:39:24
I'll re-iterate arv's style nit, please put this o
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| var needs_wrapper = false; |
| if (IS_NULL(receiver)) { |
| @@ -1209,6 +1204,16 @@ function ArrayForEach(f, receiver) { |
| } |
| } |
| +function ArrayForEach(f, receiver) { |
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
| + |
| + // 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); |
| + InnerArrayForEach(f, receiver, array, length); |
| +} |
| + |
| // Executes the function once for each element present in the |
| // array until it finds one where callback returns true. |
| @@ -1243,14 +1248,7 @@ function ArraySome(f, receiver) { |
| } |
| -function ArrayEvery(f, receiver) { |
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
| - |
| - // 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 InnerArrayEvery(f, receiver, array, length) { |
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| var needs_wrapper = false; |
| if (IS_NULL(receiver)) { |
| @@ -1273,6 +1271,16 @@ function ArrayEvery(f, receiver) { |
| return true; |
| } |
| +function ArrayEvery(f, receiver) { |
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
| + |
| + // 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 InnerArrayEvery(f, receiver, array, length); |
| +} |
| + |
| function ArrayMap(f, receiver) { |
| CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
| @@ -1595,4 +1603,7 @@ $arraySlice = ArraySlice; |
| $arraySplice = ArraySplice; |
| $arrayUnshift = ArrayUnshift; |
| +$innerArrayForEach = InnerArrayForEach; |
| +$innerArrayEvery = InnerArrayEvery; |
| + |
| })(); |