OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 files contains runtime support implemented in JavaScript. | 5 // This files contains runtime support implemented in JavaScript. |
6 | 6 |
7 // CAUTION: Some of the functions specified in this file are called | 7 // CAUTION: Some of the functions specified in this file are called |
8 // directly from compiled code. These are the functions with names in | 8 // directly from compiled code. These are the functions with names in |
9 // ALL CAPS. The compiled code passes the first argument in 'this'. | 9 // ALL CAPS. The compiled code passes the first argument in 'this'. |
10 | 10 |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 | 785 |
786 // ECMA-262, section 9.3, page 31. | 786 // ECMA-262, section 9.3, page 31. |
787 function ToNumber(x) { | 787 function ToNumber(x) { |
788 if (IS_NUMBER(x)) return x; | 788 if (IS_NUMBER(x)) return x; |
789 if (IS_STRING(x)) { | 789 if (IS_STRING(x)) { |
790 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 790 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
791 : %StringToNumber(x); | 791 : %StringToNumber(x); |
792 } | 792 } |
793 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 793 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
794 if (IS_UNDEFINED(x)) return NAN; | 794 if (IS_UNDEFINED(x)) return NAN; |
795 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); | |
796 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber); | |
rossberg
2015/07/28 15:03:19
Perhaps add a comment explaining the absence of th
bbudge
2015/07/28 15:09:51
Done.
| |
797 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); | 795 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); |
798 } | 796 } |
799 | 797 |
800 function NonNumberToNumber(x) { | 798 function NonNumberToNumber(x) { |
801 if (IS_STRING(x)) { | 799 if (IS_STRING(x)) { |
802 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 800 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
803 : %StringToNumber(x); | 801 : %StringToNumber(x); |
804 } | 802 } |
805 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 803 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
806 if (IS_UNDEFINED(x)) return NAN; | 804 if (IS_UNDEFINED(x)) return NAN; |
807 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); | |
808 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber); | |
809 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); | 805 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); |
810 } | 806 } |
811 | 807 |
812 | 808 |
813 // ECMA-262, section 9.8, page 35. | 809 // ECMA-262, section 9.8, page 35. |
814 function ToString(x) { | 810 function ToString(x) { |
815 if (IS_STRING(x)) return x; | 811 if (IS_STRING(x)) return x; |
816 if (IS_NUMBER(x)) return %_NumberToString(x); | 812 if (IS_NUMBER(x)) return %_NumberToString(x); |
817 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 813 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
818 if (IS_UNDEFINED(x)) return 'undefined'; | 814 if (IS_UNDEFINED(x)) return 'undefined'; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 function IsConcatSpreadable(O) { | 933 function IsConcatSpreadable(O) { |
938 if (!IS_SPEC_OBJECT(O)) return false; | 934 if (!IS_SPEC_OBJECT(O)) return false; |
939 var spreadable = O[symbolIsConcatSpreadable]; | 935 var spreadable = O[symbolIsConcatSpreadable]; |
940 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); | 936 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); |
941 return ToBoolean(spreadable); | 937 return ToBoolean(spreadable); |
942 } | 938 } |
943 | 939 |
944 | 940 |
945 // ECMA-262, section 8.6.2.6, page 28. | 941 // ECMA-262, section 8.6.2.6, page 28. |
946 function DefaultNumber(x) { | 942 function DefaultNumber(x) { |
947 if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) { | 943 var valueOf = x.valueOf; |
948 var valueOf = x.valueOf; | 944 if (IS_SPEC_FUNCTION(valueOf)) { |
949 if (IS_SPEC_FUNCTION(valueOf)) { | 945 var v = %_CallFunction(x, valueOf); |
950 var v = %_CallFunction(x, valueOf); | 946 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber); |
951 if (IsPrimitive(v)) return v; | 947 if (IS_FLOAT32X4(v)) throw MakeTypeError(kSimdToNumber); |
952 } | 948 if (IsPrimitive(v)) return v; |
953 | 949 } |
954 var toString = x.toString; | 950 var toString = x.toString; |
955 if (IS_SPEC_FUNCTION(toString)) { | 951 if (IS_SPEC_FUNCTION(toString)) { |
956 var s = %_CallFunction(x, toString); | 952 var s = %_CallFunction(x, toString); |
957 if (IsPrimitive(s)) return s; | 953 if (IsPrimitive(s)) return s; |
958 } | |
959 } | 954 } |
960 throw MakeTypeError(kCannotConvertToPrimitive); | 955 throw MakeTypeError(kCannotConvertToPrimitive); |
961 } | 956 } |
962 | 957 |
963 // ECMA-262, section 8.6.2.6, page 28. | 958 // ECMA-262, section 8.6.2.6, page 28. |
964 function DefaultString(x) { | 959 function DefaultString(x) { |
965 if (!IS_SYMBOL_WRAPPER(x)) { | 960 if (!IS_SYMBOL_WRAPPER(x)) { |
966 var toString = x.toString; | 961 var toString = x.toString; |
967 if (IS_SPEC_FUNCTION(toString)) { | 962 if (IS_SPEC_FUNCTION(toString)) { |
968 var s = %_CallFunction(x, toString); | 963 var s = %_CallFunction(x, toString); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 $toLength = ToLength; | 1004 $toLength = ToLength; |
1010 $toName = ToName; | 1005 $toName = ToName; |
1011 $toNumber = ToNumber; | 1006 $toNumber = ToNumber; |
1012 $toObject = ToObject; | 1007 $toObject = ToObject; |
1013 $toPositiveInteger = ToPositiveInteger; | 1008 $toPositiveInteger = ToPositiveInteger; |
1014 $toPrimitive = ToPrimitive; | 1009 $toPrimitive = ToPrimitive; |
1015 $toString = ToString; | 1010 $toString = ToString; |
1016 $toUint32 = ToUint32; | 1011 $toUint32 = ToUint32; |
1017 | 1012 |
1018 }) | 1013 }) |
OLD | NEW |