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) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 for (var i = 0; i < length; i++) { | 1191 for (var i = 0; i < length; i++) { |
1192 if (HAS_INDEX(array, i, is_array)) { | 1192 if (HAS_INDEX(array, i, is_array)) { |
1193 var element = array[i]; | 1193 var element = array[i]; |
1194 // Prepare break slots for debugger step in. | 1194 // Prepare break slots for debugger step in. |
1195 if (stepping) %DebugPrepareStepInIfStepping(f); | 1195 if (stepping) %DebugPrepareStepInIfStepping(f); |
1196 if (%_Call(f, receiver, element, i, array)) { | 1196 if (%_Call(f, receiver, element, i, array)) { |
1197 accumulator[accumulator_length++] = element; | 1197 accumulator[accumulator_length++] = element; |
1198 } | 1198 } |
1199 } | 1199 } |
1200 } | 1200 } |
1201 return accumulator; | 1201 var result = new GlobalArray(); |
| 1202 %MoveArrayContents(accumulator, result); |
| 1203 return result; |
1202 } | 1204 } |
1203 | 1205 |
1204 function ArrayFilter(f, receiver) { | 1206 function ArrayFilter(f, receiver) { |
1205 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1207 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
1206 | 1208 |
1207 // Pull out the length so that modifications to the length in the | 1209 // Pull out the length so that modifications to the length in the |
1208 // loop will not affect the looping and side effects are visible. | 1210 // loop will not affect the looping and side effects are visible. |
1209 var array = TO_OBJECT(this); | 1211 var array = TO_OBJECT(this); |
1210 var length = TO_LENGTH_OR_UINT32(array.length); | 1212 var length = TO_LENGTH_OR_UINT32(array.length); |
1211 var accumulator = InnerArrayFilter(f, receiver, array, length); | 1213 return InnerArrayFilter(f, receiver, array, length); |
1212 var result = new GlobalArray(); | |
1213 %MoveArrayContents(accumulator, result); | |
1214 return result; | |
1215 } | 1214 } |
1216 | 1215 |
1217 function InnerArrayForEach(f, receiver, array, length) { | 1216 function InnerArrayForEach(f, receiver, array, length) { |
1218 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1217 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1219 | 1218 |
1220 var is_array = IS_ARRAY(array); | 1219 var is_array = IS_ARRAY(array); |
1221 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1220 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1222 for (var i = 0; i < length; i++) { | 1221 for (var i = 0; i < length; i++) { |
1223 if (HAS_INDEX(array, i, is_array)) { | 1222 if (HAS_INDEX(array, i, is_array)) { |
1224 var element = array[i]; | 1223 var element = array[i]; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 var is_array = IS_ARRAY(array); | 1303 var is_array = IS_ARRAY(array); |
1305 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1304 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1306 for (var i = 0; i < length; i++) { | 1305 for (var i = 0; i < length; i++) { |
1307 if (HAS_INDEX(array, i, is_array)) { | 1306 if (HAS_INDEX(array, i, is_array)) { |
1308 var element = array[i]; | 1307 var element = array[i]; |
1309 // Prepare break slots for debugger step in. | 1308 // Prepare break slots for debugger step in. |
1310 if (stepping) %DebugPrepareStepInIfStepping(f); | 1309 if (stepping) %DebugPrepareStepInIfStepping(f); |
1311 accumulator[i] = %_Call(f, receiver, element, i, array); | 1310 accumulator[i] = %_Call(f, receiver, element, i, array); |
1312 } | 1311 } |
1313 } | 1312 } |
1314 return accumulator; | 1313 var result = new GlobalArray(); |
| 1314 %MoveArrayContents(accumulator, result); |
| 1315 return result; |
1315 } | 1316 } |
1316 | 1317 |
1317 | 1318 |
1318 function ArrayMap(f, receiver) { | 1319 function ArrayMap(f, receiver) { |
1319 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1320 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
1320 | 1321 |
1321 // Pull out the length so that modifications to the length in the | 1322 // Pull out the length so that modifications to the length in the |
1322 // loop will not affect the looping and side effects are visible. | 1323 // loop will not affect the looping and side effects are visible. |
1323 var array = TO_OBJECT(this); | 1324 var array = TO_OBJECT(this); |
1324 var length = TO_LENGTH_OR_UINT32(array.length); | 1325 var length = TO_LENGTH_OR_UINT32(array.length); |
1325 var accumulator = InnerArrayMap(f, receiver, array, length); | 1326 return InnerArrayMap(f, receiver, array, length); |
1326 var result = new GlobalArray(); | |
1327 %MoveArrayContents(accumulator, result); | |
1328 return result; | |
1329 } | 1327 } |
1330 | 1328 |
1331 | 1329 |
1332 // For .indexOf, we don't need to pass in the number of arguments | 1330 // For .indexOf, we don't need to pass in the number of arguments |
1333 // at the callsite since ToInteger(undefined) == 0; however, for | 1331 // at the callsite since ToInteger(undefined) == 0; however, for |
1334 // .lastIndexOf, we need to pass it, since the behavior for passing | 1332 // .lastIndexOf, we need to pass it, since the behavior for passing |
1335 // undefined is 0 but for not including the argument is length-1. | 1333 // undefined is 0 but for not including the argument is length-1. |
1336 function InnerArrayIndexOf(array, element, index, length) { | 1334 function InnerArrayIndexOf(array, element, index, length) { |
1337 if (length == 0) return -1; | 1335 if (length == 0) return -1; |
1338 if (IS_UNDEFINED(index)) { | 1336 if (IS_UNDEFINED(index)) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 %InstallToContext([ | 1656 %InstallToContext([ |
1659 "array_pop", ArrayPop, | 1657 "array_pop", ArrayPop, |
1660 "array_push", ArrayPush, | 1658 "array_push", ArrayPush, |
1661 "array_shift", ArrayShift, | 1659 "array_shift", ArrayShift, |
1662 "array_splice", ArraySplice, | 1660 "array_splice", ArraySplice, |
1663 "array_slice", ArraySlice, | 1661 "array_slice", ArraySlice, |
1664 "array_unshift", ArrayUnshift, | 1662 "array_unshift", ArrayUnshift, |
1665 ]); | 1663 ]); |
1666 | 1664 |
1667 }); | 1665 }); |
OLD | NEW |