| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 for (var i = 0; i < length; i++) { | 1189 for (var i = 0; i < length; i++) { |
| 1190 if (HAS_INDEX(array, i, is_array)) { | 1190 if (HAS_INDEX(array, i, is_array)) { |
| 1191 var element = array[i]; | 1191 var element = array[i]; |
| 1192 // Prepare break slots for debugger step in. | 1192 // Prepare break slots for debugger step in. |
| 1193 if (stepping) %DebugPrepareStepInIfStepping(f); | 1193 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1194 if (%_Call(f, receiver, element, i, array)) { | 1194 if (%_Call(f, receiver, element, i, array)) { |
| 1195 accumulator[accumulator_length++] = element; | 1195 accumulator[accumulator_length++] = element; |
| 1196 } | 1196 } |
| 1197 } | 1197 } |
| 1198 } | 1198 } |
| 1199 return accumulator; | 1199 var result = new GlobalArray(); |
| 1200 %MoveArrayContents(accumulator, result); |
| 1201 return result; |
| 1200 } | 1202 } |
| 1201 | 1203 |
| 1202 function ArrayFilter(f, receiver) { | 1204 function ArrayFilter(f, receiver) { |
| 1203 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1205 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
| 1204 | 1206 |
| 1205 // Pull out the length so that modifications to the length in the | 1207 // Pull out the length so that modifications to the length in the |
| 1206 // loop will not affect the looping and side effects are visible. | 1208 // loop will not affect the looping and side effects are visible. |
| 1207 var array = TO_OBJECT(this); | 1209 var array = TO_OBJECT(this); |
| 1208 var length = TO_LENGTH_OR_UINT32(array.length); | 1210 var length = TO_LENGTH_OR_UINT32(array.length); |
| 1209 var accumulator = InnerArrayFilter(f, receiver, array, length); | 1211 return InnerArrayFilter(f, receiver, array, length); |
| 1210 var result = new GlobalArray(); | |
| 1211 %MoveArrayContents(accumulator, result); | |
| 1212 return result; | |
| 1213 } | 1212 } |
| 1214 | 1213 |
| 1215 function InnerArrayForEach(f, receiver, array, length) { | 1214 function InnerArrayForEach(f, receiver, array, length) { |
| 1216 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1215 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1217 | 1216 |
| 1218 var is_array = IS_ARRAY(array); | 1217 var is_array = IS_ARRAY(array); |
| 1219 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1218 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1220 for (var i = 0; i < length; i++) { | 1219 for (var i = 0; i < length; i++) { |
| 1221 if (HAS_INDEX(array, i, is_array)) { | 1220 if (HAS_INDEX(array, i, is_array)) { |
| 1222 var element = array[i]; | 1221 var element = array[i]; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 var is_array = IS_ARRAY(array); | 1301 var is_array = IS_ARRAY(array); |
| 1303 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1302 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1304 for (var i = 0; i < length; i++) { | 1303 for (var i = 0; i < length; i++) { |
| 1305 if (HAS_INDEX(array, i, is_array)) { | 1304 if (HAS_INDEX(array, i, is_array)) { |
| 1306 var element = array[i]; | 1305 var element = array[i]; |
| 1307 // Prepare break slots for debugger step in. | 1306 // Prepare break slots for debugger step in. |
| 1308 if (stepping) %DebugPrepareStepInIfStepping(f); | 1307 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1309 accumulator[i] = %_Call(f, receiver, element, i, array); | 1308 accumulator[i] = %_Call(f, receiver, element, i, array); |
| 1310 } | 1309 } |
| 1311 } | 1310 } |
| 1312 return accumulator; | 1311 var result = new GlobalArray(); |
| 1312 %MoveArrayContents(accumulator, result); |
| 1313 return result; |
| 1313 } | 1314 } |
| 1314 | 1315 |
| 1315 | 1316 |
| 1316 function ArrayMap(f, receiver) { | 1317 function ArrayMap(f, receiver) { |
| 1317 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1318 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
| 1318 | 1319 |
| 1319 // Pull out the length so that modifications to the length in the | 1320 // Pull out the length so that modifications to the length in the |
| 1320 // loop will not affect the looping and side effects are visible. | 1321 // loop will not affect the looping and side effects are visible. |
| 1321 var array = TO_OBJECT(this); | 1322 var array = TO_OBJECT(this); |
| 1322 var length = TO_LENGTH_OR_UINT32(array.length); | 1323 var length = TO_LENGTH_OR_UINT32(array.length); |
| 1323 var accumulator = InnerArrayMap(f, receiver, array, length); | 1324 return InnerArrayMap(f, receiver, array, length); |
| 1324 var result = new GlobalArray(); | |
| 1325 %MoveArrayContents(accumulator, result); | |
| 1326 return result; | |
| 1327 } | 1325 } |
| 1328 | 1326 |
| 1329 | 1327 |
| 1330 // For .indexOf, we don't need to pass in the number of arguments | 1328 // For .indexOf, we don't need to pass in the number of arguments |
| 1331 // at the callsite since ToInteger(undefined) == 0; however, for | 1329 // at the callsite since ToInteger(undefined) == 0; however, for |
| 1332 // .lastIndexOf, we need to pass it, since the behavior for passing | 1330 // .lastIndexOf, we need to pass it, since the behavior for passing |
| 1333 // undefined is 0 but for not including the argument is length-1. | 1331 // undefined is 0 but for not including the argument is length-1. |
| 1334 function InnerArrayIndexOf(array, element, index, length) { | 1332 function InnerArrayIndexOf(array, element, index, length) { |
| 1335 if (length == 0) return -1; | 1333 if (length == 0) return -1; |
| 1336 if (IS_UNDEFINED(index)) { | 1334 if (IS_UNDEFINED(index)) { |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 %InstallToContext([ | 1665 %InstallToContext([ |
| 1668 "array_pop", ArrayPop, | 1666 "array_pop", ArrayPop, |
| 1669 "array_push", ArrayPush, | 1667 "array_push", ArrayPush, |
| 1670 "array_shift", ArrayShift, | 1668 "array_shift", ArrayShift, |
| 1671 "array_splice", ArraySplice, | 1669 "array_splice", ArraySplice, |
| 1672 "array_slice", ArraySlice, | 1670 "array_slice", ArraySlice, |
| 1673 "array_unshift", ArrayUnshift, | 1671 "array_unshift", ArrayUnshift, |
| 1674 ]); | 1672 ]); |
| 1675 | 1673 |
| 1676 }); | 1674 }); |
| OLD | NEW |