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 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 | 1205 |
1206 // The following functions cannot be made efficient on sparse arrays while | 1206 // The following functions cannot be made efficient on sparse arrays while |
1207 // preserving the semantics, since the calls to the receiver function can add | 1207 // preserving the semantics, since the calls to the receiver function can add |
1208 // or delete elements from the array. | 1208 // or delete elements from the array. |
1209 function InnerArrayFilter(f, receiver, array, length) { | 1209 function InnerArrayFilter(f, receiver, array, length) { |
1210 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1210 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1211 | 1211 |
1212 var accumulator = new InternalArray(); | 1212 var accumulator = new InternalArray(); |
1213 var accumulator_length = 0; | 1213 var accumulator_length = 0; |
1214 var is_array = IS_ARRAY(array); | 1214 var is_array = IS_ARRAY(array); |
| 1215 var stepping = DEBUG_IS_STEPPING(f); |
1215 for (var i = 0; i < length; i++) { | 1216 for (var i = 0; i < length; i++) { |
1216 if (HAS_INDEX(array, i, is_array)) { | 1217 if (HAS_INDEX(array, i, is_array)) { |
1217 var element = array[i]; | 1218 var element = array[i]; |
| 1219 // Prepare break slots for debugger step in. |
| 1220 if (stepping) %DebugPrepareStepInIfStepping(f); |
1218 if (%_Call(f, receiver, element, i, array)) { | 1221 if (%_Call(f, receiver, element, i, array)) { |
1219 accumulator[accumulator_length++] = element; | 1222 accumulator[accumulator_length++] = element; |
1220 } | 1223 } |
1221 } | 1224 } |
1222 } | 1225 } |
1223 var result = new GlobalArray(); | 1226 var result = new GlobalArray(); |
1224 %MoveArrayContents(accumulator, result); | 1227 %MoveArrayContents(accumulator, result); |
1225 return result; | 1228 return result; |
1226 } | 1229 } |
1227 | 1230 |
1228 | 1231 |
1229 function ArrayFilter(f, receiver) { | 1232 function ArrayFilter(f, receiver) { |
1230 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1233 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
1231 | 1234 |
1232 // Pull out the length so that modifications to the length in the | 1235 // Pull out the length so that modifications to the length in the |
1233 // loop will not affect the looping and side effects are visible. | 1236 // loop will not affect the looping and side effects are visible. |
1234 var array = TO_OBJECT(this); | 1237 var array = TO_OBJECT(this); |
1235 var length = TO_LENGTH_OR_UINT32(array.length); | 1238 var length = TO_LENGTH_OR_UINT32(array.length); |
1236 return InnerArrayFilter(f, receiver, array, length); | 1239 return InnerArrayFilter(f, receiver, array, length); |
1237 } | 1240 } |
1238 | 1241 |
1239 | 1242 |
1240 function InnerArrayForEach(f, receiver, array, length) { | 1243 function InnerArrayForEach(f, receiver, array, length) { |
1241 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1244 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1242 | 1245 |
1243 var is_array = IS_ARRAY(array); | 1246 var is_array = IS_ARRAY(array); |
| 1247 var stepping = DEBUG_IS_STEPPING(f); |
1244 for (var i = 0; i < length; i++) { | 1248 for (var i = 0; i < length; i++) { |
1245 if (HAS_INDEX(array, i, is_array)) { | 1249 if (HAS_INDEX(array, i, is_array)) { |
1246 var element = array[i]; | 1250 var element = array[i]; |
| 1251 // Prepare break slots for debugger step in. |
| 1252 if (stepping) %DebugPrepareStepInIfStepping(f); |
1247 %_Call(f, receiver, element, i, array); | 1253 %_Call(f, receiver, element, i, array); |
1248 } | 1254 } |
1249 } | 1255 } |
1250 } | 1256 } |
1251 | 1257 |
1252 | 1258 |
1253 function ArrayForEach(f, receiver) { | 1259 function ArrayForEach(f, receiver) { |
1254 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | 1260 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
1255 | 1261 |
1256 // Pull out the length so that modifications to the length in the | 1262 // Pull out the length so that modifications to the length in the |
1257 // loop will not affect the looping and side effects are visible. | 1263 // loop will not affect the looping and side effects are visible. |
1258 var array = TO_OBJECT(this); | 1264 var array = TO_OBJECT(this); |
1259 var length = TO_LENGTH_OR_UINT32(array.length); | 1265 var length = TO_LENGTH_OR_UINT32(array.length); |
1260 InnerArrayForEach(f, receiver, array, length); | 1266 InnerArrayForEach(f, receiver, array, length); |
1261 } | 1267 } |
1262 | 1268 |
1263 | 1269 |
1264 function InnerArraySome(f, receiver, array, length) { | 1270 function InnerArraySome(f, receiver, array, length) { |
1265 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1271 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1266 | 1272 |
1267 var is_array = IS_ARRAY(array); | 1273 var is_array = IS_ARRAY(array); |
| 1274 var stepping = DEBUG_IS_STEPPING(f); |
1268 for (var i = 0; i < length; i++) { | 1275 for (var i = 0; i < length; i++) { |
1269 if (HAS_INDEX(array, i, is_array)) { | 1276 if (HAS_INDEX(array, i, is_array)) { |
1270 var element = array[i]; | 1277 var element = array[i]; |
| 1278 // Prepare break slots for debugger step in. |
| 1279 if (stepping) %DebugPrepareStepInIfStepping(f); |
1271 if (%_Call(f, receiver, element, i, array)) return true; | 1280 if (%_Call(f, receiver, element, i, array)) return true; |
1272 } | 1281 } |
1273 } | 1282 } |
1274 return false; | 1283 return false; |
1275 } | 1284 } |
1276 | 1285 |
1277 | 1286 |
1278 // Executes the function once for each element present in the | 1287 // Executes the function once for each element present in the |
1279 // array until it finds one where callback returns true. | 1288 // array until it finds one where callback returns true. |
1280 function ArraySome(f, receiver) { | 1289 function ArraySome(f, receiver) { |
1281 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1290 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
1282 | 1291 |
1283 // Pull out the length so that modifications to the length in the | 1292 // Pull out the length so that modifications to the length in the |
1284 // loop will not affect the looping and side effects are visible. | 1293 // loop will not affect the looping and side effects are visible. |
1285 var array = TO_OBJECT(this); | 1294 var array = TO_OBJECT(this); |
1286 var length = TO_LENGTH_OR_UINT32(array.length); | 1295 var length = TO_LENGTH_OR_UINT32(array.length); |
1287 return InnerArraySome(f, receiver, array, length); | 1296 return InnerArraySome(f, receiver, array, length); |
1288 } | 1297 } |
1289 | 1298 |
1290 | 1299 |
1291 function InnerArrayEvery(f, receiver, array, length) { | 1300 function InnerArrayEvery(f, receiver, array, length) { |
1292 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1301 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1293 | 1302 |
1294 var is_array = IS_ARRAY(array); | 1303 var is_array = IS_ARRAY(array); |
| 1304 var stepping = DEBUG_IS_STEPPING(f); |
1295 for (var i = 0; i < length; i++) { | 1305 for (var i = 0; i < length; i++) { |
1296 if (HAS_INDEX(array, i, is_array)) { | 1306 if (HAS_INDEX(array, i, is_array)) { |
1297 var element = array[i]; | 1307 var element = array[i]; |
| 1308 // Prepare break slots for debugger step in. |
| 1309 if (stepping) %DebugPrepareStepInIfStepping(f); |
1298 if (!%_Call(f, receiver, element, i, array)) return false; | 1310 if (!%_Call(f, receiver, element, i, array)) return false; |
1299 } | 1311 } |
1300 } | 1312 } |
1301 return true; | 1313 return true; |
1302 } | 1314 } |
1303 | 1315 |
1304 function ArrayEvery(f, receiver) { | 1316 function ArrayEvery(f, receiver) { |
1305 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1317 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
1306 | 1318 |
1307 // Pull out the length so that modifications to the length in the | 1319 // Pull out the length so that modifications to the length in the |
1308 // loop will not affect the looping and side effects are visible. | 1320 // loop will not affect the looping and side effects are visible. |
1309 var array = TO_OBJECT(this); | 1321 var array = TO_OBJECT(this); |
1310 var length = TO_LENGTH_OR_UINT32(array.length); | 1322 var length = TO_LENGTH_OR_UINT32(array.length); |
1311 return InnerArrayEvery(f, receiver, array, length); | 1323 return InnerArrayEvery(f, receiver, array, length); |
1312 } | 1324 } |
1313 | 1325 |
1314 | 1326 |
1315 function InnerArrayMap(f, receiver, array, length) { | 1327 function InnerArrayMap(f, receiver, array, length) { |
1316 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1328 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1317 | 1329 |
1318 var accumulator = new InternalArray(length); | 1330 var accumulator = new InternalArray(length); |
1319 var is_array = IS_ARRAY(array); | 1331 var is_array = IS_ARRAY(array); |
| 1332 var stepping = DEBUG_IS_STEPPING(f); |
1320 for (var i = 0; i < length; i++) { | 1333 for (var i = 0; i < length; i++) { |
1321 if (HAS_INDEX(array, i, is_array)) { | 1334 if (HAS_INDEX(array, i, is_array)) { |
1322 var element = array[i]; | 1335 var element = array[i]; |
| 1336 // Prepare break slots for debugger step in. |
| 1337 if (stepping) %DebugPrepareStepInIfStepping(f); |
1323 accumulator[i] = %_Call(f, receiver, element, i, array); | 1338 accumulator[i] = %_Call(f, receiver, element, i, array); |
1324 } | 1339 } |
1325 } | 1340 } |
1326 var result = new GlobalArray(); | 1341 var result = new GlobalArray(); |
1327 %MoveArrayContents(accumulator, result); | 1342 %MoveArrayContents(accumulator, result); |
1328 return result; | 1343 return result; |
1329 } | 1344 } |
1330 | 1345 |
1331 | 1346 |
1332 function ArrayMap(f, receiver) { | 1347 function ArrayMap(f, receiver) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 find_initial: if (argumentsLength < 2) { | 1490 find_initial: if (argumentsLength < 2) { |
1476 for (; i < length; i++) { | 1491 for (; i < length; i++) { |
1477 if (HAS_INDEX(array, i, is_array)) { | 1492 if (HAS_INDEX(array, i, is_array)) { |
1478 current = array[i++]; | 1493 current = array[i++]; |
1479 break find_initial; | 1494 break find_initial; |
1480 } | 1495 } |
1481 } | 1496 } |
1482 throw MakeTypeError(kReduceNoInitial); | 1497 throw MakeTypeError(kReduceNoInitial); |
1483 } | 1498 } |
1484 | 1499 |
| 1500 var stepping = DEBUG_IS_STEPPING(callback); |
1485 for (; i < length; i++) { | 1501 for (; i < length; i++) { |
1486 if (HAS_INDEX(array, i, is_array)) { | 1502 if (HAS_INDEX(array, i, is_array)) { |
1487 var element = array[i]; | 1503 var element = array[i]; |
| 1504 // Prepare break slots for debugger step in. |
| 1505 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1488 current = callback(current, element, i, array); | 1506 current = callback(current, element, i, array); |
1489 } | 1507 } |
1490 } | 1508 } |
1491 return current; | 1509 return current; |
1492 } | 1510 } |
1493 | 1511 |
1494 | 1512 |
1495 function ArrayReduce(callback, current) { | 1513 function ArrayReduce(callback, current) { |
1496 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); | 1514 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); |
1497 | 1515 |
(...skipping 17 matching lines...) Expand all Loading... |
1515 find_initial: if (argumentsLength < 2) { | 1533 find_initial: if (argumentsLength < 2) { |
1516 for (; i >= 0; i--) { | 1534 for (; i >= 0; i--) { |
1517 if (HAS_INDEX(array, i, is_array)) { | 1535 if (HAS_INDEX(array, i, is_array)) { |
1518 current = array[i--]; | 1536 current = array[i--]; |
1519 break find_initial; | 1537 break find_initial; |
1520 } | 1538 } |
1521 } | 1539 } |
1522 throw MakeTypeError(kReduceNoInitial); | 1540 throw MakeTypeError(kReduceNoInitial); |
1523 } | 1541 } |
1524 | 1542 |
| 1543 var stepping = DEBUG_IS_STEPPING(callback); |
1525 for (; i >= 0; i--) { | 1544 for (; i >= 0; i--) { |
1526 if (HAS_INDEX(array, i, is_array)) { | 1545 if (HAS_INDEX(array, i, is_array)) { |
1527 var element = array[i]; | 1546 var element = array[i]; |
| 1547 // Prepare break slots for debugger step in. |
| 1548 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1528 current = callback(current, element, i, array); | 1549 current = callback(current, element, i, array); |
1529 } | 1550 } |
1530 } | 1551 } |
1531 return current; | 1552 return current; |
1532 } | 1553 } |
1533 | 1554 |
1534 | 1555 |
1535 function ArrayReduceRight(callback, current) { | 1556 function ArrayReduceRight(callback, current) { |
1536 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); | 1557 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); |
1537 | 1558 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 %InstallToContext([ | 1950 %InstallToContext([ |
1930 "array_pop", ArrayPop, | 1951 "array_pop", ArrayPop, |
1931 "array_push", ArrayPush, | 1952 "array_push", ArrayPush, |
1932 "array_shift", ArrayShift, | 1953 "array_shift", ArrayShift, |
1933 "array_splice", ArraySplice, | 1954 "array_splice", ArraySplice, |
1934 "array_slice", ArraySlice, | 1955 "array_slice", ArraySlice, |
1935 "array_unshift", ArrayUnshift, | 1956 "array_unshift", ArrayUnshift, |
1936 ]); | 1957 ]); |
1937 | 1958 |
1938 }); | 1959 }); |
OLD | NEW |