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