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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 */ | 265 */ |
266 | 266 |
267 // ECMA-262, section 11.10, page 57. | 267 // ECMA-262, section 11.10, page 57. |
268 function BIT_OR(y) { | 268 function BIT_OR(y) { |
269 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); | 269 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
270 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 270 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
271 return %NumberOr(x, y); | 271 return %NumberOr(x, y); |
272 } | 272 } |
273 | 273 |
274 | 274 |
| 275 //ECMA-262, section 11.10, page 57. |
| 276 function BIT_OR_STRONG(y) { |
| 277 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 278 return %NumberOr(this, y); |
| 279 } |
| 280 throw %MakeTypeError('strong_implicit_cast'); |
| 281 } |
| 282 |
| 283 |
275 // ECMA-262, section 11.10, page 57. | 284 // ECMA-262, section 11.10, page 57. |
276 function BIT_AND(y) { | 285 function BIT_AND(y) { |
277 var x; | 286 var x; |
278 if (IS_NUMBER(this)) { | 287 if (IS_NUMBER(this)) { |
279 x = this; | 288 x = this; |
280 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 289 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
281 } else { | 290 } else { |
282 x = %NonNumberToNumber(this); | 291 x = %NonNumberToNumber(this); |
283 // Make sure to convert the right operand to a number before | 292 // Make sure to convert the right operand to a number before |
284 // bailing out in the fast case, but after converting the | 293 // bailing out in the fast case, but after converting the |
285 // left operand. This ensures that valueOf methods on the right | 294 // left operand. This ensures that valueOf methods on the right |
286 // operand are always executed. | 295 // operand are always executed. |
287 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 296 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
288 // Optimize for the case where we end up AND'ing a value | 297 // Optimize for the case where we end up AND'ing a value |
289 // that doesn't convert to a number. This is common in | 298 // that doesn't convert to a number. This is common in |
290 // certain benchmarks. | 299 // certain benchmarks. |
291 if (NUMBER_IS_NAN(x)) return 0; | 300 if (NUMBER_IS_NAN(x)) return 0; |
292 } | 301 } |
293 return %NumberAnd(x, y); | 302 return %NumberAnd(x, y); |
294 } | 303 } |
295 | 304 |
296 | 305 |
| 306 //ECMA-262, section 11.10, page 57. |
| 307 function BIT_AND_STRONG(y) { |
| 308 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 309 return %NumberAnd(this, y); |
| 310 } |
| 311 throw %MakeTypeError('strong_implicit_cast'); |
| 312 } |
| 313 |
| 314 |
297 // ECMA-262, section 11.10, page 57. | 315 // ECMA-262, section 11.10, page 57. |
298 function BIT_XOR(y) { | 316 function BIT_XOR(y) { |
299 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); | 317 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
300 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 318 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
301 return %NumberXor(x, y); | 319 return %NumberXor(x, y); |
302 } | 320 } |
303 | 321 |
304 | 322 |
| 323 //ECMA-262, section 11.10, page 57. |
| 324 function BIT_XOR_STRONG(y) { |
| 325 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 326 return %NumberXor(this, y); |
| 327 } |
| 328 throw %MakeTypeError('strong_implicit_cast'); |
| 329 } |
| 330 |
| 331 |
305 // ECMA-262, section 11.7.1, page 51. | 332 // ECMA-262, section 11.7.1, page 51. |
306 function SHL(y) { | 333 function SHL(y) { |
307 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); | 334 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
308 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 335 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
309 return %NumberShl(x, y); | 336 return %NumberShl(x, y); |
310 } | 337 } |
311 | 338 |
312 | 339 |
| 340 //ECMA-262, section 11.7.1, page 51. |
| 341 function SHL_STRONG(y) { |
| 342 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 343 return %NumberShl(this, y); |
| 344 } |
| 345 throw %MakeTypeError('strong_implicit_cast'); |
| 346 } |
| 347 |
| 348 |
313 // ECMA-262, section 11.7.2, page 51. | 349 // ECMA-262, section 11.7.2, page 51. |
314 function SAR(y) { | 350 function SAR(y) { |
315 var x; | 351 var x; |
316 if (IS_NUMBER(this)) { | 352 if (IS_NUMBER(this)) { |
317 x = this; | 353 x = this; |
318 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 354 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
319 } else { | 355 } else { |
320 x = %NonNumberToNumber(this); | 356 x = %NonNumberToNumber(this); |
321 // Make sure to convert the right operand to a number before | 357 // Make sure to convert the right operand to a number before |
322 // bailing out in the fast case, but after converting the | 358 // bailing out in the fast case, but after converting the |
323 // left operand. This ensures that valueOf methods on the right | 359 // left operand. This ensures that valueOf methods on the right |
324 // operand are always executed. | 360 // operand are always executed. |
325 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 361 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
326 // Optimize for the case where we end up shifting a value | 362 // Optimize for the case where we end up shifting a value |
327 // that doesn't convert to a number. This is common in | 363 // that doesn't convert to a number. This is common in |
328 // certain benchmarks. | 364 // certain benchmarks. |
329 if (NUMBER_IS_NAN(x)) return 0; | 365 if (NUMBER_IS_NAN(x)) return 0; |
330 } | 366 } |
331 return %NumberSar(x, y); | 367 return %NumberSar(x, y); |
332 } | 368 } |
333 | 369 |
334 | 370 |
| 371 //ECMA-262, section 11.7.2, page 51. |
| 372 function SAR_STRONG(y) { |
| 373 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 374 return %NumberSar(this, y); |
| 375 } |
| 376 throw %MakeTypeError('strong_implicit_cast'); |
| 377 } |
| 378 |
| 379 |
335 // ECMA-262, section 11.7.3, page 52. | 380 // ECMA-262, section 11.7.3, page 52. |
336 function SHR(y) { | 381 function SHR(y) { |
337 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); | 382 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); |
338 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); | 383 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); |
339 return %NumberShr(x, y); | 384 return %NumberShr(x, y); |
340 } | 385 } |
341 | 386 |
342 | 387 |
| 388 //ECMA-262, section 11.7.3, page 52. |
| 389 function SHR_STRONG(y) { |
| 390 if (IS_NUMBER(this) && IS_NUMBER(y)) { |
| 391 return %NumberShr(this, y); |
| 392 } |
| 393 throw %MakeTypeError('strong_implicit_cast'); |
| 394 } |
| 395 |
343 | 396 |
344 /* ----------------------------- | 397 /* ----------------------------- |
345 - - - H e l p e r s - - - | 398 - - - H e l p e r s - - - |
346 ----------------------------- | 399 ----------------------------- |
347 */ | 400 */ |
348 | 401 |
349 // ECMA-262, section 11.4.1, page 46. | 402 // ECMA-262, section 11.4.1, page 46. |
350 function DELETE(key, language_mode) { | 403 function DELETE(key, language_mode) { |
351 return %DeleteProperty(%ToObject(this), %ToName(key), language_mode); | 404 return %DeleteProperty(%ToObject(this), %ToName(key), language_mode); |
352 } | 405 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 866 |
814 /* ----------------------------------------------- | 867 /* ----------------------------------------------- |
815 - - - J a v a S c r i p t S t u b s - - - | 868 - - - J a v a S c r i p t S t u b s - - - |
816 ----------------------------------------------- | 869 ----------------------------------------------- |
817 */ | 870 */ |
818 | 871 |
819 function STRING_LENGTH_STUB(name) { | 872 function STRING_LENGTH_STUB(name) { |
820 var receiver = this; // implicit first parameter | 873 var receiver = this; // implicit first parameter |
821 return %_StringGetLength(%_JSValueGetValue(receiver)); | 874 return %_StringGetLength(%_JSValueGetValue(receiver)); |
822 } | 875 } |
OLD | NEW |