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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return; | 684 return; |
685 } | 685 } |
686 } | 686 } |
687 | 687 |
688 | 688 |
689 // ES6, draft 12-24-14, section 7.3.8 | 689 // ES6, draft 12-24-14, section 7.3.8 |
690 function GetMethod(obj, p) { | 690 function GetMethod(obj, p) { |
691 var func = obj[p]; | 691 var func = obj[p]; |
692 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; | 692 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; |
693 if (IS_SPEC_FUNCTION(func)) return func; | 693 if (IS_SPEC_FUNCTION(func)) return func; |
694 throw MakeTypeError(kCalledNonCallable, typeof func); | 694 throw MakeTypeError('called_non_callable', [typeof func]); |
695 } | 695 } |
696 | 696 |
697 | 697 |
698 // Harmony proxies. | 698 // Harmony proxies. |
699 function DefineProxyProperty(obj, p, attributes, should_throw) { | 699 function DefineProxyProperty(obj, p, attributes, should_throw) { |
700 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 700 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
701 if (IS_SYMBOL(p)) return false; | 701 if (IS_SYMBOL(p)) return false; |
702 | 702 |
703 var handler = %GetHandler(obj); | 703 var handler = %GetHandler(obj); |
704 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); | 704 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 } | 1580 } |
1581 return %_ValueOf(this); | 1581 return %_ValueOf(this); |
1582 } | 1582 } |
1583 | 1583 |
1584 | 1584 |
1585 // ECMA-262 section 15.7.4.5 | 1585 // ECMA-262 section 15.7.4.5 |
1586 function NumberToFixedJS(fractionDigits) { | 1586 function NumberToFixedJS(fractionDigits) { |
1587 var x = this; | 1587 var x = this; |
1588 if (!IS_NUMBER(this)) { | 1588 if (!IS_NUMBER(this)) { |
1589 if (!IS_NUMBER_WRAPPER(this)) { | 1589 if (!IS_NUMBER_WRAPPER(this)) { |
1590 throw MakeTypeError(kIncompatibleMethodReceiver, | 1590 throw MakeTypeError("incompatible_method_receiver", |
1591 "Number.prototype.toFixed", this); | 1591 ["Number.prototype.toFixed", this]); |
1592 } | 1592 } |
1593 // Get the value of this number in case it's an object. | 1593 // Get the value of this number in case it's an object. |
1594 x = %_ValueOf(this); | 1594 x = %_ValueOf(this); |
1595 } | 1595 } |
1596 var f = TO_INTEGER(fractionDigits); | 1596 var f = TO_INTEGER(fractionDigits); |
1597 | 1597 |
1598 if (f < 0 || f > 20) { | 1598 if (f < 0 || f > 20) { |
1599 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); | 1599 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); |
1600 } | 1600 } |
1601 | 1601 |
1602 if (NUMBER_IS_NAN(x)) return "NaN"; | 1602 if (NUMBER_IS_NAN(x)) return "NaN"; |
1603 if (x == INFINITY) return "Infinity"; | 1603 if (x == INFINITY) return "Infinity"; |
1604 if (x == -INFINITY) return "-Infinity"; | 1604 if (x == -INFINITY) return "-Infinity"; |
1605 | 1605 |
1606 return %NumberToFixed(x, f); | 1606 return %NumberToFixed(x, f); |
1607 } | 1607 } |
1608 | 1608 |
1609 | 1609 |
1610 // ECMA-262 section 15.7.4.6 | 1610 // ECMA-262 section 15.7.4.6 |
1611 function NumberToExponentialJS(fractionDigits) { | 1611 function NumberToExponentialJS(fractionDigits) { |
1612 var x = this; | 1612 var x = this; |
1613 if (!IS_NUMBER(this)) { | 1613 if (!IS_NUMBER(this)) { |
1614 if (!IS_NUMBER_WRAPPER(this)) { | 1614 if (!IS_NUMBER_WRAPPER(this)) { |
1615 throw MakeTypeError(kIncompatibleMethodReceiver, | 1615 throw MakeTypeError("incompatible_method_receiver", |
1616 "Number.prototype.toExponential", this); | 1616 ["Number.prototype.toExponential", this]); |
1617 } | 1617 } |
1618 // Get the value of this number in case it's an object. | 1618 // Get the value of this number in case it's an object. |
1619 x = %_ValueOf(this); | 1619 x = %_ValueOf(this); |
1620 } | 1620 } |
1621 var f = IS_UNDEFINED(fractionDigits) ? UNDEFINED : TO_INTEGER(fractionDigits); | 1621 var f = IS_UNDEFINED(fractionDigits) ? UNDEFINED : TO_INTEGER(fractionDigits); |
1622 | 1622 |
1623 if (NUMBER_IS_NAN(x)) return "NaN"; | 1623 if (NUMBER_IS_NAN(x)) return "NaN"; |
1624 if (x == INFINITY) return "Infinity"; | 1624 if (x == INFINITY) return "Infinity"; |
1625 if (x == -INFINITY) return "-Infinity"; | 1625 if (x == -INFINITY) return "-Infinity"; |
1626 | 1626 |
1627 if (IS_UNDEFINED(f)) { | 1627 if (IS_UNDEFINED(f)) { |
1628 f = -1; // Signal for runtime function that f is not defined. | 1628 f = -1; // Signal for runtime function that f is not defined. |
1629 } else if (f < 0 || f > 20) { | 1629 } else if (f < 0 || f > 20) { |
1630 throw new $RangeError("toExponential() argument must be between 0 and 20"); | 1630 throw new $RangeError("toExponential() argument must be between 0 and 20"); |
1631 } | 1631 } |
1632 return %NumberToExponential(x, f); | 1632 return %NumberToExponential(x, f); |
1633 } | 1633 } |
1634 | 1634 |
1635 | 1635 |
1636 // ECMA-262 section 15.7.4.7 | 1636 // ECMA-262 section 15.7.4.7 |
1637 function NumberToPrecisionJS(precision) { | 1637 function NumberToPrecisionJS(precision) { |
1638 var x = this; | 1638 var x = this; |
1639 if (!IS_NUMBER(this)) { | 1639 if (!IS_NUMBER(this)) { |
1640 if (!IS_NUMBER_WRAPPER(this)) { | 1640 if (!IS_NUMBER_WRAPPER(this)) { |
1641 throw MakeTypeError(kIncompatibleMethodReceiver, | 1641 throw MakeTypeError("incompatible_method_receiver", |
1642 "Number.prototype.toPrecision", this); | 1642 ["Number.prototype.toPrecision", this]); |
1643 } | 1643 } |
1644 // Get the value of this number in case it's an object. | 1644 // Get the value of this number in case it's an object. |
1645 x = %_ValueOf(this); | 1645 x = %_ValueOf(this); |
1646 } | 1646 } |
1647 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 1647 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
1648 var p = TO_INTEGER(precision); | 1648 var p = TO_INTEGER(precision); |
1649 | 1649 |
1650 if (NUMBER_IS_NAN(x)) return "NaN"; | 1650 if (NUMBER_IS_NAN(x)) return "NaN"; |
1651 if (x == INFINITY) return "Infinity"; | 1651 if (x == INFINITY) return "Infinity"; |
1652 if (x == -INFINITY) return "-Infinity"; | 1652 if (x == -INFINITY) return "-Infinity"; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 } | 1914 } |
1915 if (!IS_SPEC_FUNCTION(method)) { | 1915 if (!IS_SPEC_FUNCTION(method)) { |
1916 throw MakeTypeError('not_iterable', [obj]); | 1916 throw MakeTypeError('not_iterable', [obj]); |
1917 } | 1917 } |
1918 var iterator = %_CallFunction(obj, method); | 1918 var iterator = %_CallFunction(obj, method); |
1919 if (!IS_SPEC_OBJECT(iterator)) { | 1919 if (!IS_SPEC_OBJECT(iterator)) { |
1920 throw MakeTypeError('not_an_iterator', [iterator]); | 1920 throw MakeTypeError('not_an_iterator', [iterator]); |
1921 } | 1921 } |
1922 return iterator; | 1922 return iterator; |
1923 } | 1923 } |
OLD | NEW |