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 var $arrayConcat; | 5 var $arrayConcat; |
6 var $arrayJoin; | 6 var $arrayJoin; |
7 var $arrayPush; | 7 var $arrayPush; |
8 var $arrayPop; | 8 var $arrayPop; |
9 var $arrayShift; | 9 var $arrayShift; |
10 var $arraySlice; | 10 var $arraySlice; |
11 var $arraySplice; | 11 var $arraySplice; |
12 var $arrayUnshift; | 12 var $arrayUnshift; |
13 var $innerArrayForEach; | 13 var $innerArrayForEach; |
14 var $innerArrayEvery; | 14 var $innerArrayEvery; |
| 15 var $innerArrayIndexOf; |
| 16 var $innerArrayLastIndexOf; |
15 | 17 |
16 (function(global, shared, exports) { | 18 (function(global, shared, exports) { |
17 | 19 |
18 "use strict"; | 20 "use strict"; |
19 | 21 |
20 %CheckIsBootstrapping(); | 22 %CheckIsBootstrapping(); |
21 | 23 |
22 // ------------------------------------------------------------------- | 24 // ------------------------------------------------------------------- |
23 // Imports | 25 // Imports |
24 | 26 |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 if (stepping) %DebugPrepareStepInIfStepping(f); | 1315 if (stepping) %DebugPrepareStepInIfStepping(f); |
1314 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1316 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
1315 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); | 1317 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
1316 } | 1318 } |
1317 } | 1319 } |
1318 %MoveArrayContents(accumulator, result); | 1320 %MoveArrayContents(accumulator, result); |
1319 return result; | 1321 return result; |
1320 } | 1322 } |
1321 | 1323 |
1322 | 1324 |
1323 function ArrayIndexOf(element, index) { | 1325 // For .indexOf, we don't need to pass in the number of arguments |
1324 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); | 1326 // at the callsite since ToInteger(undefined) == 0; however, for |
1325 | 1327 // .lastIndexOf, we need to pass it, since the behavior for passing |
1326 var length = TO_UINT32(this.length); | 1328 // undefined is 0 but for not including the argument is length-1. |
| 1329 function InnerArrayIndexOf(element, index, length) { |
1327 if (length == 0) return -1; | 1330 if (length == 0) return -1; |
1328 if (IS_UNDEFINED(index)) { | 1331 if (IS_UNDEFINED(index)) { |
1329 index = 0; | 1332 index = 0; |
1330 } else { | 1333 } else { |
1331 index = TO_INTEGER(index); | 1334 index = TO_INTEGER(index); |
1332 // If index is negative, index from the end of the array. | 1335 // If index is negative, index from the end of the array. |
1333 if (index < 0) { | 1336 if (index < 0) { |
1334 index = length + index; | 1337 index = length + index; |
1335 // If index is still negative, search the entire array. | 1338 // If index is still negative, search the entire array. |
1336 if (index < 0) index = 0; | 1339 if (index < 0) index = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 // Lookup through the array. | 1373 // Lookup through the array. |
1371 for (var i = min; i < max; i++) { | 1374 for (var i = min; i < max; i++) { |
1372 if (IS_UNDEFINED(this[i]) && i in this) { | 1375 if (IS_UNDEFINED(this[i]) && i in this) { |
1373 return i; | 1376 return i; |
1374 } | 1377 } |
1375 } | 1378 } |
1376 return -1; | 1379 return -1; |
1377 } | 1380 } |
1378 | 1381 |
1379 | 1382 |
1380 function ArrayLastIndexOf(element, index) { | 1383 function ArrayIndexOf(element, index) { |
1381 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); | 1384 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); |
1382 | 1385 |
1383 var length = TO_UINT32(this.length); | 1386 var length = TO_UINT32(this.length); |
| 1387 return %_CallFunction(this, element, index, length, InnerArrayIndexOf); |
| 1388 } |
| 1389 |
| 1390 |
| 1391 function InnerArrayLastIndexOf(element, index, length, argumentsLength) { |
1384 if (length == 0) return -1; | 1392 if (length == 0) return -1; |
1385 if (%_ArgumentsLength() < 2) { | 1393 if (argumentsLength < 2) { |
1386 index = length - 1; | 1394 index = length - 1; |
1387 } else { | 1395 } else { |
1388 index = TO_INTEGER(index); | 1396 index = TO_INTEGER(index); |
1389 // If index is negative, index from end of the array. | 1397 // If index is negative, index from end of the array. |
1390 if (index < 0) index += length; | 1398 if (index < 0) index += length; |
1391 // If index is still negative, do not search the array. | 1399 // If index is still negative, do not search the array. |
1392 if (index < 0) return -1; | 1400 if (index < 0) return -1; |
1393 else if (index >= length) index = length - 1; | 1401 else if (index >= length) index = length - 1; |
1394 } | 1402 } |
1395 var min = 0; | 1403 var min = 0; |
(...skipping 27 matching lines...) Expand all Loading... |
1423 } | 1431 } |
1424 for (var i = max; i >= min; i--) { | 1432 for (var i = max; i >= min; i--) { |
1425 if (IS_UNDEFINED(this[i]) && i in this) { | 1433 if (IS_UNDEFINED(this[i]) && i in this) { |
1426 return i; | 1434 return i; |
1427 } | 1435 } |
1428 } | 1436 } |
1429 return -1; | 1437 return -1; |
1430 } | 1438 } |
1431 | 1439 |
1432 | 1440 |
| 1441 function ArrayLastIndexOf(element, index) { |
| 1442 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); |
| 1443 |
| 1444 var length = TO_UINT32(this.length); |
| 1445 return %_CallFunction(this, element, index, length, |
| 1446 %_ArgumentsLength(), InnerArrayLastIndexOf); |
| 1447 } |
| 1448 |
| 1449 |
1433 function ArrayReduce(callback, current) { | 1450 function ArrayReduce(callback, current) { |
1434 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); | 1451 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); |
1435 | 1452 |
1436 // Pull out the length so that modifications to the length in the | 1453 // Pull out the length so that modifications to the length in the |
1437 // loop will not affect the looping and side effects are visible. | 1454 // loop will not affect the looping and side effects are visible. |
1438 var array = $toObject(this); | 1455 var array = $toObject(this); |
1439 var length = $toUint32(array.length); | 1456 var length = $toUint32(array.length); |
1440 | 1457 |
1441 if (!IS_SPEC_FUNCTION(callback)) { | 1458 if (!IS_SPEC_FUNCTION(callback)) { |
1442 throw MakeTypeError(kCalledNonCallable, callback); | 1459 throw MakeTypeError(kCalledNonCallable, callback); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 $arrayJoin = ArrayJoin; | 1619 $arrayJoin = ArrayJoin; |
1603 $arrayPush = ArrayPush; | 1620 $arrayPush = ArrayPush; |
1604 $arrayPop = ArrayPop; | 1621 $arrayPop = ArrayPop; |
1605 $arrayShift = ArrayShift; | 1622 $arrayShift = ArrayShift; |
1606 $arraySlice = ArraySlice; | 1623 $arraySlice = ArraySlice; |
1607 $arraySplice = ArraySplice; | 1624 $arraySplice = ArraySplice; |
1608 $arrayUnshift = ArrayUnshift; | 1625 $arrayUnshift = ArrayUnshift; |
1609 | 1626 |
1610 $innerArrayForEach = InnerArrayForEach; | 1627 $innerArrayForEach = InnerArrayForEach; |
1611 $innerArrayEvery = InnerArrayEvery; | 1628 $innerArrayEvery = InnerArrayEvery; |
| 1629 $innerArrayIndexOf = InnerArrayIndexOf; |
| 1630 $innerArrayLastIndexOf = InnerArrayLastIndexOf; |
1612 | 1631 |
1613 }); | 1632 }); |
OLD | NEW |