| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // ECMA-262 Section 11.9.3. | 96 // ECMA-262 Section 11.9.3. |
| 97 EQUALS = function EQUALS(y) { | 97 EQUALS = function EQUALS(y) { |
| 98 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); | 98 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); |
| 99 var x = this; | 99 var x = this; |
| 100 | 100 |
| 101 while (true) { | 101 while (true) { |
| 102 if (IS_NUMBER(x)) { | 102 if (IS_NUMBER(x)) { |
| 103 while (true) { | 103 while (true) { |
| 104 if (IS_NUMBER(y)) return %NumberEquals(x, y); | 104 if (IS_NUMBER(y)) return %NumberEquals(x, y); |
| 105 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 105 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 106 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal | |
| 107 if (!IS_SPEC_OBJECT(y)) { | 106 if (!IS_SPEC_OBJECT(y)) { |
| 107 if (IS_SYMBOL(y) || IS_SIMD_OBJECT(y)) return 1; // not equal |
| 108 // String or boolean. | 108 // String or boolean. |
| 109 return %NumberEquals(x, %$toNumber(y)); | 109 return %NumberEquals(x, %$toNumber(y)); |
| 110 } | 110 } |
| 111 y = %$toPrimitive(y, NO_HINT); | 111 y = %$toPrimitive(y, NO_HINT); |
| 112 } | 112 } |
| 113 } else if (IS_STRING(x)) { | 113 } else if (IS_STRING(x)) { |
| 114 while (true) { | 114 while (true) { |
| 115 if (IS_STRING(y)) return %StringEquals(x, y); | 115 if (IS_STRING(y)) return %StringEquals(x, y); |
| 116 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal | |
| 117 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); | 116 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); |
| 118 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); | 117 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); |
| 119 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 118 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 119 if (IS_SYMBOL(y) || IS_SIMD_OBJECT(y)) return 1; // not equal |
| 120 y = %$toPrimitive(y, NO_HINT); | 120 y = %$toPrimitive(y, NO_HINT); |
| 121 } | 121 } |
| 122 } else if (IS_SYMBOL(x)) { | 122 } else if (IS_SYMBOL(x)) { |
| 123 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 123 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 124 return 1; // not equal | 124 return 1; // not equal |
| 125 } else if (IS_BOOLEAN(x)) { | 125 } else if (IS_BOOLEAN(x)) { |
| 126 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 126 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 127 if (IS_NULL_OR_UNDEFINED(y)) return 1; | 127 if (IS_NULL_OR_UNDEFINED(y)) return 1; |
| 128 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); | 128 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); |
| 129 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); | 129 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); |
| 130 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal | 130 if (IS_SYMBOL(y) || IS_SIMD_OBJECT(y)) return 1; // not equal |
| 131 // y is object. | 131 // y is object. |
| 132 x = %$toNumber(x); | 132 x = %$toNumber(x); |
| 133 y = %$toPrimitive(y, NO_HINT); | 133 y = %$toPrimitive(y, NO_HINT); |
| 134 } else if (IS_NULL_OR_UNDEFINED(x)) { | 134 } else if (IS_NULL_OR_UNDEFINED(x)) { |
| 135 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; | 135 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; |
| 136 } else if (IS_FLOAT32X4(x)) { | 136 } else if (IS_SIMD_OBJECT(x)) { |
| 137 if (IS_FLOAT32X4(y)) | 137 return %SimdEquals(x, y); |
| 138 return %Float32x4Equals(x, y); | |
| 139 return 1; // not equal | |
| 140 } else { | 138 } else { |
| 141 // x is an object. | 139 // x is an object. |
| 142 if (IS_SPEC_OBJECT(y)) { | 140 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 143 return %_ObjectEquals(x, y) ? 0 : 1; | 141 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 142 if (IS_BOOLEAN(y)) { |
| 143 y = %$toNumber(y); |
| 144 } else if (IS_SYMBOL(y) || IS_SIMD_OBJECT(y)) { |
| 145 return 1; // not equal |
| 144 } | 146 } |
| 145 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | |
| 146 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal | |
| 147 if (IS_BOOLEAN(y)) y = %$toNumber(y); | |
| 148 x = %$toPrimitive(x, NO_HINT); | 147 x = %$toPrimitive(x, NO_HINT); |
| 149 } | 148 } |
| 150 } | 149 } |
| 151 } | 150 } |
| 152 | 151 |
| 153 // ECMA-262, section 11.9.4, page 56. | 152 // ECMA-262, section 11.9.4, page 56. |
| 154 STRICT_EQUALS = function STRICT_EQUALS(x) { | 153 STRICT_EQUALS = function STRICT_EQUALS(x) { |
| 155 if (IS_STRING(this)) { | 154 if (IS_STRING(this)) { |
| 156 if (!IS_STRING(x)) return 1; // not equal | 155 if (!IS_STRING(x)) return 1; // not equal |
| 157 return %StringEquals(this, x); | 156 return %StringEquals(this, x); |
| 158 } | 157 } |
| 159 | 158 |
| 160 if (IS_NUMBER(this)) { | 159 if (IS_NUMBER(this)) { |
| 161 if (!IS_NUMBER(x)) return 1; // not equal | 160 if (!IS_NUMBER(x)) return 1; // not equal |
| 162 return %NumberEquals(this, x); | 161 return %NumberEquals(this, x); |
| 163 } | 162 } |
| 164 | 163 |
| 165 if (IS_FLOAT32X4(this) && IS_FLOAT32X4(x)) | 164 if (IS_SIMD_OBJECT(this)) return %SimdEquals(this, x); |
| 166 return %Float32x4Equals(this, x); | |
| 167 | 165 |
| 168 // If anything else gets here, we just do simple identity check. | 166 // If anything else gets here, we just do simple identity check. |
| 169 // Objects (including functions), null, undefined and booleans were | 167 // Objects (including functions), null, undefined and booleans were |
| 170 // checked in the CompareStub, so there should be nothing left. | 168 // checked in the CompareStub, so there should be nothing left. |
| 171 return %_ObjectEquals(this, x) ? 0 : 1; | 169 return %_ObjectEquals(this, x) ? 0 : 1; |
| 172 } | 170 } |
| 173 | 171 |
| 174 | 172 |
| 175 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as | 173 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as |
| 176 // the result when either (or both) the operands are NaN. | 174 // the result when either (or both) the operands are NaN. |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 ------------------------------------- | 757 ------------------------------------- |
| 760 */ | 758 */ |
| 761 | 759 |
| 762 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 760 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
| 763 // (1) for number hint, and (2) for string hint. | 761 // (1) for number hint, and (2) for string hint. |
| 764 function ToPrimitive(x, hint) { | 762 function ToPrimitive(x, hint) { |
| 765 // Fast case check. | 763 // Fast case check. |
| 766 if (IS_STRING(x)) return x; | 764 if (IS_STRING(x)) return x; |
| 767 // Normal behavior. | 765 // Normal behavior. |
| 768 if (!IS_SPEC_OBJECT(x)) return x; | 766 if (!IS_SPEC_OBJECT(x)) return x; |
| 769 if (IS_FLOAT32X4(x)) return x; | 767 if (IS_SIMD_OBJECT(x)) return x; |
| 770 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 768 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
| 771 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x); | 769 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x); |
| 772 } | 770 } |
| 773 | 771 |
| 774 | 772 |
| 775 // ECMA-262, section 9.2, page 30 | 773 // ECMA-262, section 9.2, page 30 |
| 776 function ToBoolean(x) { | 774 function ToBoolean(x) { |
| 777 if (IS_BOOLEAN(x)) return x; | 775 if (IS_BOOLEAN(x)) return x; |
| 778 if (IS_STRING(x)) return x.length != 0; | 776 if (IS_STRING(x)) return x.length != 0; |
| 779 if (x == null) return false; | 777 if (x == null) return false; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 return IS_SYMBOL(x) ? x : ToString(x); | 829 return IS_SYMBOL(x) ? x : ToString(x); |
| 832 } | 830 } |
| 833 | 831 |
| 834 | 832 |
| 835 // ECMA-262, section 9.9, page 36. | 833 // ECMA-262, section 9.9, page 36. |
| 836 function ToObject(x) { | 834 function ToObject(x) { |
| 837 if (IS_STRING(x)) return new GlobalString(x); | 835 if (IS_STRING(x)) return new GlobalString(x); |
| 838 if (IS_NUMBER(x)) return new GlobalNumber(x); | 836 if (IS_NUMBER(x)) return new GlobalNumber(x); |
| 839 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); | 837 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); |
| 840 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); | 838 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); |
| 841 if (IS_FLOAT32X4(x)) return %NewFloat32x4Wrapper(x); | 839 if (IS_SIMD_OBJECT(x)) return %SimdToObject(x); |
| 842 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 840 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
| 843 throw MakeTypeError(kUndefinedOrNullToObject); | 841 throw MakeTypeError(kUndefinedOrNullToObject); |
| 844 } | 842 } |
| 845 return x; | 843 return x; |
| 846 } | 844 } |
| 847 | 845 |
| 848 | 846 |
| 849 // ECMA-262, section 9.4, page 34. | 847 // ECMA-262, section 9.4, page 34. |
| 850 function ToInteger(x) { | 848 function ToInteger(x) { |
| 851 if (%_IsSmi(x)) return x; | 849 if (%_IsSmi(x)) return x; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 879 // ES5, section 9.12 | 877 // ES5, section 9.12 |
| 880 function SameValue(x, y) { | 878 function SameValue(x, y) { |
| 881 if (typeof x != typeof y) return false; | 879 if (typeof x != typeof y) return false; |
| 882 if (IS_NUMBER(x)) { | 880 if (IS_NUMBER(x)) { |
| 883 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | 881 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; |
| 884 // x is +0 and y is -0 or vice versa. | 882 // x is +0 and y is -0 or vice versa. |
| 885 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { | 883 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { |
| 886 return false; | 884 return false; |
| 887 } | 885 } |
| 888 } | 886 } |
| 889 if (IS_FLOAT32X4(x)) { | 887 if (IS_SIMD_OBJECT(x)) return %SimdSameValue(x, y); |
| 890 return %Float32x4SameValue(x, y); | |
| 891 } | |
| 892 return x === y; | 888 return x === y; |
| 893 } | 889 } |
| 894 | 890 |
| 895 | 891 |
| 896 // ES6, section 7.2.4 | 892 // ES6, section 7.2.4 |
| 897 function SameValueZero(x, y) { | 893 function SameValueZero(x, y) { |
| 898 if (typeof x != typeof y) return false; | 894 if (typeof x != typeof y) return false; |
| 899 if (IS_NUMBER(x)) { | 895 if (IS_NUMBER(x)) { |
| 900 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | 896 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; |
| 901 } | 897 } |
| 902 if (IS_FLOAT32X4(x)) { | 898 if (IS_SIMD_OBJECT(x)) return %SimdSameValueZero(x, y); |
| 903 return %Float32x4SameValueZero(x, y); | |
| 904 } | |
| 905 return x === y; | 899 return x === y; |
| 906 } | 900 } |
| 907 | 901 |
| 908 | 902 |
| 909 function ConcatIterableToArray(target, iterable) { | 903 function ConcatIterableToArray(target, iterable) { |
| 910 var index = target.length; | 904 var index = target.length; |
| 911 for (var element of iterable) { | 905 for (var element of iterable) { |
| 912 %AddElement(target, index++, element); | 906 %AddElement(target, index++, element); |
| 913 } | 907 } |
| 914 return target; | 908 return target; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 938 return ToBoolean(spreadable); | 932 return ToBoolean(spreadable); |
| 939 } | 933 } |
| 940 | 934 |
| 941 | 935 |
| 942 // ECMA-262, section 8.6.2.6, page 28. | 936 // ECMA-262, section 8.6.2.6, page 28. |
| 943 function DefaultNumber(x) { | 937 function DefaultNumber(x) { |
| 944 var valueOf = x.valueOf; | 938 var valueOf = x.valueOf; |
| 945 if (IS_SPEC_FUNCTION(valueOf)) { | 939 if (IS_SPEC_FUNCTION(valueOf)) { |
| 946 var v = %_CallFunction(x, valueOf); | 940 var v = %_CallFunction(x, valueOf); |
| 947 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber); | 941 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber); |
| 948 if (IS_FLOAT32X4(v)) throw MakeTypeError(kSimdToNumber); | 942 if (IS_SIMD_OBJECT(x)) throw MakeTypeError(kSimdToNumber); |
| 949 if (IsPrimitive(v)) return v; | 943 if (IsPrimitive(v)) return v; |
| 950 } | 944 } |
| 951 var toString = x.toString; | 945 var toString = x.toString; |
| 952 if (IS_SPEC_FUNCTION(toString)) { | 946 if (IS_SPEC_FUNCTION(toString)) { |
| 953 var s = %_CallFunction(x, toString); | 947 var s = %_CallFunction(x, toString); |
| 954 if (IsPrimitive(s)) return s; | 948 if (IsPrimitive(s)) return s; |
| 955 } | 949 } |
| 956 throw MakeTypeError(kCannotConvertToPrimitive); | 950 throw MakeTypeError(kCannotConvertToPrimitive); |
| 957 } | 951 } |
| 958 | 952 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 $toLength = ToLength; | 1000 $toLength = ToLength; |
| 1007 $toName = ToName; | 1001 $toName = ToName; |
| 1008 $toNumber = ToNumber; | 1002 $toNumber = ToNumber; |
| 1009 $toObject = ToObject; | 1003 $toObject = ToObject; |
| 1010 $toPositiveInteger = ToPositiveInteger; | 1004 $toPositiveInteger = ToPositiveInteger; |
| 1011 $toPrimitive = ToPrimitive; | 1005 $toPrimitive = ToPrimitive; |
| 1012 $toString = ToString; | 1006 $toString = ToString; |
| 1013 $toUint32 = ToUint32; | 1007 $toUint32 = ToUint32; |
| 1014 | 1008 |
| 1015 }) | 1009 }) |
| OLD | NEW |