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