| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (IS_NULL_OR_UNDEFINED(y)) return 1; | 120 if (IS_NULL_OR_UNDEFINED(y)) return 1; |
| 121 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); | 121 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); |
| 122 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); | 122 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); |
| 123 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal | 123 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal |
| 124 // y is object. | 124 // y is object. |
| 125 x = %$toNumber(x); | 125 x = %$toNumber(x); |
| 126 y = %$toPrimitive(y, NO_HINT); | 126 y = %$toPrimitive(y, NO_HINT); |
| 127 } else if (IS_NULL_OR_UNDEFINED(x)) { | 127 } else if (IS_NULL_OR_UNDEFINED(x)) { |
| 128 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; | 128 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; |
| 129 } else if (IS_SIMD_VALUE(x)) { | 129 } else if (IS_SIMD_VALUE(x)) { |
| 130 if (!IS_SIMD_VALUE(y)) return 1; // not equal |
| 130 return %SimdEquals(x, y); | 131 return %SimdEquals(x, y); |
| 131 } else { | 132 } else { |
| 132 // x is an object. | 133 // x is an object. |
| 133 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 134 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 134 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 135 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 135 if (IS_BOOLEAN(y)) { | 136 if (IS_BOOLEAN(y)) { |
| 136 y = %$toNumber(y); | 137 y = %$toNumber(y); |
| 137 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) { | 138 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) { |
| 138 return 1; // not equal | 139 return 1; // not equal |
| 139 } | 140 } |
| 140 x = %$toPrimitive(x, NO_HINT); | 141 x = %$toPrimitive(x, NO_HINT); |
| 141 } | 142 } |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 145 // ECMA-262, section 11.9.4, page 56. | |
| 146 STRICT_EQUALS = function STRICT_EQUALS(x) { | |
| 147 if (IS_STRING(this)) { | |
| 148 if (!IS_STRING(x)) return 1; // not equal | |
| 149 return %StringEquals(this, x); | |
| 150 } | |
| 151 | |
| 152 if (IS_NUMBER(this)) { | |
| 153 if (!IS_NUMBER(x)) return 1; // not equal | |
| 154 return %NumberEquals(this, x); | |
| 155 } | |
| 156 | |
| 157 if (IS_SIMD_VALUE(this)) return %SimdEquals(this, x); | |
| 158 | |
| 159 // If anything else gets here, we just do simple identity check. | |
| 160 // Objects (including functions), null, undefined and booleans were | |
| 161 // checked in the CompareStub, so there should be nothing left. | |
| 162 return %_ObjectEquals(this, x) ? 0 : 1; | |
| 163 } | |
| 164 | |
| 165 | 146 |
| 166 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as | 147 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as |
| 167 // the result when either (or both) the operands are NaN. | 148 // the result when either (or both) the operands are NaN. |
| 168 COMPARE = function COMPARE(x, ncr) { | 149 COMPARE = function COMPARE(x, ncr) { |
| 169 var left; | 150 var left; |
| 170 var right; | 151 var right; |
| 171 // Fast cases for string, numbers and undefined compares. | 152 // Fast cases for string, numbers and undefined compares. |
| 172 if (IS_STRING(this)) { | 153 if (IS_STRING(this)) { |
| 173 if (IS_STRING(x)) return %_StringCompare(this, x); | 154 if (IS_STRING(x)) return %_StringCompare(this, x); |
| 174 if (IS_UNDEFINED(x)) return ncr; | 155 if (IS_UNDEFINED(x)) return ncr; |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 $toBoolean = ToBoolean; | 909 $toBoolean = ToBoolean; |
| 929 $toInteger = ToInteger; | 910 $toInteger = ToInteger; |
| 930 $toLength = ToLength; | 911 $toLength = ToLength; |
| 931 $toName = ToName; | 912 $toName = ToName; |
| 932 $toNumber = ToNumber; | 913 $toNumber = ToNumber; |
| 933 $toPositiveInteger = ToPositiveInteger; | 914 $toPositiveInteger = ToPositiveInteger; |
| 934 $toPrimitive = ToPrimitive; | 915 $toPrimitive = ToPrimitive; |
| 935 $toString = ToString; | 916 $toString = ToString; |
| 936 | 917 |
| 937 }) | 918 }) |
| OLD | NEW |