| 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 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
| 6 // in runtime.js: | 6 // in runtime.js: |
| 7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
| 8 // var $Boolean = global.Boolean; | 8 // var $Boolean = global.Boolean; |
| 9 // var $Number = global.Number; | 9 // var $Number = global.Number; |
| 10 // var $Function = global.Function; | 10 // var $Function = global.Function; |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); | 1515 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); |
| 1516 if (%_IsConstructCall()) { | 1516 if (%_IsConstructCall()) { |
| 1517 %_SetValueOf(this, value); | 1517 %_SetValueOf(this, value); |
| 1518 } else { | 1518 } else { |
| 1519 return value; | 1519 return value; |
| 1520 } | 1520 } |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 | 1523 |
| 1524 // ECMA-262 section 15.7.4.2. | 1524 // ECMA-262 section 15.7.4.2. |
| 1525 function NumberToString(radix) { | 1525 function NumberToStringJS(radix) { |
| 1526 // NOTE: Both Number objects and values can enter here as | 1526 // NOTE: Both Number objects and values can enter here as |
| 1527 // 'this'. This is not as dictated by ECMA-262. | 1527 // 'this'. This is not as dictated by ECMA-262. |
| 1528 var number = this; | 1528 var number = this; |
| 1529 if (!IS_NUMBER(this)) { | 1529 if (!IS_NUMBER(this)) { |
| 1530 if (!IS_NUMBER_WRAPPER(this)) { | 1530 if (!IS_NUMBER_WRAPPER(this)) { |
| 1531 throw new $TypeError('Number.prototype.toString is not generic'); | 1531 throw new $TypeError('Number.prototype.toString is not generic'); |
| 1532 } | 1532 } |
| 1533 // Get the value of this number in case it's an object. | 1533 // Get the value of this number in case it's an object. |
| 1534 number = %_ValueOf(this); | 1534 number = %_ValueOf(this); |
| 1535 } | 1535 } |
| 1536 // Fast case: Convert number in radix 10. | 1536 // Fast case: Convert number in radix 10. |
| 1537 if (IS_UNDEFINED(radix) || radix === 10) { | 1537 if (IS_UNDEFINED(radix) || radix === 10) { |
| 1538 return %_NumberToString(number); | 1538 return %_NumberToString(number); |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 // Convert the radix to an integer and check the range. | 1541 // Convert the radix to an integer and check the range. |
| 1542 radix = TO_INTEGER(radix); | 1542 radix = TO_INTEGER(radix); |
| 1543 if (radix < 2 || radix > 36) { | 1543 if (radix < 2 || radix > 36) { |
| 1544 throw new $RangeError('toString() radix argument must be between 2 and 36'); | 1544 throw new $RangeError('toString() radix argument must be between 2 and 36'); |
| 1545 } | 1545 } |
| 1546 // Convert the number to a string in the given radix. | 1546 // Convert the number to a string in the given radix. |
| 1547 return %NumberToRadixString(number, radix); | 1547 return %NumberToRadixString(number, radix); |
| 1548 } | 1548 } |
| 1549 | 1549 |
| 1550 | 1550 |
| 1551 // ECMA-262 section 15.7.4.3 | 1551 // ECMA-262 section 15.7.4.3 |
| 1552 function NumberToLocaleString() { | 1552 function NumberToLocaleString() { |
| 1553 return %_CallFunction(this, NumberToString); | 1553 return %_CallFunction(this, NumberToStringJS); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 | 1556 |
| 1557 // ECMA-262 section 15.7.4.4 | 1557 // ECMA-262 section 15.7.4.4 |
| 1558 function NumberValueOf() { | 1558 function NumberValueOf() { |
| 1559 // NOTE: Both Number objects and values can enter here as | 1559 // NOTE: Both Number objects and values can enter here as |
| 1560 // 'this'. This is not as dictated by ECMA-262. | 1560 // 'this'. This is not as dictated by ECMA-262. |
| 1561 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) { | 1561 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) { |
| 1562 throw new $TypeError('Number.prototype.valueOf is not generic'); | 1562 throw new $TypeError('Number.prototype.valueOf is not generic'); |
| 1563 } | 1563 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 | 1695 |
| 1696 // --- Harmony constants (no spec refs until settled.) | 1696 // --- Harmony constants (no spec refs until settled.) |
| 1697 | 1697 |
| 1698 "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1, | 1698 "MAX_SAFE_INTEGER", %_MathPow(2, 53) - 1, |
| 1699 "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1, | 1699 "MIN_SAFE_INTEGER", -%_MathPow(2, 53) + 1, |
| 1700 "EPSILON", %_MathPow(2, -52) | 1700 "EPSILON", %_MathPow(2, -52) |
| 1701 )); | 1701 )); |
| 1702 | 1702 |
| 1703 // Set up non-enumerable functions on the Number prototype object. | 1703 // Set up non-enumerable functions on the Number prototype object. |
| 1704 InstallFunctions($Number.prototype, DONT_ENUM, $Array( | 1704 InstallFunctions($Number.prototype, DONT_ENUM, $Array( |
| 1705 "toString", NumberToString, | 1705 "toString", NumberToStringJS, |
| 1706 "toLocaleString", NumberToLocaleString, | 1706 "toLocaleString", NumberToLocaleString, |
| 1707 "valueOf", NumberValueOf, | 1707 "valueOf", NumberValueOf, |
| 1708 "toFixed", NumberToFixedJS, | 1708 "toFixed", NumberToFixedJS, |
| 1709 "toExponential", NumberToExponentialJS, | 1709 "toExponential", NumberToExponentialJS, |
| 1710 "toPrecision", NumberToPrecisionJS | 1710 "toPrecision", NumberToPrecisionJS |
| 1711 )); | 1711 )); |
| 1712 | 1712 |
| 1713 // Harmony Number constructor additions | 1713 // Harmony Number constructor additions |
| 1714 InstallFunctions($Number, DONT_ENUM, $Array( | 1714 InstallFunctions($Number, DONT_ENUM, $Array( |
| 1715 "isFinite", NumberIsFinite, | 1715 "isFinite", NumberIsFinite, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 } | 1894 } |
| 1895 if (!IS_SPEC_FUNCTION(method)) { | 1895 if (!IS_SPEC_FUNCTION(method)) { |
| 1896 throw MakeTypeError('not_iterable', [obj]); | 1896 throw MakeTypeError('not_iterable', [obj]); |
| 1897 } | 1897 } |
| 1898 var iterator = %_CallFunction(obj, method); | 1898 var iterator = %_CallFunction(obj, method); |
| 1899 if (!IS_SPEC_OBJECT(iterator)) { | 1899 if (!IS_SPEC_OBJECT(iterator)) { |
| 1900 throw MakeTypeError('not_an_iterator', [iterator]); | 1900 throw MakeTypeError('not_an_iterator', [iterator]); |
| 1901 } | 1901 } |
| 1902 return iterator; | 1902 return iterator; |
| 1903 } | 1903 } |
| OLD | NEW |