Chromium Code Reviews| Index: src/array.js |
| diff --git a/src/array.js b/src/array.js |
| index bf24d16d11bd7da9fe48cade405f590c96c66243..80fd6063cccceb97340ec28f5cee28d00c6252c6 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, check_has_index) |
| +{ |
|
arv (Not doing code reviews)
2015/05/11 17:45:01
{ before newline
|
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| var needs_wrapper = false; |
| if (IS_NULL(receiver)) { |
| @@ -1199,7 +1194,7 @@ function ArrayForEach(f, receiver) { |
| var is_array = IS_ARRAY(array); |
| var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| for (var i = 0; i < length; i++) { |
| - if (HAS_INDEX(array, i, is_array)) { |
| + if (!check_has_index || HAS_INDEX(array, i, is_array)) { |
|
arv (Not doing code reviews)
2015/05/11 17:45:01
This might be noticable.
Another option would be
caitp (gmail)
2015/05/11 17:47:25
Can js2c resolve macros across different files? If
adamk
2015/05/11 19:54:28
I think we can leave out check_has_index for now,
|
| var element = array[i]; |
| // Prepare break slots for debugger step in. |
| if (stepping) %DebugPrepareStepInIfStepping(f); |
| @@ -1209,6 +1204,16 @@ function ArrayForEach(f, receiver) { |
| } |
| } |
|
arv (Not doing code reviews)
2015/05/11 17:45:01
Would %SetInlineBuiltinFlag work?
|
| +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, true); |
| +} |
| + |
| // 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, check_has_index) { |
| if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| var needs_wrapper = false; |
| if (IS_NULL(receiver)) { |
| @@ -1262,7 +1260,7 @@ function ArrayEvery(f, receiver) { |
| var is_array = IS_ARRAY(array); |
| var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| for (var i = 0; i < length; i++) { |
| - if (HAS_INDEX(array, i, is_array)) { |
| + if (!check_has_index || HAS_INDEX(array, i, is_array)) { |
| var element = array[i]; |
| // Prepare break slots for debugger step in. |
| if (stepping) %DebugPrepareStepInIfStepping(f); |
| @@ -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, true); |
| +} |
| + |
| 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; |
| + |
| })(); |