| 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 |
| 11 | 11 |
| 12 /* ----------------------------------- | 12 /* ----------------------------------- |
| 13 - - - C o m p a r i s o n - - - | 13 - - - C o m p a r i s o n - - - |
| 14 ----------------------------------- | 14 ----------------------------------- |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 // The following declarations are shared with other native JS files. | 17 // The following declarations are shared with other native JS files. |
| 18 // They are all declared at this one spot to avoid redeclaration errors. | 18 // They are all declared at this one spot to avoid redeclaration errors. |
| 19 var EQUALS; | 19 var $Object = global.Object; |
| 20 var STRICT_EQUALS; | 20 var $Array = global.Array; |
| 21 var COMPARE; | 21 var $String = global.String; |
| 22 var ADD; | 22 var $Number = global.Number; |
| 23 var ADD_STRONG; | 23 var $Function = global.Function; |
| 24 var STRING_ADD_LEFT; | 24 var $Boolean = global.Boolean; |
| 25 var STRING_ADD_LEFT_STRONG; | 25 var $NaN = %GetRootNaN(); |
| 26 var STRING_ADD_RIGHT; | |
| 27 var STRING_ADD_RIGHT_STRONG; | |
| 28 var SUB; | |
| 29 var SUB_STRONG; | |
| 30 var MUL; | |
| 31 var MUL_STRONG; | |
| 32 var DIV; | |
| 33 var DIV_STRONG; | |
| 34 var MOD; | |
| 35 var MOD_STRONG; | |
| 36 var BIT_OR; | |
| 37 var BIT_OR_STRONG; | |
| 38 var BIT_AND; | |
| 39 var BIT_AND_STRONG; | |
| 40 var BIT_XOR; | |
| 41 var BIT_XOR_STRONG; | |
| 42 var SHL; | |
| 43 var SHL_STRONG; | |
| 44 var SAR; | |
| 45 var SAR_STRONG; | |
| 46 var SHR; | |
| 47 var SHR_STRONG; | |
| 48 var DELETE; | |
| 49 var IN; | |
| 50 var INSTANCE_OF; | |
| 51 var FILTER_KEY; | |
| 52 var CALL_NON_FUNCTION; | |
| 53 var CALL_NON_FUNCTION_AS_CONSTRUCTOR; | |
| 54 var CALL_FUNCTION_PROXY; | |
| 55 var CALL_FUNCTION_PROXY_AS_CONSTRUCTOR; | |
| 56 var APPLY_PREPARE; | |
| 57 var REFLECT_APPLY_PREPARE; | |
| 58 var REFLECT_CONSTRUCT_PREPARE; | |
| 59 var STACK_OVERFLOW; | |
| 60 var TO_OBJECT; | |
| 61 var TO_NUMBER; | |
| 62 var TO_STRING; | |
| 63 var TO_NAME; | |
| 64 | |
| 65 var STRING_LENGTH_STUB; | |
| 66 | |
| 67 var $defaultNumber; | |
| 68 var $defaultString; | |
| 69 var $NaN; | |
| 70 var $nonNumberToNumber; | |
| 71 var $nonStringToString; | |
| 72 var $sameValue; | |
| 73 var $sameValueZero; | |
| 74 var $toBoolean; | |
| 75 var $toInt32; | |
| 76 var $toInteger; | |
| 77 var $toLength; | |
| 78 var $toName; | |
| 79 var $toNumber; | |
| 80 var $toObject; | |
| 81 var $toPositiveInteger; | |
| 82 var $toPrimitive; | |
| 83 var $toString; | |
| 84 var $toUint32; | |
| 85 | |
| 86 (function() { | |
| 87 | |
| 88 %CheckIsBootstrapping(); | |
| 89 | |
| 90 var GlobalArray = global.Array; | |
| 91 var GlobalBoolean = global.Boolean; | |
| 92 var GlobalString = global.String; | |
| 93 var GlobalNumber = global.Number; | |
| 94 | |
| 95 // ---------------------------------------------------------------------------- | |
| 96 | 26 |
| 97 // ECMA-262 Section 11.9.3. | 27 // ECMA-262 Section 11.9.3. |
| 98 EQUALS = function EQUALS(y) { | 28 function EQUALS(y) { |
| 99 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); | 29 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); |
| 100 var x = this; | 30 var x = this; |
| 101 | 31 |
| 102 while (true) { | 32 while (true) { |
| 103 if (IS_NUMBER(x)) { | 33 if (IS_NUMBER(x)) { |
| 104 while (true) { | 34 while (true) { |
| 105 if (IS_NUMBER(y)) return %NumberEquals(x, y); | 35 if (IS_NUMBER(y)) return %NumberEquals(x, y); |
| 106 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 36 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 107 if (IS_SYMBOL(y)) return 1; // not equal | 37 if (IS_SYMBOL(y)) return 1; // not equal |
| 108 if (!IS_SPEC_OBJECT(y)) { | 38 if (!IS_SPEC_OBJECT(y)) { |
| 109 // String or boolean. | 39 // String or boolean. |
| 110 return %NumberEquals(x, %$toNumber(y)); | 40 return %NumberEquals(x, %ToNumber(y)); |
| 111 } | 41 } |
| 112 y = %$toPrimitive(y, NO_HINT); | 42 y = %ToPrimitive(y, NO_HINT); |
| 113 } | 43 } |
| 114 } else if (IS_STRING(x)) { | 44 } else if (IS_STRING(x)) { |
| 115 while (true) { | 45 while (true) { |
| 116 if (IS_STRING(y)) return %StringEquals(x, y); | 46 if (IS_STRING(y)) return %StringEquals(x, y); |
| 117 if (IS_SYMBOL(y)) return 1; // not equal | 47 if (IS_SYMBOL(y)) return 1; // not equal |
| 118 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); | 48 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); |
| 119 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); | 49 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
| 120 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 50 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 121 y = %$toPrimitive(y, NO_HINT); | 51 y = %ToPrimitive(y, NO_HINT); |
| 122 } | 52 } |
| 123 } else if (IS_SYMBOL(x)) { | 53 } else if (IS_SYMBOL(x)) { |
| 124 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 54 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 125 return 1; // not equal | 55 return 1; // not equal |
| 126 } else if (IS_BOOLEAN(x)) { | 56 } else if (IS_BOOLEAN(x)) { |
| 127 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 57 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 128 if (IS_NULL_OR_UNDEFINED(y)) return 1; | 58 if (IS_NULL_OR_UNDEFINED(y)) return 1; |
| 129 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); | 59 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); |
| 130 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); | 60 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
| 131 if (IS_SYMBOL(y)) return 1; // not equal | 61 if (IS_SYMBOL(y)) return 1; // not equal |
| 132 // y is object. | 62 // y is object. |
| 133 x = %$toNumber(x); | 63 x = %ToNumber(x); |
| 134 y = %$toPrimitive(y, NO_HINT); | 64 y = %ToPrimitive(y, NO_HINT); |
| 135 } else if (IS_NULL_OR_UNDEFINED(x)) { | 65 } else if (IS_NULL_OR_UNDEFINED(x)) { |
| 136 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; | 66 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; |
| 137 } else { | 67 } else { |
| 138 // x is an object. | 68 // x is an object. |
| 139 if (IS_SPEC_OBJECT(y)) { | 69 if (IS_SPEC_OBJECT(y)) { |
| 140 return %_ObjectEquals(x, y) ? 0 : 1; | 70 return %_ObjectEquals(x, y) ? 0 : 1; |
| 141 } | 71 } |
| 142 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 72 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
| 143 if (IS_SYMBOL(y)) return 1; // not equal | 73 if (IS_SYMBOL(y)) return 1; // not equal |
| 144 if (IS_BOOLEAN(y)) y = %$toNumber(y); | 74 if (IS_BOOLEAN(y)) y = %ToNumber(y); |
| 145 x = %$toPrimitive(x, NO_HINT); | 75 x = %ToPrimitive(x, NO_HINT); |
| 146 } | 76 } |
| 147 } | 77 } |
| 148 } | 78 } |
| 149 | 79 |
| 150 // ECMA-262, section 11.9.4, page 56. | 80 // ECMA-262, section 11.9.4, page 56. |
| 151 STRICT_EQUALS = function STRICT_EQUALS(x) { | 81 function STRICT_EQUALS(x) { |
| 152 if (IS_STRING(this)) { | 82 if (IS_STRING(this)) { |
| 153 if (!IS_STRING(x)) return 1; // not equal | 83 if (!IS_STRING(x)) return 1; // not equal |
| 154 return %StringEquals(this, x); | 84 return %StringEquals(this, x); |
| 155 } | 85 } |
| 156 | 86 |
| 157 if (IS_NUMBER(this)) { | 87 if (IS_NUMBER(this)) { |
| 158 if (!IS_NUMBER(x)) return 1; // not equal | 88 if (!IS_NUMBER(x)) return 1; // not equal |
| 159 return %NumberEquals(this, x); | 89 return %NumberEquals(this, x); |
| 160 } | 90 } |
| 161 | 91 |
| 162 // If anything else gets here, we just do simple identity check. | 92 // If anything else gets here, we just do simple identity check. |
| 163 // Objects (including functions), null, undefined and booleans were | 93 // Objects (including functions), null, undefined and booleans were |
| 164 // checked in the CompareStub, so there should be nothing left. | 94 // checked in the CompareStub, so there should be nothing left. |
| 165 return %_ObjectEquals(this, x) ? 0 : 1; | 95 return %_ObjectEquals(this, x) ? 0 : 1; |
| 166 } | 96 } |
| 167 | 97 |
| 168 | 98 |
| 169 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as | 99 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as |
| 170 // the result when either (or both) the operands are NaN. | 100 // the result when either (or both) the operands are NaN. |
| 171 COMPARE = function COMPARE(x, ncr) { | 101 function COMPARE(x, ncr) { |
| 172 var left; | 102 var left; |
| 173 var right; | 103 var right; |
| 174 // Fast cases for string, numbers and undefined compares. | 104 // Fast cases for string, numbers and undefined compares. |
| 175 if (IS_STRING(this)) { | 105 if (IS_STRING(this)) { |
| 176 if (IS_STRING(x)) return %_StringCompare(this, x); | 106 if (IS_STRING(x)) return %_StringCompare(this, x); |
| 177 if (IS_UNDEFINED(x)) return ncr; | 107 if (IS_UNDEFINED(x)) return ncr; |
| 178 left = this; | 108 left = this; |
| 179 } else if (IS_NUMBER(this)) { | 109 } else if (IS_NUMBER(this)) { |
| 180 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr); | 110 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr); |
| 181 if (IS_UNDEFINED(x)) return ncr; | 111 if (IS_UNDEFINED(x)) return ncr; |
| 182 left = this; | 112 left = this; |
| 183 } else if (IS_UNDEFINED(this)) { | 113 } else if (IS_UNDEFINED(this)) { |
| 184 if (!IS_UNDEFINED(x)) { | 114 if (!IS_UNDEFINED(x)) { |
| 185 %$toPrimitive(x, NUMBER_HINT); | 115 %ToPrimitive(x, NUMBER_HINT); |
| 186 } | 116 } |
| 187 return ncr; | 117 return ncr; |
| 188 } else if (IS_UNDEFINED(x)) { | 118 } else if (IS_UNDEFINED(x)) { |
| 189 %$toPrimitive(this, NUMBER_HINT); | 119 %ToPrimitive(this, NUMBER_HINT); |
| 190 return ncr; | 120 return ncr; |
| 191 } else { | 121 } else { |
| 192 left = %$toPrimitive(this, NUMBER_HINT); | 122 left = %ToPrimitive(this, NUMBER_HINT); |
| 193 } | 123 } |
| 194 | 124 |
| 195 right = %$toPrimitive(x, NUMBER_HINT); | 125 right = %ToPrimitive(x, NUMBER_HINT); |
| 196 if (IS_STRING(left) && IS_STRING(right)) { | 126 if (IS_STRING(left) && IS_STRING(right)) { |
| 197 return %_StringCompare(left, right); | 127 return %_StringCompare(left, right); |
| 198 } else { | 128 } else { |
| 199 var left_number = %$toNumber(left); | 129 var left_number = %ToNumber(left); |
| 200 var right_number = %$toNumber(right); | 130 var right_number = %ToNumber(right); |
| 201 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; | 131 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; |
| 202 return %NumberCompare(left_number, right_number, ncr); | 132 return %NumberCompare(left_number, right_number, ncr); |
| 203 } | 133 } |
| 204 } | 134 } |
| 205 | 135 |
| 206 | 136 |
| 207 | 137 |
| 208 /* ----------------------------------- | 138 /* ----------------------------------- |
| 209 - - - A r i t h m e t i c - - - | 139 - - - A r i t h m e t i c - - - |
| 210 ----------------------------------- | 140 ----------------------------------- |
| 211 */ | 141 */ |
| 212 | 142 |
| 213 // ECMA-262, section 11.6.1, page 50. | 143 // ECMA-262, section 11.6.1, page 50. |
| 214 ADD = function ADD(x) { | 144 function ADD(x) { |
| 215 // Fast case: Check for number operands and do the addition. | 145 // Fast case: Check for number operands and do the addition. |
| 216 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); | 146 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); |
| 217 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); | 147 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); |
| 218 | 148 |
| 219 // Default implementation. | 149 // Default implementation. |
| 220 var a = %$toPrimitive(this, NO_HINT); | 150 var a = %ToPrimitive(this, NO_HINT); |
| 221 var b = %$toPrimitive(x, NO_HINT); | 151 var b = %ToPrimitive(x, NO_HINT); |
| 222 | 152 |
| 223 if (IS_STRING(a)) { | 153 if (IS_STRING(a)) { |
| 224 return %_StringAdd(a, %$toString(b)); | 154 return %_StringAdd(a, %ToString(b)); |
| 225 } else if (IS_STRING(b)) { | 155 } else if (IS_STRING(b)) { |
| 226 return %_StringAdd(%$nonStringToString(a), b); | 156 return %_StringAdd(%NonStringToString(a), b); |
| 227 } else { | 157 } else { |
| 228 return %NumberAdd(%$toNumber(a), %$toNumber(b)); | 158 return %NumberAdd(%ToNumber(a), %ToNumber(b)); |
| 229 } | 159 } |
| 230 } | 160 } |
| 231 | 161 |
| 232 | 162 |
| 233 // Strong mode ADD throws if an implicit conversion would be performed | 163 // Strong mode ADD throws if an implicit conversion would be performed |
| 234 ADD_STRONG = function ADD_STRONG(x) { | 164 function ADD_STRONG(x) { |
| 235 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); | 165 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); |
| 236 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); | 166 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); |
| 237 | 167 |
| 238 throw %MakeTypeError('strong_implicit_cast'); | 168 throw %MakeTypeError('strong_implicit_cast'); |
| 239 } | 169 } |
| 240 | 170 |
| 241 | 171 |
| 242 // Left operand (this) is already a string. | 172 // Left operand (this) is already a string. |
| 243 STRING_ADD_LEFT = function STRING_ADD_LEFT(y) { | 173 function STRING_ADD_LEFT(y) { |
| 244 if (!IS_STRING(y)) { | 174 if (!IS_STRING(y)) { |
| 245 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { | 175 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { |
| 246 y = %_ValueOf(y); | 176 y = %_ValueOf(y); |
| 247 } else { | 177 } else { |
| 248 y = IS_NUMBER(y) | 178 y = IS_NUMBER(y) |
| 249 ? %_NumberToString(y) | 179 ? %_NumberToString(y) |
| 250 : %$toString(%$toPrimitive(y, NO_HINT)); | 180 : %ToString(%ToPrimitive(y, NO_HINT)); |
| 251 } | 181 } |
| 252 } | 182 } |
| 253 return %_StringAdd(this, y); | 183 return %_StringAdd(this, y); |
| 254 } | 184 } |
| 255 | 185 |
| 256 | 186 |
| 257 // Left operand (this) is already a string. | 187 // Left operand (this) is already a string. |
| 258 STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) { | 188 function STRING_ADD_LEFT_STRONG(y) { |
| 259 if (IS_STRING(y)) { | 189 if (IS_STRING(y)) { |
| 260 return %_StringAdd(this, y); | 190 return %_StringAdd(this, y); |
| 261 } | 191 } |
| 262 throw %MakeTypeError('strong_implicit_cast'); | 192 throw %MakeTypeError('strong_implicit_cast'); |
| 263 } | 193 } |
| 264 | 194 |
| 265 | 195 |
| 266 // Right operand (y) is already a string. | 196 // Right operand (y) is already a string. |
| 267 STRING_ADD_RIGHT = function STRING_ADD_RIGHT(y) { | 197 function STRING_ADD_RIGHT(y) { |
| 268 var x = this; | 198 var x = this; |
| 269 if (!IS_STRING(x)) { | 199 if (!IS_STRING(x)) { |
| 270 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { | 200 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { |
| 271 x = %_ValueOf(x); | 201 x = %_ValueOf(x); |
| 272 } else { | 202 } else { |
| 273 x = IS_NUMBER(x) | 203 x = IS_NUMBER(x) |
| 274 ? %_NumberToString(x) | 204 ? %_NumberToString(x) |
| 275 : %$toString(%$toPrimitive(x, NO_HINT)); | 205 : %ToString(%ToPrimitive(x, NO_HINT)); |
| 276 } | 206 } |
| 277 } | 207 } |
| 278 return %_StringAdd(x, y); | 208 return %_StringAdd(x, y); |
| 279 } | 209 } |
| 280 | 210 |
| 281 | 211 |
| 282 // Right operand (y) is already a string. | 212 // Right operand (y) is already a string. |
| 283 STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) { | 213 function STRING_ADD_RIGHT_STRONG(y) { |
| 284 if (IS_STRING(this)) { | 214 if (IS_STRING(this)) { |
| 285 return %_StringAdd(this, y); | 215 return %_StringAdd(this, y); |
| 286 } | 216 } |
| 287 throw %MakeTypeError('strong_implicit_cast'); | 217 throw %MakeTypeError('strong_implicit_cast'); |
| 288 } | 218 } |
| 289 | 219 |
| 290 | 220 |
| 291 // ECMA-262, section 11.6.2, page 50. | 221 // ECMA-262, section 11.6.2, page 50. |
| 292 SUB = function SUB(y) { | 222 function SUB(y) { |
| 293 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 223 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 294 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 224 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 295 return %NumberSub(x, y); | 225 return %NumberSub(x, y); |
| 296 } | 226 } |
| 297 | 227 |
| 298 | 228 |
| 299 // Strong mode SUB throws if an implicit conversion would be performed | 229 // Strong mode SUB throws if an implicit conversion would be performed |
| 300 SUB_STRONG = function SUB_STRONG(y) { | 230 function SUB_STRONG(y) { |
| 301 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 231 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 302 return %NumberSub(this, y); | 232 return %NumberSub(this, y); |
| 303 } | 233 } |
| 304 throw %MakeTypeError('strong_implicit_cast'); | 234 throw %MakeTypeError('strong_implicit_cast'); |
| 305 } | 235 } |
| 306 | 236 |
| 307 | 237 |
| 308 // ECMA-262, section 11.5.1, page 48. | 238 // ECMA-262, section 11.5.1, page 48. |
| 309 MUL = function MUL(y) { | 239 function MUL(y) { |
| 310 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 240 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 311 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 241 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 312 return %NumberMul(x, y); | 242 return %NumberMul(x, y); |
| 313 } | 243 } |
| 314 | 244 |
| 315 | 245 |
| 316 // Strong mode MUL throws if an implicit conversion would be performed | 246 // Strong mode MUL throws if an implicit conversion would be performed |
| 317 MUL_STRONG = function MUL_STRONG(y) { | 247 function MUL_STRONG(y) { |
| 318 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 248 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 319 return %NumberMul(this, y); | 249 return %NumberMul(this, y); |
| 320 } | 250 } |
| 321 throw %MakeTypeError('strong_implicit_cast'); | 251 throw %MakeTypeError('strong_implicit_cast'); |
| 322 } | 252 } |
| 323 | 253 |
| 324 | 254 |
| 325 // ECMA-262, section 11.5.2, page 49. | 255 // ECMA-262, section 11.5.2, page 49. |
| 326 DIV = function DIV(y) { | 256 function DIV(y) { |
| 327 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 257 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 328 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 258 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 329 return %NumberDiv(x, y); | 259 return %NumberDiv(x, y); |
| 330 } | 260 } |
| 331 | 261 |
| 332 | 262 |
| 333 // Strong mode DIV throws if an implicit conversion would be performed | 263 // Strong mode DIV throws if an implicit conversion would be performed |
| 334 DIV_STRONG = function DIV_STRONG(y) { | 264 function DIV_STRONG(y) { |
| 335 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 265 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 336 return %NumberDiv(this, y); | 266 return %NumberDiv(this, y); |
| 337 } | 267 } |
| 338 throw %MakeTypeError('strong_implicit_cast'); | 268 throw %MakeTypeError('strong_implicit_cast'); |
| 339 } | 269 } |
| 340 | 270 |
| 341 | 271 |
| 342 // ECMA-262, section 11.5.3, page 49. | 272 // ECMA-262, section 11.5.3, page 49. |
| 343 MOD = function MOD(y) { | 273 function MOD(y) { |
| 344 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 274 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 345 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 275 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 346 return %NumberMod(x, y); | 276 return %NumberMod(x, y); |
| 347 } | 277 } |
| 348 | 278 |
| 349 | 279 |
| 350 // Strong mode MOD throws if an implicit conversion would be performed | 280 // Strong mode MOD throws if an implicit conversion would be performed |
| 351 MOD_STRONG = function MOD_STRONG(y) { | 281 function MOD_STRONG(y) { |
| 352 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 282 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 353 return %NumberMod(this, y); | 283 return %NumberMod(this, y); |
| 354 } | 284 } |
| 355 throw %MakeTypeError('strong_implicit_cast'); | 285 throw %MakeTypeError('strong_implicit_cast'); |
| 356 } | 286 } |
| 357 | 287 |
| 358 | 288 |
| 359 /* ------------------------------------------- | 289 /* ------------------------------------------- |
| 360 - - - B i t o p e r a t i o n s - - - | 290 - - - B i t o p e r a t i o n s - - - |
| 361 ------------------------------------------- | 291 ------------------------------------------- |
| 362 */ | 292 */ |
| 363 | 293 |
| 364 // ECMA-262, section 11.10, page 57. | 294 // ECMA-262, section 11.10, page 57. |
| 365 BIT_OR = function BIT_OR(y) { | 295 function BIT_OR(y) { |
| 366 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 296 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 367 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 297 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 368 return %NumberOr(x, y); | 298 return %NumberOr(x, y); |
| 369 } | 299 } |
| 370 | 300 |
| 371 | 301 |
| 372 // Strong mode BIT_OR throws if an implicit conversion would be performed | 302 // Strong mode BIT_OR throws if an implicit conversion would be performed |
| 373 BIT_OR_STRONG = function BIT_OR_STRONG(y) { | 303 function BIT_OR_STRONG(y) { |
| 374 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 304 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 375 return %NumberOr(this, y); | 305 return %NumberOr(this, y); |
| 376 } | 306 } |
| 377 throw %MakeTypeError('strong_implicit_cast'); | 307 throw %MakeTypeError('strong_implicit_cast'); |
| 378 } | 308 } |
| 379 | 309 |
| 380 | 310 |
| 381 // ECMA-262, section 11.10, page 57. | 311 // ECMA-262, section 11.10, page 57. |
| 382 BIT_AND = function BIT_AND(y) { | 312 function BIT_AND(y) { |
| 383 var x; | 313 var x; |
| 384 if (IS_NUMBER(this)) { | 314 if (IS_NUMBER(this)) { |
| 385 x = this; | 315 x = this; |
| 386 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 316 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 387 } else { | 317 } else { |
| 388 x = %$nonNumberToNumber(this); | 318 x = %NonNumberToNumber(this); |
| 389 // Make sure to convert the right operand to a number before | 319 // Make sure to convert the right operand to a number before |
| 390 // bailing out in the fast case, but after converting the | 320 // bailing out in the fast case, but after converting the |
| 391 // left operand. This ensures that valueOf methods on the right | 321 // left operand. This ensures that valueOf methods on the right |
| 392 // operand are always executed. | 322 // operand are always executed. |
| 393 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 323 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 394 // Optimize for the case where we end up AND'ing a value | 324 // Optimize for the case where we end up AND'ing a value |
| 395 // that doesn't convert to a number. This is common in | 325 // that doesn't convert to a number. This is common in |
| 396 // certain benchmarks. | 326 // certain benchmarks. |
| 397 if (NUMBER_IS_NAN(x)) return 0; | 327 if (NUMBER_IS_NAN(x)) return 0; |
| 398 } | 328 } |
| 399 return %NumberAnd(x, y); | 329 return %NumberAnd(x, y); |
| 400 } | 330 } |
| 401 | 331 |
| 402 | 332 |
| 403 // Strong mode BIT_AND throws if an implicit conversion would be performed | 333 // Strong mode BIT_AND throws if an implicit conversion would be performed |
| 404 BIT_AND_STRONG = function BIT_AND_STRONG(y) { | 334 function BIT_AND_STRONG(y) { |
| 405 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 335 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 406 return %NumberAnd(this, y); | 336 return %NumberAnd(this, y); |
| 407 } | 337 } |
| 408 throw %MakeTypeError('strong_implicit_cast'); | 338 throw %MakeTypeError('strong_implicit_cast'); |
| 409 } | 339 } |
| 410 | 340 |
| 411 | 341 |
| 412 // ECMA-262, section 11.10, page 57. | 342 // ECMA-262, section 11.10, page 57. |
| 413 BIT_XOR = function BIT_XOR(y) { | 343 function BIT_XOR(y) { |
| 414 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 344 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 415 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 345 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 416 return %NumberXor(x, y); | 346 return %NumberXor(x, y); |
| 417 } | 347 } |
| 418 | 348 |
| 419 | 349 |
| 420 // Strong mode BIT_XOR throws if an implicit conversion would be performed | 350 // Strong mode BIT_XOR throws if an implicit conversion would be performed |
| 421 BIT_XOR_STRONG = function BIT_XOR_STRONG(y) { | 351 function BIT_XOR_STRONG(y) { |
| 422 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 352 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 423 return %NumberXor(this, y); | 353 return %NumberXor(this, y); |
| 424 } | 354 } |
| 425 throw %MakeTypeError('strong_implicit_cast'); | 355 throw %MakeTypeError('strong_implicit_cast'); |
| 426 } | 356 } |
| 427 | 357 |
| 428 | 358 |
| 429 // ECMA-262, section 11.7.1, page 51. | 359 // ECMA-262, section 11.7.1, page 51. |
| 430 SHL = function SHL(y) { | 360 function SHL(y) { |
| 431 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 361 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 432 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 362 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 433 return %NumberShl(x, y); | 363 return %NumberShl(x, y); |
| 434 } | 364 } |
| 435 | 365 |
| 436 | 366 |
| 437 // Strong mode SHL throws if an implicit conversion would be performed | 367 // Strong mode SHL throws if an implicit conversion would be performed |
| 438 SHL_STRONG = function SHL_STRONG(y) { | 368 function SHL_STRONG(y) { |
| 439 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 369 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 440 return %NumberShl(this, y); | 370 return %NumberShl(this, y); |
| 441 } | 371 } |
| 442 throw %MakeTypeError('strong_implicit_cast'); | 372 throw %MakeTypeError('strong_implicit_cast'); |
| 443 } | 373 } |
| 444 | 374 |
| 445 | 375 |
| 446 // ECMA-262, section 11.7.2, page 51. | 376 // ECMA-262, section 11.7.2, page 51. |
| 447 SAR = function SAR(y) { | 377 function SAR(y) { |
| 448 var x; | 378 var x; |
| 449 if (IS_NUMBER(this)) { | 379 if (IS_NUMBER(this)) { |
| 450 x = this; | 380 x = this; |
| 451 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 381 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 452 } else { | 382 } else { |
| 453 x = %$nonNumberToNumber(this); | 383 x = %NonNumberToNumber(this); |
| 454 // Make sure to convert the right operand to a number before | 384 // Make sure to convert the right operand to a number before |
| 455 // bailing out in the fast case, but after converting the | 385 // bailing out in the fast case, but after converting the |
| 456 // left operand. This ensures that valueOf methods on the right | 386 // left operand. This ensures that valueOf methods on the right |
| 457 // operand are always executed. | 387 // operand are always executed. |
| 458 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 388 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 459 // Optimize for the case where we end up shifting a value | 389 // Optimize for the case where we end up shifting a value |
| 460 // that doesn't convert to a number. This is common in | 390 // that doesn't convert to a number. This is common in |
| 461 // certain benchmarks. | 391 // certain benchmarks. |
| 462 if (NUMBER_IS_NAN(x)) return 0; | 392 if (NUMBER_IS_NAN(x)) return 0; |
| 463 } | 393 } |
| 464 return %NumberSar(x, y); | 394 return %NumberSar(x, y); |
| 465 } | 395 } |
| 466 | 396 |
| 467 | 397 |
| 468 // Strong mode SAR throws if an implicit conversion would be performed | 398 // Strong mode SAR throws if an implicit conversion would be performed |
| 469 SAR_STRONG = function SAR_STRONG(y) { | 399 function SAR_STRONG(y) { |
| 470 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 400 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 471 return %NumberSar(this, y); | 401 return %NumberSar(this, y); |
| 472 } | 402 } |
| 473 throw %MakeTypeError('strong_implicit_cast'); | 403 throw %MakeTypeError('strong_implicit_cast'); |
| 474 } | 404 } |
| 475 | 405 |
| 476 | 406 |
| 477 // ECMA-262, section 11.7.3, page 52. | 407 // ECMA-262, section 11.7.3, page 52. |
| 478 SHR = function SHR(y) { | 408 function SHR(y) { |
| 479 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); | 409 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
| 480 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); | 410 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
| 481 return %NumberShr(x, y); | 411 return %NumberShr(x, y); |
| 482 } | 412 } |
| 483 | 413 |
| 484 | 414 |
| 485 // Strong mode SHR throws if an implicit conversion would be performed | 415 // Strong mode SHR throws if an implicit conversion would be performed |
| 486 SHR_STRONG = function SHR_STRONG(y) { | 416 function SHR_STRONG(y) { |
| 487 if (IS_NUMBER(this) && IS_NUMBER(y)) { | 417 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 488 return %NumberShr(this, y); | 418 return %NumberShr(this, y); |
| 489 } | 419 } |
| 490 throw %MakeTypeError('strong_implicit_cast'); | 420 throw %MakeTypeError('strong_implicit_cast'); |
| 491 } | 421 } |
| 492 | 422 |
| 493 | 423 |
| 494 /* ----------------------------- | 424 /* ----------------------------- |
| 495 - - - H e l p e r s - - - | 425 - - - H e l p e r s - - - |
| 496 ----------------------------- | 426 ----------------------------- |
| 497 */ | 427 */ |
| 498 | 428 |
| 499 // ECMA-262, section 11.4.1, page 46. | 429 // ECMA-262, section 11.4.1, page 46. |
| 500 DELETE = function DELETE(key, language_mode) { | 430 function DELETE(key, language_mode) { |
| 501 return %DeleteProperty(%$toObject(this), %$toName(key), language_mode); | 431 return %DeleteProperty(%ToObject(this), %ToName(key), language_mode); |
| 502 } | 432 } |
| 503 | 433 |
| 504 | 434 |
| 505 // ECMA-262, section 11.8.7, page 54. | 435 // ECMA-262, section 11.8.7, page 54. |
| 506 IN = function IN(x) { | 436 function IN(x) { |
| 507 if (!IS_SPEC_OBJECT(x)) { | 437 if (!IS_SPEC_OBJECT(x)) { |
| 508 throw %MakeTypeError(kInvalidInOperatorUse, this, x); | 438 throw %MakeTypeError(kInvalidInOperatorUse, this, x); |
| 509 } | 439 } |
| 510 if (%_IsNonNegativeSmi(this)) { | 440 if (%_IsNonNegativeSmi(this)) { |
| 511 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { | 441 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { |
| 512 return this < x.length; | 442 return this < x.length; |
| 513 } | 443 } |
| 514 return %HasElement(x, this); | 444 return %HasElement(x, this); |
| 515 } | 445 } |
| 516 return %HasProperty(x, %$toName(this)); | 446 return %HasProperty(x, %ToName(this)); |
| 517 } | 447 } |
| 518 | 448 |
| 519 | 449 |
| 520 // ECMA-262, section 11.8.6, page 54. To make the implementation more | 450 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
| 521 // efficient, the return value should be zero if the 'this' is an | 451 // efficient, the return value should be zero if the 'this' is an |
| 522 // instance of F, and non-zero if not. This makes it possible to avoid | 452 // instance of F, and non-zero if not. This makes it possible to avoid |
| 523 // an expensive ToBoolean conversion in the generated code. | 453 // an expensive ToBoolean conversion in the generated code. |
| 524 INSTANCE_OF = function INSTANCE_OF(F) { | 454 function INSTANCE_OF(F) { |
| 525 var V = this; | 455 var V = this; |
| 526 if (!IS_SPEC_FUNCTION(F)) { | 456 if (!IS_SPEC_FUNCTION(F)) { |
| 527 throw %MakeTypeError(kInstanceofFunctionExpected, F); | 457 throw %MakeTypeError(kInstanceofFunctionExpected, F); |
| 528 } | 458 } |
| 529 | 459 |
| 530 // If V is not an object, return false. | 460 // If V is not an object, return false. |
| 531 if (!IS_SPEC_OBJECT(V)) { | 461 if (!IS_SPEC_OBJECT(V)) { |
| 532 return 1; | 462 return 1; |
| 533 } | 463 } |
| 534 | 464 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 545 } | 475 } |
| 546 | 476 |
| 547 // Return whether or not O is in the prototype chain of V. | 477 // Return whether or not O is in the prototype chain of V. |
| 548 return %IsInPrototypeChain(O, V) ? 0 : 1; | 478 return %IsInPrototypeChain(O, V) ? 0 : 1; |
| 549 } | 479 } |
| 550 | 480 |
| 551 | 481 |
| 552 // Filter a given key against an object by checking if the object | 482 // Filter a given key against an object by checking if the object |
| 553 // has a property with the given key; return the key as a string if | 483 // has a property with the given key; return the key as a string if |
| 554 // it has. Otherwise returns 0 (smi). Used in for-in statements. | 484 // it has. Otherwise returns 0 (smi). Used in for-in statements. |
| 555 FILTER_KEY = function FILTER_KEY(key) { | 485 function FILTER_KEY(key) { |
| 556 var string = %$toName(key); | 486 var string = %ToName(key); |
| 557 if (%HasProperty(this, string)) return string; | 487 if (%HasProperty(this, string)) return string; |
| 558 return 0; | 488 return 0; |
| 559 } | 489 } |
| 560 | 490 |
| 561 | 491 |
| 562 CALL_NON_FUNCTION = function CALL_NON_FUNCTION() { | 492 function CALL_NON_FUNCTION() { |
| 563 var delegate = %GetFunctionDelegate(this); | 493 var delegate = %GetFunctionDelegate(this); |
| 564 if (!IS_FUNCTION(delegate)) { | 494 if (!IS_FUNCTION(delegate)) { |
| 565 var callsite = %RenderCallSite(); | 495 var callsite = %RenderCallSite(); |
| 566 if (callsite == "") callsite = typeof this; | 496 if (callsite == "") callsite = typeof this; |
| 567 throw %MakeTypeError(kCalledNonCallable, callsite); | 497 throw %MakeTypeError(kCalledNonCallable, callsite); |
| 568 } | 498 } |
| 569 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); | 499 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); |
| 570 } | 500 } |
| 571 | 501 |
| 572 | 502 |
| 573 CALL_NON_FUNCTION_AS_CONSTRUCTOR = function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { | 503 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { |
| 574 var delegate = %GetConstructorDelegate(this); | 504 var delegate = %GetConstructorDelegate(this); |
| 575 if (!IS_FUNCTION(delegate)) { | 505 if (!IS_FUNCTION(delegate)) { |
| 576 var callsite = %RenderCallSite(); | 506 var callsite = %RenderCallSite(); |
| 577 if (callsite == "") callsite = typeof this; | 507 if (callsite == "") callsite = typeof this; |
| 578 throw %MakeTypeError(kCalledNonCallable, callsite); | 508 throw %MakeTypeError(kCalledNonCallable, callsite); |
| 579 } | 509 } |
| 580 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); | 510 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); |
| 581 } | 511 } |
| 582 | 512 |
| 583 | 513 |
| 584 CALL_FUNCTION_PROXY = function CALL_FUNCTION_PROXY() { | 514 function CALL_FUNCTION_PROXY() { |
| 585 var arity = %_ArgumentsLength() - 1; | 515 var arity = %_ArgumentsLength() - 1; |
| 586 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg. | 516 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg. |
| 587 var trap = %GetCallTrap(proxy); | 517 var trap = %GetCallTrap(proxy); |
| 588 return %Apply(trap, this, arguments, 0, arity); | 518 return %Apply(trap, this, arguments, 0, arity); |
| 589 } | 519 } |
| 590 | 520 |
| 591 | 521 |
| 592 CALL_FUNCTION_PROXY_AS_CONSTRUCTOR = | 522 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR() { |
| 593 function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR () { | |
| 594 var proxy = this; | 523 var proxy = this; |
| 595 var trap = %GetConstructTrap(proxy); | 524 var trap = %GetConstructTrap(proxy); |
| 596 return %Apply(trap, this, arguments, 0, %_ArgumentsLength()); | 525 return %Apply(trap, this, arguments, 0, %_ArgumentsLength()); |
| 597 } | 526 } |
| 598 | 527 |
| 599 | 528 |
| 600 APPLY_PREPARE = function APPLY_PREPARE(args) { | 529 function APPLY_PREPARE(args) { |
| 601 var length; | 530 var length; |
| 602 // First check whether length is a positive Smi and args is an | 531 // First check whether length is a positive Smi and args is an |
| 603 // array. This is the fast case. If this fails, we do the slow case | 532 // array. This is the fast case. If this fails, we do the slow case |
| 604 // that takes care of more eventualities. | 533 // that takes care of more eventualities. |
| 605 if (IS_ARRAY(args)) { | 534 if (IS_ARRAY(args)) { |
| 606 length = args.length; | 535 length = args.length; |
| 607 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && | 536 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 608 IS_SPEC_FUNCTION(this)) { | 537 IS_SPEC_FUNCTION(this)) { |
| 609 return length; | 538 return length; |
| 610 } | 539 } |
| 611 } | 540 } |
| 612 | 541 |
| 613 length = (args == null) ? 0 : %$toUint32(args.length); | 542 length = (args == null) ? 0 : %ToUint32(args.length); |
| 614 | 543 |
| 615 // We can handle any number of apply arguments if the stack is | 544 // We can handle any number of apply arguments if the stack is |
| 616 // big enough, but sanity check the value to avoid overflow when | 545 // big enough, but sanity check the value to avoid overflow when |
| 617 // multiplying with pointer size. | 546 // multiplying with pointer size. |
| 618 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); | 547 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
| 619 | 548 |
| 620 if (!IS_SPEC_FUNCTION(this)) { | 549 if (!IS_SPEC_FUNCTION(this)) { |
| 621 throw %MakeTypeError(kApplyNonFunction, %$toString(this), typeof this); | 550 throw %MakeTypeError(kApplyNonFunction, %ToString(this), typeof this); |
| 622 } | 551 } |
| 623 | 552 |
| 624 // Make sure the arguments list has the right type. | 553 // Make sure the arguments list has the right type. |
| 625 if (args != null && !IS_SPEC_OBJECT(args)) { | 554 if (args != null && !IS_SPEC_OBJECT(args)) { |
| 626 throw %MakeTypeError(kWrongArgs, "Function.prototype.apply"); | 555 throw %MakeTypeError(kWrongArgs, "Function.prototype.apply"); |
| 627 } | 556 } |
| 628 | 557 |
| 629 // Return the length which is the number of arguments to copy to the | 558 // Return the length which is the number of arguments to copy to the |
| 630 // stack. It is guaranteed to be a small integer at this point. | 559 // stack. It is guaranteed to be a small integer at this point. |
| 631 return length; | 560 return length; |
| 632 } | 561 } |
| 633 | 562 |
| 634 | 563 |
| 635 REFLECT_APPLY_PREPARE = function REFLECT_APPLY_PREPARE(args) { | 564 function REFLECT_APPLY_PREPARE(args) { |
| 636 var length; | 565 var length; |
| 637 // First check whether length is a positive Smi and args is an | 566 // First check whether length is a positive Smi and args is an |
| 638 // array. This is the fast case. If this fails, we do the slow case | 567 // array. This is the fast case. If this fails, we do the slow case |
| 639 // that takes care of more eventualities. | 568 // that takes care of more eventualities. |
| 640 if (IS_ARRAY(args)) { | 569 if (IS_ARRAY(args)) { |
| 641 length = args.length; | 570 length = args.length; |
| 642 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && | 571 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 643 IS_SPEC_FUNCTION(this)) { | 572 IS_SPEC_FUNCTION(this)) { |
| 644 return length; | 573 return length; |
| 645 } | 574 } |
| 646 } | 575 } |
| 647 | 576 |
| 648 if (!IS_SPEC_FUNCTION(this)) { | 577 if (!IS_SPEC_FUNCTION(this)) { |
| 649 throw %MakeTypeError(kCalledNonCallable, %$toString(this)); | 578 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); |
| 650 } | 579 } |
| 651 | 580 |
| 652 if (!IS_SPEC_OBJECT(args)) { | 581 if (!IS_SPEC_OBJECT(args)) { |
| 653 throw %MakeTypeError(kWrongArgs, "Reflect.apply"); | 582 throw %MakeTypeError(kWrongArgs, "Reflect.apply"); |
| 654 } | 583 } |
| 655 | 584 |
| 656 length = %$toLength(args.length); | 585 length = %ToLength(args.length); |
| 657 | 586 |
| 658 // We can handle any number of apply arguments if the stack is | 587 // We can handle any number of apply arguments if the stack is |
| 659 // big enough, but sanity check the value to avoid overflow when | 588 // big enough, but sanity check the value to avoid overflow when |
| 660 // multiplying with pointer size. | 589 // multiplying with pointer size. |
| 661 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); | 590 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
| 662 | 591 |
| 663 // Return the length which is the number of arguments to copy to the | 592 // Return the length which is the number of arguments to copy to the |
| 664 // stack. It is guaranteed to be a small integer at this point. | 593 // stack. It is guaranteed to be a small integer at this point. |
| 665 return length; | 594 return length; |
| 666 } | 595 } |
| 667 | 596 |
| 668 | 597 |
| 669 REFLECT_CONSTRUCT_PREPARE = function REFLECT_CONSTRUCT_PREPARE( | 598 function REFLECT_CONSTRUCT_PREPARE(args, newTarget) { |
| 670 args, newTarget) { | |
| 671 var length; | 599 var length; |
| 672 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this); | 600 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this); |
| 673 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget); | 601 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget); |
| 674 | 602 |
| 675 // First check whether length is a positive Smi and args is an | 603 // First check whether length is a positive Smi and args is an |
| 676 // array. This is the fast case. If this fails, we do the slow case | 604 // array. This is the fast case. If this fails, we do the slow case |
| 677 // that takes care of more eventualities. | 605 // that takes care of more eventualities. |
| 678 if (IS_ARRAY(args)) { | 606 if (IS_ARRAY(args)) { |
| 679 length = args.length; | 607 length = args.length; |
| 680 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && | 608 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && |
| 681 ctorOk && newTargetOk) { | 609 ctorOk && newTargetOk) { |
| 682 return length; | 610 return length; |
| 683 } | 611 } |
| 684 } | 612 } |
| 685 | 613 |
| 686 if (!ctorOk) { | 614 if (!ctorOk) { |
| 687 if (!IS_SPEC_FUNCTION(this)) { | 615 if (!IS_SPEC_FUNCTION(this)) { |
| 688 throw %MakeTypeError(kCalledNonCallable, %$toString(this)); | 616 throw %MakeTypeError(kCalledNonCallable, %ToString(this)); |
| 689 } else { | 617 } else { |
| 690 throw %MakeTypeError(kNotConstructor, %$toString(this)); | 618 throw %MakeTypeError(kNotConstructor, %ToString(this)); |
| 691 } | 619 } |
| 692 } | 620 } |
| 693 | 621 |
| 694 if (!newTargetOk) { | 622 if (!newTargetOk) { |
| 695 if (!IS_SPEC_FUNCTION(newTarget)) { | 623 if (!IS_SPEC_FUNCTION(newTarget)) { |
| 696 throw %MakeTypeError(kCalledNonCallable, %$toString(newTarget)); | 624 throw %MakeTypeError(kCalledNonCallable, %ToString(newTarget)); |
| 697 } else { | 625 } else { |
| 698 throw %MakeTypeError(kNotConstructor, %$toString(newTarget)); | 626 throw %MakeTypeError(kNotConstructor, %ToString(newTarget)); |
| 699 } | 627 } |
| 700 } | 628 } |
| 701 | 629 |
| 702 if (!IS_SPEC_OBJECT(args)) { | 630 if (!IS_SPEC_OBJECT(args)) { |
| 703 throw %MakeTypeError(kWrongArgs, "Reflect.construct"); | 631 throw %MakeTypeError(kWrongArgs, "Reflect.construct"); |
| 704 } | 632 } |
| 705 | 633 |
| 706 length = %$toLength(args.length); | 634 length = %ToLength(args.length); |
| 707 | 635 |
| 708 // We can handle any number of apply arguments if the stack is | 636 // We can handle any number of apply arguments if the stack is |
| 709 // big enough, but sanity check the value to avoid overflow when | 637 // big enough, but sanity check the value to avoid overflow when |
| 710 // multiplying with pointer size. | 638 // multiplying with pointer size. |
| 711 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); | 639 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); |
| 712 | 640 |
| 713 // Return the length which is the number of arguments to copy to the | 641 // Return the length which is the number of arguments to copy to the |
| 714 // stack. It is guaranteed to be a small integer at this point. | 642 // stack. It is guaranteed to be a small integer at this point. |
| 715 return length; | 643 return length; |
| 716 } | 644 } |
| 717 | 645 |
| 718 | 646 |
| 719 STACK_OVERFLOW = function STACK_OVERFLOW(length) { | 647 function STACK_OVERFLOW(length) { |
| 720 throw %MakeRangeError(kStackOverflow); | 648 throw %MakeRangeError(kStackOverflow); |
| 721 } | 649 } |
| 722 | 650 |
| 723 | 651 |
| 724 // Convert the receiver to an object - forward to ToObject. | 652 // Convert the receiver to an object - forward to ToObject. |
| 725 TO_OBJECT = function TO_OBJECT() { | 653 function TO_OBJECT() { |
| 726 return %$toObject(this); | 654 return %ToObject(this); |
| 727 } | 655 } |
| 728 | 656 |
| 729 | 657 |
| 730 // Convert the receiver to a number - forward to ToNumber. | 658 // Convert the receiver to a number - forward to ToNumber. |
| 731 TO_NUMBER = function TO_NUMBER() { | 659 function TO_NUMBER() { |
| 732 return %$toNumber(this); | 660 return %ToNumber(this); |
| 733 } | 661 } |
| 734 | 662 |
| 735 | 663 |
| 736 // Convert the receiver to a string - forward to ToString. | 664 // Convert the receiver to a string - forward to ToString. |
| 737 TO_STRING = function TO_STRING() { | 665 function TO_STRING() { |
| 738 return %$toString(this); | 666 return %ToString(this); |
| 739 } | 667 } |
| 740 | 668 |
| 741 | 669 |
| 742 // Convert the receiver to a string or symbol - forward to ToName. | 670 // Convert the receiver to a string or symbol - forward to ToName. |
| 743 TO_NAME = function TO_NAME() { | 671 function TO_NAME() { |
| 744 return %$toName(this); | 672 return %ToName(this); |
| 745 } | 673 } |
| 746 | 674 |
| 747 | 675 |
| 748 /* ----------------------------------------------- | |
| 749 - - - J a v a S c r i p t S t u b s - - - | |
| 750 ----------------------------------------------- | |
| 751 */ | |
| 752 | |
| 753 STRING_LENGTH_STUB = function STRING_LENGTH_STUB(name) { | |
| 754 var receiver = this; // implicit first parameter | |
| 755 return %_StringGetLength(%_JSValueGetValue(receiver)); | |
| 756 } | |
| 757 | |
| 758 | |
| 759 /* ------------------------------------- | 676 /* ------------------------------------- |
| 760 - - - C o n v e r s i o n s - - - | 677 - - - C o n v e r s i o n s - - - |
| 761 ------------------------------------- | 678 ------------------------------------- |
| 762 */ | 679 */ |
| 763 | 680 |
| 764 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 681 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
| 765 // (1) for number hint, and (2) for string hint. | 682 // (1) for number hint, and (2) for string hint. |
| 766 function ToPrimitive(x, hint) { | 683 function ToPrimitive(x, hint) { |
| 767 // Fast case check. | 684 // Fast case check. |
| 768 if (IS_STRING(x)) return x; | 685 if (IS_STRING(x)) return x; |
| 769 // Normal behavior. | 686 // Normal behavior. |
| 770 if (!IS_SPEC_OBJECT(x)) return x; | 687 if (!IS_SPEC_OBJECT(x)) return x; |
| 771 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive); | 688 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive); |
| 772 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 689 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
| 773 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x); | 690 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
| 774 } | 691 } |
| 775 | 692 |
| 776 | 693 |
| 777 // ECMA-262, section 9.2, page 30 | 694 // ECMA-262, section 9.2, page 30 |
| 778 function ToBoolean(x) { | 695 function ToBoolean(x) { |
| 779 if (IS_BOOLEAN(x)) return x; | 696 if (IS_BOOLEAN(x)) return x; |
| 780 if (IS_STRING(x)) return x.length != 0; | 697 if (IS_STRING(x)) return x.length != 0; |
| 781 if (x == null) return false; | 698 if (x == null) return false; |
| 782 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); | 699 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); |
| 783 return true; | 700 return true; |
| 784 } | 701 } |
| 785 | 702 |
| 786 | 703 |
| 787 // ECMA-262, section 9.3, page 31. | 704 // ECMA-262, section 9.3, page 31. |
| 788 function ToNumber(x) { | 705 function ToNumber(x) { |
| 789 if (IS_NUMBER(x)) return x; | 706 if (IS_NUMBER(x)) return x; |
| 790 if (IS_STRING(x)) { | 707 if (IS_STRING(x)) { |
| 791 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 708 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 792 : %StringToNumber(x); | 709 : %StringToNumber(x); |
| 793 } | 710 } |
| 794 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 711 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 795 if (IS_UNDEFINED(x)) return NAN; | 712 if (IS_UNDEFINED(x)) return NAN; |
| 796 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); | 713 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); |
| 797 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); | 714 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 798 } | 715 } |
| 799 | 716 |
| 800 function NonNumberToNumber(x) { | 717 function NonNumberToNumber(x) { |
| 801 if (IS_STRING(x)) { | 718 if (IS_STRING(x)) { |
| 802 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 719 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 803 : %StringToNumber(x); | 720 : %StringToNumber(x); |
| 804 } | 721 } |
| 805 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 722 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 806 if (IS_UNDEFINED(x)) return NAN; | 723 if (IS_UNDEFINED(x)) return NAN; |
| 807 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); | 724 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); |
| 808 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); | 725 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 809 } | 726 } |
| 810 | 727 |
| 811 | 728 |
| 812 // ECMA-262, section 9.8, page 35. | 729 // ECMA-262, section 9.8, page 35. |
| 813 function ToString(x) { | 730 function ToString(x) { |
| 814 if (IS_STRING(x)) return x; | 731 if (IS_STRING(x)) return x; |
| 815 if (IS_NUMBER(x)) return %_NumberToString(x); | 732 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 816 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 733 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 817 if (IS_UNDEFINED(x)) return 'undefined'; | 734 if (IS_UNDEFINED(x)) return 'undefined'; |
| 818 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString); | 735 if (IS_SYMBOL(x)) throw %MakeTypeError(kSymbolToString); |
| 819 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); | 736 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
| 820 } | 737 } |
| 821 | 738 |
| 822 function NonStringToString(x) { | 739 function NonStringToString(x) { |
| 823 if (IS_NUMBER(x)) return %_NumberToString(x); | 740 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 824 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 741 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 825 if (IS_UNDEFINED(x)) return 'undefined'; | 742 if (IS_UNDEFINED(x)) return 'undefined'; |
| 826 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString); | 743 if (IS_SYMBOL(x)) throw %MakeTypeError(kSymbolToString); |
| 827 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); | 744 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
| 828 } | 745 } |
| 829 | 746 |
| 830 | 747 |
| 831 // ES6 symbols | 748 // ES6 symbols |
| 832 function ToName(x) { | 749 function ToName(x) { |
| 833 return IS_SYMBOL(x) ? x : ToString(x); | 750 return IS_SYMBOL(x) ? x : %ToString(x); |
| 834 } | 751 } |
| 835 | 752 |
| 836 | 753 |
| 837 // ECMA-262, section 9.9, page 36. | 754 // ECMA-262, section 9.9, page 36. |
| 838 function ToObject(x) { | 755 function ToObject(x) { |
| 839 if (IS_STRING(x)) return new GlobalString(x); | 756 if (IS_STRING(x)) return new $String(x); |
| 840 if (IS_NUMBER(x)) return new GlobalNumber(x); | 757 if (IS_NUMBER(x)) return new $Number(x); |
| 841 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); | 758 if (IS_BOOLEAN(x)) return new $Boolean(x); |
| 842 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); | 759 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); |
| 843 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 760 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
| 844 throw MakeTypeError(kUndefinedOrNullToObject); | 761 throw %MakeTypeError(kUndefinedOrNullToObject); |
| 845 } | 762 } |
| 846 return x; | 763 return x; |
| 847 } | 764 } |
| 848 | 765 |
| 849 | 766 |
| 850 // ECMA-262, section 9.4, page 34. | 767 // ECMA-262, section 9.4, page 34. |
| 851 function ToInteger(x) { | 768 function ToInteger(x) { |
| 852 if (%_IsSmi(x)) return x; | 769 if (%_IsSmi(x)) return x; |
| 853 return %NumberToInteger(ToNumber(x)); | 770 return %NumberToInteger(ToNumber(x)); |
| 854 } | 771 } |
| 855 | 772 |
| 856 | 773 |
| 857 // ES6, draft 08-24-14, section 7.1.15 | 774 // ES6, draft 08-24-14, section 7.1.15 |
| 858 function ToLength(arg) { | 775 function ToLength(arg) { |
| 859 arg = ToInteger(arg); | 776 arg = ToInteger(arg); |
| 860 if (arg < 0) return 0; | 777 if (arg < 0) return 0; |
| 861 return arg < GlobalNumber.MAX_SAFE_INTEGER ? arg | 778 return arg < $Number.MAX_SAFE_INTEGER ? arg : $Number.MAX_SAFE_INTEGER; |
| 862 : GlobalNumber.MAX_SAFE_INTEGER; | |
| 863 } | 779 } |
| 864 | 780 |
| 865 | 781 |
| 866 // ECMA-262, section 9.6, page 34. | 782 // ECMA-262, section 9.6, page 34. |
| 867 function ToUint32(x) { | 783 function ToUint32(x) { |
| 868 if (%_IsSmi(x) && x >= 0) return x; | 784 if (%_IsSmi(x) && x >= 0) return x; |
| 869 return %NumberToJSUint32(ToNumber(x)); | 785 return %NumberToJSUint32(ToNumber(x)); |
| 870 } | 786 } |
| 871 | 787 |
| 872 | 788 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 883 if (IS_NUMBER(x)) { | 799 if (IS_NUMBER(x)) { |
| 884 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | 800 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; |
| 885 // x is +0 and y is -0 or vice versa. | 801 // x is +0 and y is -0 or vice versa. |
| 886 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { | 802 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { |
| 887 return false; | 803 return false; |
| 888 } | 804 } |
| 889 } | 805 } |
| 890 return x === y; | 806 return x === y; |
| 891 } | 807 } |
| 892 | 808 |
| 893 | |
| 894 // ES6, section 7.2.4 | 809 // ES6, section 7.2.4 |
| 895 function SameValueZero(x, y) { | 810 function SameValueZero(x, y) { |
| 896 if (typeof x != typeof y) return false; | 811 if (typeof x != typeof y) return false; |
| 897 if (IS_NUMBER(x)) { | 812 if (IS_NUMBER(x)) { |
| 898 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | 813 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; |
| 899 } | 814 } |
| 900 return x === y; | 815 return x === y; |
| 901 } | 816 } |
| 902 | 817 |
| 903 | 818 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 924 return ToBoolean(spreadable); | 839 return ToBoolean(spreadable); |
| 925 } | 840 } |
| 926 | 841 |
| 927 | 842 |
| 928 // ECMA-262, section 8.6.2.6, page 28. | 843 // ECMA-262, section 8.6.2.6, page 28. |
| 929 function DefaultNumber(x) { | 844 function DefaultNumber(x) { |
| 930 if (!IS_SYMBOL_WRAPPER(x)) { | 845 if (!IS_SYMBOL_WRAPPER(x)) { |
| 931 var valueOf = x.valueOf; | 846 var valueOf = x.valueOf; |
| 932 if (IS_SPEC_FUNCTION(valueOf)) { | 847 if (IS_SPEC_FUNCTION(valueOf)) { |
| 933 var v = %_CallFunction(x, valueOf); | 848 var v = %_CallFunction(x, valueOf); |
| 934 if (IsPrimitive(v)) return v; | 849 if (%IsPrimitive(v)) return v; |
| 935 } | 850 } |
| 936 | 851 |
| 937 var toString = x.toString; | 852 var toString = x.toString; |
| 938 if (IS_SPEC_FUNCTION(toString)) { | 853 if (IS_SPEC_FUNCTION(toString)) { |
| 939 var s = %_CallFunction(x, toString); | 854 var s = %_CallFunction(x, toString); |
| 940 if (IsPrimitive(s)) return s; | 855 if (%IsPrimitive(s)) return s; |
| 941 } | 856 } |
| 942 } | 857 } |
| 943 throw MakeTypeError(kCannotConvertToPrimitive); | 858 throw %MakeTypeError(kCannotConvertToPrimitive); |
| 944 } | 859 } |
| 945 | 860 |
| 946 // ECMA-262, section 8.6.2.6, page 28. | 861 // ECMA-262, section 8.6.2.6, page 28. |
| 947 function DefaultString(x) { | 862 function DefaultString(x) { |
| 948 if (!IS_SYMBOL_WRAPPER(x)) { | 863 if (!IS_SYMBOL_WRAPPER(x)) { |
| 949 var toString = x.toString; | 864 var toString = x.toString; |
| 950 if (IS_SPEC_FUNCTION(toString)) { | 865 if (IS_SPEC_FUNCTION(toString)) { |
| 951 var s = %_CallFunction(x, toString); | 866 var s = %_CallFunction(x, toString); |
| 952 if (IsPrimitive(s)) return s; | 867 if (%IsPrimitive(s)) return s; |
| 953 } | 868 } |
| 954 | 869 |
| 955 var valueOf = x.valueOf; | 870 var valueOf = x.valueOf; |
| 956 if (IS_SPEC_FUNCTION(valueOf)) { | 871 if (IS_SPEC_FUNCTION(valueOf)) { |
| 957 var v = %_CallFunction(x, valueOf); | 872 var v = %_CallFunction(x, valueOf); |
| 958 if (IsPrimitive(v)) return v; | 873 if (%IsPrimitive(v)) return v; |
| 959 } | 874 } |
| 960 } | 875 } |
| 961 throw MakeTypeError(kCannotConvertToPrimitive); | 876 throw %MakeTypeError(kCannotConvertToPrimitive); |
| 962 } | 877 } |
| 963 | 878 |
| 964 function ToPositiveInteger(x, rangeErrorIndex) { | 879 function ToPositiveInteger(x, rangeErrorIndex) { |
| 965 var i = TO_INTEGER_MAP_MINUS_ZERO(x); | 880 var i = TO_INTEGER_MAP_MINUS_ZERO(x); |
| 966 if (i < 0) throw MakeRangeError(rangeErrorIndex); | 881 if (i < 0) throw MakeRangeError(rangeErrorIndex); |
| 967 return i; | 882 return i; |
| 968 } | 883 } |
| 969 | 884 |
| 970 //---------------------------------------------------------------------------- | |
| 971 | 885 |
| 972 // NOTE: Setting the prototype for Array must take place as early as | 886 // NOTE: Setting the prototype for Array must take place as early as |
| 973 // possible due to code generation for array literals. When | 887 // possible due to code generation for array literals. When |
| 974 // generating code for a array literal a boilerplate array is created | 888 // generating code for a array literal a boilerplate array is created |
| 975 // that is cloned when running the code. It is essential that the | 889 // that is cloned when running the code. It is essential that the |
| 976 // boilerplate gets the right prototype. | 890 // boilerplate gets the right prototype. |
| 977 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); | 891 %FunctionSetPrototype($Array, new $Array(0)); |
| 978 | 892 |
| 979 //---------------------------------------------------------------------------- | |
| 980 | 893 |
| 981 $defaultNumber = DefaultNumber; | 894 /* ----------------------------------------------- |
| 982 $defaultString = DefaultString; | 895 - - - J a v a S c r i p t S t u b s - - - |
| 983 $NaN = %GetRootNaN(); | 896 ----------------------------------------------- |
| 984 $nonNumberToNumber = NonNumberToNumber; | 897 */ |
| 985 $nonStringToString = NonStringToString; | |
| 986 $sameValue = SameValue; | |
| 987 $sameValueZero = SameValueZero; | |
| 988 $toBoolean = ToBoolean; | |
| 989 $toInt32 = ToInt32; | |
| 990 $toInteger = ToInteger; | |
| 991 $toLength = ToLength; | |
| 992 $toName = ToName; | |
| 993 $toNumber = ToNumber; | |
| 994 $toObject = ToObject; | |
| 995 $toPositiveInteger = ToPositiveInteger; | |
| 996 $toPrimitive = ToPrimitive; | |
| 997 $toString = ToString; | |
| 998 $toUint32 = ToUint32; | |
| 999 | 898 |
| 1000 })(); | 899 function STRING_LENGTH_STUB(name) { |
| 900 var receiver = this; // implicit first parameter |
| 901 return %_StringGetLength(%_JSValueGetValue(receiver)); |
| 902 } |
| OLD | NEW |