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 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 function ArrayFill(value, start, end) { | 1485 function ArrayFill(value, start, end) { |
1486 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); | 1486 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
1487 | 1487 |
1488 var array = TO_OBJECT(this); | 1488 var array = TO_OBJECT(this); |
1489 var length = TO_LENGTH(array.length); | 1489 var length = TO_LENGTH(array.length); |
1490 | 1490 |
1491 return InnerArrayFill(value, start, end, array, length); | 1491 return InnerArrayFill(value, start, end, array, length); |
1492 } | 1492 } |
1493 | 1493 |
1494 | 1494 |
1495 function InnerArrayIncludes(searchElement, fromIndex, array, length) { | |
1496 if (length === 0) { | |
1497 return false; | |
1498 } | |
1499 | |
1500 var n = TO_INTEGER(fromIndex); | |
1501 | |
1502 var k; | |
1503 if (n >= 0) { | |
1504 k = n; | |
1505 } else { | |
1506 k = length + n; | |
1507 if (k < 0) { | |
1508 k = 0; | |
1509 } | |
1510 } | |
1511 | |
1512 while (k < length) { | |
1513 var elementK = array[k]; | |
1514 if (%SameValueZero(searchElement, elementK)) { | |
1515 return true; | |
1516 } | |
1517 | |
1518 ++k; | |
1519 } | |
1520 | |
1521 return false; | |
1522 } | |
1523 | |
1524 | |
1525 // ES2016 draft, section 22.1.3.11 | |
1526 function ArrayIncludes(searchElement, fromIndex) { | |
1527 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.includes"); | |
1528 | |
1529 var array = TO_OBJECT(this); | |
1530 var length = TO_LENGTH(array.length); | |
1531 | |
1532 return InnerArrayIncludes(searchElement, fromIndex, array, length); | |
1533 } | |
1534 | |
1535 | |
1536 // ES6, draft 10-14-14, section 22.1.2.1 | 1495 // ES6, draft 10-14-14, section 22.1.2.1 |
1537 function ArrayFrom(arrayLike, mapfn, receiver) { | 1496 function ArrayFrom(arrayLike, mapfn, receiver) { |
1538 var items = TO_OBJECT(arrayLike); | 1497 var items = TO_OBJECT(arrayLike); |
1539 var mapping = !IS_UNDEFINED(mapfn); | 1498 var mapping = !IS_UNDEFINED(mapfn); |
1540 | 1499 |
1541 if (mapping) { | 1500 if (mapping) { |
1542 if (!IS_CALLABLE(mapfn)) { | 1501 if (!IS_CALLABLE(mapfn)) { |
1543 throw MakeTypeError(kCalledNonCallable, mapfn); | 1502 throw MakeTypeError(kCalledNonCallable, mapfn); |
1544 } | 1503 } |
1545 } | 1504 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 "every", getFunction("every", ArrayEvery, 1), | 1629 "every", getFunction("every", ArrayEvery, 1), |
1671 "map", getFunction("map", ArrayMap, 1), | 1630 "map", getFunction("map", ArrayMap, 1), |
1672 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), | 1631 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), |
1673 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1632 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1674 "reduce", getFunction("reduce", ArrayReduce, 1), | 1633 "reduce", getFunction("reduce", ArrayReduce, 1), |
1675 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1), | 1634 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1), |
1676 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2), | 1635 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2), |
1677 "find", getFunction("find", ArrayFind, 1), | 1636 "find", getFunction("find", ArrayFind, 1), |
1678 "findIndex", getFunction("findIndex", ArrayFindIndex, 1), | 1637 "findIndex", getFunction("findIndex", ArrayFindIndex, 1), |
1679 "fill", getFunction("fill", ArrayFill, 1), | 1638 "fill", getFunction("fill", ArrayFill, 1), |
1680 "includes", getFunction("includes", ArrayIncludes, 1), | 1639 "includes", getFunction("includes", null, 1) |
1681 ]); | 1640 ]); |
1682 | 1641 |
1683 utils.InstallGetter(GlobalArray, speciesSymbol, ArraySpecies); | 1642 utils.InstallGetter(GlobalArray, speciesSymbol, ArraySpecies); |
1684 | 1643 |
1685 %FinishArrayPrototypeSetup(GlobalArray.prototype); | 1644 %FinishArrayPrototypeSetup(GlobalArray.prototype); |
1686 | 1645 |
1687 // The internal Array prototype doesn't need to be fancy, since it's never | 1646 // The internal Array prototype doesn't need to be fancy, since it's never |
1688 // exposed to user code. | 1647 // exposed to user code. |
1689 // Adding only the functions that are actually used. | 1648 // Adding only the functions that are actually used. |
1690 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ | 1649 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 to.ArrayJoin = ArrayJoin; | 1683 to.ArrayJoin = ArrayJoin; |
1725 to.ArrayPush = ArrayPush; | 1684 to.ArrayPush = ArrayPush; |
1726 to.ArrayToString = ArrayToString; | 1685 to.ArrayToString = ArrayToString; |
1727 to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 1686 to.InnerArrayCopyWithin = InnerArrayCopyWithin; |
1728 to.InnerArrayEvery = InnerArrayEvery; | 1687 to.InnerArrayEvery = InnerArrayEvery; |
1729 to.InnerArrayFill = InnerArrayFill; | 1688 to.InnerArrayFill = InnerArrayFill; |
1730 to.InnerArrayFilter = InnerArrayFilter; | 1689 to.InnerArrayFilter = InnerArrayFilter; |
1731 to.InnerArrayFind = InnerArrayFind; | 1690 to.InnerArrayFind = InnerArrayFind; |
1732 to.InnerArrayFindIndex = InnerArrayFindIndex; | 1691 to.InnerArrayFindIndex = InnerArrayFindIndex; |
1733 to.InnerArrayForEach = InnerArrayForEach; | 1692 to.InnerArrayForEach = InnerArrayForEach; |
1734 to.InnerArrayIncludes = InnerArrayIncludes; | |
1735 to.InnerArrayIndexOf = InnerArrayIndexOf; | 1693 to.InnerArrayIndexOf = InnerArrayIndexOf; |
1736 to.InnerArrayJoin = InnerArrayJoin; | 1694 to.InnerArrayJoin = InnerArrayJoin; |
1737 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; | 1695 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; |
1738 to.InnerArrayReduce = InnerArrayReduce; | 1696 to.InnerArrayReduce = InnerArrayReduce; |
1739 to.InnerArrayReduceRight = InnerArrayReduceRight; | 1697 to.InnerArrayReduceRight = InnerArrayReduceRight; |
1740 to.InnerArraySome = InnerArraySome; | 1698 to.InnerArraySome = InnerArraySome; |
1741 to.InnerArraySort = InnerArraySort; | 1699 to.InnerArraySort = InnerArraySort; |
1742 to.InnerArrayToLocaleString = InnerArrayToLocaleString; | 1700 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1743 to.PackedArrayReverse = PackedArrayReverse; | 1701 to.PackedArrayReverse = PackedArrayReverse; |
1744 }); | 1702 }); |
1745 | 1703 |
1746 %InstallToContext([ | 1704 %InstallToContext([ |
1747 "array_pop", ArrayPop, | 1705 "array_pop", ArrayPop, |
1748 "array_push", ArrayPush, | 1706 "array_push", ArrayPush, |
1749 "array_shift", ArrayShift, | 1707 "array_shift", ArrayShift, |
1750 "array_splice", ArraySplice, | 1708 "array_splice", ArraySplice, |
1751 "array_slice", ArraySlice, | 1709 "array_slice", ArraySlice, |
1752 "array_unshift", ArrayUnshift, | 1710 "array_unshift", ArrayUnshift, |
1753 ]); | 1711 ]); |
1754 | 1712 |
1755 }); | 1713 }); |
OLD | NEW |