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 $arrayPush; | 6 var $arrayPush; |
7 var $arrayPop; | 7 var $arrayPop; |
8 var $arrayShift; | 8 var $arrayShift; |
9 var $arraySlice; | 9 var $arraySlice; |
10 var $arraySplice; | 10 var $arraySplice; |
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 | 1485 |
1486 function ArrayLastIndexOf(element, index) { | 1486 function ArrayLastIndexOf(element, index) { |
1487 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); | 1487 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); |
1488 | 1488 |
1489 var length = TO_UINT32(this.length); | 1489 var length = TO_UINT32(this.length); |
1490 return %_CallFunction(this, element, index, length, | 1490 return %_CallFunction(this, element, index, length, |
1491 %_ArgumentsLength(), InnerArrayLastIndexOf); | 1491 %_ArgumentsLength(), InnerArrayLastIndexOf); |
1492 } | 1492 } |
1493 | 1493 |
1494 | 1494 |
1495 function ArrayReduce(callback, current) { | 1495 function InnerArrayReduce(callback, current, array, length, argumentsLength) { |
1496 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); | |
1497 | |
1498 // Pull out the length so that modifications to the length in the | |
1499 // loop will not affect the looping and side effects are visible. | |
1500 var array = $toObject(this); | |
1501 var length = $toUint32(array.length); | |
1502 | |
1503 if (!IS_SPEC_FUNCTION(callback)) { | 1496 if (!IS_SPEC_FUNCTION(callback)) { |
1504 throw MakeTypeError(kCalledNonCallable, callback); | 1497 throw MakeTypeError(kCalledNonCallable, callback); |
1505 } | 1498 } |
1506 | 1499 |
1507 var is_array = IS_ARRAY(array); | 1500 var is_array = IS_ARRAY(array); |
1508 var i = 0; | 1501 var i = 0; |
1509 find_initial: if (%_ArgumentsLength() < 2) { | 1502 find_initial: if (argumentsLength < 2) { |
1510 for (; i < length; i++) { | 1503 for (; i < length; i++) { |
1511 if (HAS_INDEX(array, i, is_array)) { | 1504 if (HAS_INDEX(array, i, is_array)) { |
1512 current = array[i++]; | 1505 current = array[i++]; |
1513 break find_initial; | 1506 break find_initial; |
1514 } | 1507 } |
1515 } | 1508 } |
1516 throw MakeTypeError(kReduceNoInitial); | 1509 throw MakeTypeError(kReduceNoInitial); |
1517 } | 1510 } |
1518 | 1511 |
1519 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1512 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
1520 for (; i < length; i++) { | 1513 for (; i < length; i++) { |
1521 if (HAS_INDEX(array, i, is_array)) { | 1514 if (HAS_INDEX(array, i, is_array)) { |
1522 var element = array[i]; | 1515 var element = array[i]; |
1523 // Prepare break slots for debugger step in. | 1516 // Prepare break slots for debugger step in. |
1524 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1517 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1525 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); | 1518 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); |
1526 } | 1519 } |
1527 } | 1520 } |
1528 return current; | 1521 return current; |
1529 } | 1522 } |
1530 | 1523 |
1531 | 1524 |
1532 function ArrayReduceRight(callback, current) { | 1525 function ArrayReduce(callback, current) { |
1533 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); | 1526 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); |
1534 | 1527 |
1535 // Pull out the length so that side effects are visible before the | 1528 // Pull out the length so that modifications to the length in the |
1536 // callback function is checked. | 1529 // loop will not affect the looping and side effects are visible. |
1537 var array = $toObject(this); | 1530 var array = $toObject(this); |
1538 var length = $toUint32(array.length); | 1531 var length = $toUint32(array.length); |
| 1532 return InnerArrayReduce(callback, current, array, length, |
| 1533 %_ArgumentsLength()); |
| 1534 } |
1539 | 1535 |
| 1536 |
| 1537 function InnerArrayReduceRight(callback, current, array, length, |
| 1538 argumentsLength) { |
1540 if (!IS_SPEC_FUNCTION(callback)) { | 1539 if (!IS_SPEC_FUNCTION(callback)) { |
1541 throw MakeTypeError(kCalledNonCallable, callback); | 1540 throw MakeTypeError(kCalledNonCallable, callback); |
1542 } | 1541 } |
1543 | 1542 |
1544 var is_array = IS_ARRAY(array); | 1543 var is_array = IS_ARRAY(array); |
1545 var i = length - 1; | 1544 var i = length - 1; |
1546 find_initial: if (%_ArgumentsLength() < 2) { | 1545 find_initial: if (argumentsLength < 2) { |
1547 for (; i >= 0; i--) { | 1546 for (; i >= 0; i--) { |
1548 if (HAS_INDEX(array, i, is_array)) { | 1547 if (HAS_INDEX(array, i, is_array)) { |
1549 current = array[i--]; | 1548 current = array[i--]; |
1550 break find_initial; | 1549 break find_initial; |
1551 } | 1550 } |
1552 } | 1551 } |
1553 throw MakeTypeError(kReduceNoInitial); | 1552 throw MakeTypeError(kReduceNoInitial); |
1554 } | 1553 } |
1555 | 1554 |
1556 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1555 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
1557 for (; i >= 0; i--) { | 1556 for (; i >= 0; i--) { |
1558 if (HAS_INDEX(array, i, is_array)) { | 1557 if (HAS_INDEX(array, i, is_array)) { |
1559 var element = array[i]; | 1558 var element = array[i]; |
1560 // Prepare break slots for debugger step in. | 1559 // Prepare break slots for debugger step in. |
1561 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1560 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1562 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); | 1561 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); |
1563 } | 1562 } |
1564 } | 1563 } |
1565 return current; | 1564 return current; |
1566 } | 1565 } |
1567 | 1566 |
| 1567 |
| 1568 function ArrayReduceRight(callback, current) { |
| 1569 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); |
| 1570 |
| 1571 // Pull out the length so that side effects are visible before the |
| 1572 // callback function is checked. |
| 1573 var array = $toObject(this); |
| 1574 var length = $toUint32(array.length); |
| 1575 return InnerArrayReduceRight(callback, current, array, length, |
| 1576 %_ArgumentsLength()); |
| 1577 } |
| 1578 |
1568 // ES5, 15.4.3.2 | 1579 // ES5, 15.4.3.2 |
1569 function ArrayIsArray(obj) { | 1580 function ArrayIsArray(obj) { |
1570 return IS_ARRAY(obj); | 1581 return IS_ARRAY(obj); |
1571 } | 1582 } |
1572 | 1583 |
1573 | 1584 |
1574 // ------------------------------------------------------------------- | 1585 // ------------------------------------------------------------------- |
1575 | 1586 |
1576 // Set up non-enumerable constructor property on the Array.prototype | 1587 // Set up non-enumerable constructor property on the Array.prototype |
1577 // object. | 1588 // object. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 utils.Export(function(to) { | 1677 utils.Export(function(to) { |
1667 to.ArrayJoin = ArrayJoin; | 1678 to.ArrayJoin = ArrayJoin; |
1668 to.ArrayToString = ArrayToString; | 1679 to.ArrayToString = ArrayToString; |
1669 to.InnerArrayEvery = InnerArrayEvery; | 1680 to.InnerArrayEvery = InnerArrayEvery; |
1670 to.InnerArrayFilter = InnerArrayFilter; | 1681 to.InnerArrayFilter = InnerArrayFilter; |
1671 to.InnerArrayForEach = InnerArrayForEach; | 1682 to.InnerArrayForEach = InnerArrayForEach; |
1672 to.InnerArrayIndexOf = InnerArrayIndexOf; | 1683 to.InnerArrayIndexOf = InnerArrayIndexOf; |
1673 to.InnerArrayJoin = InnerArrayJoin; | 1684 to.InnerArrayJoin = InnerArrayJoin; |
1674 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; | 1685 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; |
1675 to.InnerArrayMap = InnerArrayMap; | 1686 to.InnerArrayMap = InnerArrayMap; |
| 1687 to.InnerArrayReduce = InnerArrayReduce; |
| 1688 to.InnerArrayReduceRight = InnerArrayReduceRight; |
1676 to.InnerArrayReverse = InnerArrayReverse; | 1689 to.InnerArrayReverse = InnerArrayReverse; |
1677 to.InnerArraySome = InnerArraySome; | 1690 to.InnerArraySome = InnerArraySome; |
1678 to.InnerArraySort = InnerArraySort; | 1691 to.InnerArraySort = InnerArraySort; |
1679 to.InnerArrayToLocaleString = InnerArrayToLocaleString; | 1692 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1680 }); | 1693 }); |
1681 | 1694 |
1682 $arrayConcat = ArrayConcatJS; | 1695 $arrayConcat = ArrayConcatJS; |
1683 $arrayPush = ArrayPush; | 1696 $arrayPush = ArrayPush; |
1684 $arrayPop = ArrayPop; | 1697 $arrayPop = ArrayPop; |
1685 $arrayShift = ArrayShift; | 1698 $arrayShift = ArrayShift; |
1686 $arraySlice = ArraySlice; | 1699 $arraySlice = ArraySlice; |
1687 $arraySplice = ArraySplice; | 1700 $arraySplice = ArraySplice; |
1688 $arrayUnshift = ArrayUnshift; | 1701 $arrayUnshift = ArrayUnshift; |
1689 | 1702 |
1690 }); | 1703 }); |
OLD | NEW |