OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 %FunctionSetName(getter, name); | 72 %FunctionSetName(getter, name); |
73 %FunctionSetName(setter, name); | 73 %FunctionSetName(setter, name); |
74 %FunctionRemovePrototype(getter); | 74 %FunctionRemovePrototype(getter); |
75 %FunctionRemovePrototype(setter); | 75 %FunctionRemovePrototype(setter); |
76 %DefineOrRedefineAccessorProperty(object, name, getter, setter, DONT_ENUM); | 76 %DefineOrRedefineAccessorProperty(object, name, getter, setter, DONT_ENUM); |
77 %SetNativeFlag(getter); | 77 %SetNativeFlag(getter); |
78 %SetNativeFlag(setter); | 78 %SetNativeFlag(setter); |
79 } | 79 } |
80 | 80 |
81 | 81 |
| 82 // Helper function for installing constant properties on objects. |
| 83 function InstallConstants(object, constants) { |
| 84 if (constants.length >= 4) { |
| 85 %OptimizeObjectForAddingMultipleProperties(object, constants.length >> 1); |
| 86 } |
| 87 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
| 88 for (var i = 0; i < constants.length; i += 2) { |
| 89 var name = constants[i]; |
| 90 var k = constants[i + 1]; |
| 91 %SetProperty(object, name, k, attributes); |
| 92 } |
| 93 %ToFastProperties(object); |
| 94 } |
| 95 |
| 96 |
82 // Prevents changes to the prototype of a built-in function. | 97 // Prevents changes to the prototype of a built-in function. |
83 // The "prototype" property of the function object is made non-configurable, | 98 // The "prototype" property of the function object is made non-configurable, |
84 // and the prototype object is made non-extensible. The latter prevents | 99 // and the prototype object is made non-extensible. The latter prevents |
85 // changing the __proto__ property. | 100 // changing the __proto__ property. |
86 function SetUpLockedPrototype(constructor, fields, methods) { | 101 function SetUpLockedPrototype(constructor, fields, methods) { |
87 %CheckIsBootstrapping(); | 102 %CheckIsBootstrapping(); |
88 var prototype = constructor.prototype; | 103 var prototype = constructor.prototype; |
89 // Install functions first, because this function is used to initialize | 104 // Install functions first, because this function is used to initialize |
90 // PropertyDescriptor itself. | 105 // PropertyDescriptor itself. |
91 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); | 106 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); |
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 return %NumberToPrecision(x, p); | 1632 return %NumberToPrecision(x, p); |
1618 } | 1633 } |
1619 | 1634 |
1620 | 1635 |
1621 // Harmony isFinite. | 1636 // Harmony isFinite. |
1622 function NumberIsFinite(number) { | 1637 function NumberIsFinite(number) { |
1623 return IS_NUMBER(number) && NUMBER_IS_FINITE(number); | 1638 return IS_NUMBER(number) && NUMBER_IS_FINITE(number); |
1624 } | 1639 } |
1625 | 1640 |
1626 | 1641 |
| 1642 // Harmony isInteger |
| 1643 function NumberIsInteger(number) { |
| 1644 return NumberIsFinite(number) && TO_INTEGER(number) == number; |
| 1645 } |
| 1646 |
| 1647 |
1627 // Harmony isNaN. | 1648 // Harmony isNaN. |
1628 function NumberIsNaN(number) { | 1649 function NumberIsNaN(number) { |
1629 return IS_NUMBER(number) && NUMBER_IS_NAN(number); | 1650 return IS_NUMBER(number) && NUMBER_IS_NAN(number); |
1630 } | 1651 } |
1631 | 1652 |
1632 | 1653 |
| 1654 // Harmony isSafeInteger |
| 1655 function NumberIsSafeInteger(number) { |
| 1656 if (NumberIsFinite(number)) { |
| 1657 var integral = TO_INTEGER(number); |
| 1658 if (integral == number) |
| 1659 return MathAbs(integral) <= $Number.MAX_SAFE_INTEGER; |
| 1660 } |
| 1661 return false; |
| 1662 } |
| 1663 |
| 1664 |
1633 // ---------------------------------------------------------------------------- | 1665 // ---------------------------------------------------------------------------- |
1634 | 1666 |
1635 function SetUpNumber() { | 1667 function SetUpNumber() { |
1636 %CheckIsBootstrapping(); | 1668 %CheckIsBootstrapping(); |
1637 | 1669 |
1638 %SetCode($Number, NumberConstructor); | 1670 %SetCode($Number, NumberConstructor); |
1639 %FunctionSetPrototype($Number, new $Number(0)); | 1671 %FunctionSetPrototype($Number, new $Number(0)); |
1640 | 1672 |
1641 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); | 1673 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
1642 // Set up the constructor property on the Number prototype object. | 1674 // Set up the constructor property on the Number prototype object. |
1643 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 1675 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
1644 | 1676 |
1645 %OptimizeObjectForAddingMultipleProperties($Number, 5); | 1677 InstallConstants($Number, $Array( |
1646 // ECMA-262 section 15.7.3.1. | 1678 // ECMA-262 section 15.7.3.1. |
1647 %SetProperty($Number, | 1679 "MAX_VALUE", 1.7976931348623157e+308, |
1648 "MAX_VALUE", | 1680 // ECMA-262 section 15.7.3.2. |
1649 1.7976931348623157e+308, | 1681 "MIN_VALUE", 5e-324, |
1650 DONT_ENUM | DONT_DELETE | READ_ONLY); | 1682 // ECMA-262 section 15.7.3.3. |
| 1683 "NaN", NAN, |
| 1684 // ECMA-262 section 15.7.3.4. |
| 1685 "NEGATIVE_INFINITY", -INFINITY, |
| 1686 // ECMA-262 section 15.7.3.5. |
| 1687 "POSITIVE_INFINITY", INFINITY, |
1651 | 1688 |
1652 // ECMA-262 section 15.7.3.2. | 1689 // --- Harmony constants (no spec refs until settled.) |
1653 %SetProperty($Number, "MIN_VALUE", 5e-324, | |
1654 DONT_ENUM | DONT_DELETE | READ_ONLY); | |
1655 | 1690 |
1656 // ECMA-262 section 15.7.3.3. | 1691 "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1, |
1657 %SetProperty($Number, "NaN", NAN, DONT_ENUM | DONT_DELETE | READ_ONLY); | 1692 "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1, |
1658 | 1693 "EPSILON", %_MathPow(2, -52) |
1659 // ECMA-262 section 15.7.3.4. | 1694 )); |
1660 %SetProperty($Number, | |
1661 "NEGATIVE_INFINITY", | |
1662 -INFINITY, | |
1663 DONT_ENUM | DONT_DELETE | READ_ONLY); | |
1664 | |
1665 // ECMA-262 section 15.7.3.5. | |
1666 %SetProperty($Number, | |
1667 "POSITIVE_INFINITY", | |
1668 INFINITY, | |
1669 DONT_ENUM | DONT_DELETE | READ_ONLY); | |
1670 %ToFastProperties($Number); | |
1671 | 1695 |
1672 // Set up non-enumerable functions on the Number prototype object. | 1696 // Set up non-enumerable functions on the Number prototype object. |
1673 InstallFunctions($Number.prototype, DONT_ENUM, $Array( | 1697 InstallFunctions($Number.prototype, DONT_ENUM, $Array( |
1674 "toString", NumberToString, | 1698 "toString", NumberToString, |
1675 "toLocaleString", NumberToLocaleString, | 1699 "toLocaleString", NumberToLocaleString, |
1676 "valueOf", NumberValueOf, | 1700 "valueOf", NumberValueOf, |
1677 "toFixed", NumberToFixed, | 1701 "toFixed", NumberToFixed, |
1678 "toExponential", NumberToExponential, | 1702 "toExponential", NumberToExponential, |
1679 "toPrecision", NumberToPrecision | 1703 "toPrecision", NumberToPrecision |
1680 )); | 1704 )); |
| 1705 |
| 1706 // Harmony Number constructor additions |
1681 InstallFunctions($Number, DONT_ENUM, $Array( | 1707 InstallFunctions($Number, DONT_ENUM, $Array( |
1682 "isFinite", NumberIsFinite, | 1708 "isFinite", NumberIsFinite, |
1683 "isNaN", NumberIsNaN | 1709 "isInteger", NumberIsInteger, |
| 1710 "isNaN", NumberIsNaN, |
| 1711 "isSafeInteger", NumberIsSafeInteger, |
| 1712 "parseInt", GlobalParseInt, |
| 1713 "parseFloat", GlobalParseFloat |
1684 )); | 1714 )); |
1685 } | 1715 } |
1686 | 1716 |
1687 SetUpNumber(); | 1717 SetUpNumber(); |
1688 | 1718 |
1689 | 1719 |
1690 // ---------------------------------------------------------------------------- | 1720 // ---------------------------------------------------------------------------- |
1691 // Function | 1721 // Function |
1692 | 1722 |
1693 function FunctionSourceString(func) { | 1723 function FunctionSourceString(func) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 // Eventually, we should move to a real event queue that allows to maintain | 1874 // Eventually, we should move to a real event queue that allows to maintain |
1845 // relative ordering of different kinds of tasks. | 1875 // relative ordering of different kinds of tasks. |
1846 | 1876 |
1847 RunMicrotasks.runners = new InternalArray; | 1877 RunMicrotasks.runners = new InternalArray; |
1848 | 1878 |
1849 function RunMicrotasks() { | 1879 function RunMicrotasks() { |
1850 while (%SetMicrotaskPending(false)) { | 1880 while (%SetMicrotaskPending(false)) { |
1851 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); | 1881 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); |
1852 } | 1882 } |
1853 } | 1883 } |
OLD | NEW |