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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return %_ObjectEquals(x, y) ? 0 : 1; | 73 return %_ObjectEquals(x, y) ? 0 : 1; |
74 } | 74 } |
75 if (y == null) return 1; // not equal | 75 if (y == null) return 1; // not equal |
76 return %NumberEquals(%ToNumber(x), %ToNumber(y)); | 76 return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
77 } else if (x == null) { | 77 } else if (x == null) { |
78 // NOTE: This checks for both null and undefined. | 78 // NOTE: This checks for both null and undefined. |
79 return (y == null) ? 0 : 1; | 79 return (y == null) ? 0 : 1; |
80 } else { | 80 } else { |
81 // x is not a number, boolean, null or undefined. | 81 // x is not a number, boolean, null or undefined. |
82 if (y == null) return 1; // not equal | 82 if (y == null) return 1; // not equal |
83 if (IS_OBJECT(y)) { | 83 if (IS_SPEC_OBJECT_OR_NULL(y)) { |
84 return %_ObjectEquals(x, y) ? 0 : 1; | |
85 } | |
86 if (IS_FUNCTION(y)) { | |
87 return %_ObjectEquals(x, y) ? 0 : 1; | 84 return %_ObjectEquals(x, y) ? 0 : 1; |
88 } | 85 } |
89 | 86 |
90 x = %ToPrimitive(x, NO_HINT); | 87 x = %ToPrimitive(x, NO_HINT); |
91 } | 88 } |
92 } | 89 } |
93 } | 90 } |
94 | 91 |
95 // ECMA-262, section 11.9.4, page 56. | 92 // ECMA-262, section 11.9.4, page 56. |
96 function STRICT_EQUALS(x) { | 93 function STRICT_EQUALS(x) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 */ | 334 */ |
338 | 335 |
339 // ECMA-262, section 11.4.1, page 46. | 336 // ECMA-262, section 11.4.1, page 46. |
340 function DELETE(key) { | 337 function DELETE(key) { |
341 return %DeleteProperty(%ToObject(this), %ToString(key)); | 338 return %DeleteProperty(%ToObject(this), %ToString(key)); |
342 } | 339 } |
343 | 340 |
344 | 341 |
345 // ECMA-262, section 11.8.7, page 54. | 342 // ECMA-262, section 11.8.7, page 54. |
346 function IN(x) { | 343 function IN(x) { |
347 if (x == null || (!IS_OBJECT(x) && !IS_FUNCTION(x))) { | 344 if (x == null || !IS_SPEC_OBJECT_OR_NULL(x)) { |
348 throw %MakeTypeError('invalid_in_operator_use', [this, x]); | 345 throw %MakeTypeError('invalid_in_operator_use', [this, x]); |
349 } | 346 } |
350 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); | 347 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); |
351 } | 348 } |
352 | 349 |
353 | 350 |
354 // ECMA-262, section 11.8.6, page 54. To make the implementation more | 351 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
355 // efficient, the return value should be zero if the 'this' is an | 352 // efficient, the return value should be zero if the 'this' is an |
356 // instance of F, and non-zero if not. This makes it possible to avoid | 353 // instance of F, and non-zero if not. This makes it possible to avoid |
357 // an expensive ToBoolean conversion in the generated code. | 354 // an expensive ToBoolean conversion in the generated code. |
358 function INSTANCE_OF(F) { | 355 function INSTANCE_OF(F) { |
359 var V = this; | 356 var V = this; |
360 if (!IS_FUNCTION(F)) { | 357 if (!IS_FUNCTION(F)) { |
361 throw %MakeTypeError('instanceof_function_expected', [V]); | 358 throw %MakeTypeError('instanceof_function_expected', [V]); |
362 } | 359 } |
363 | 360 |
364 // If V is not an object, return false. | 361 // If V is not an object, return false. |
365 if (IS_NULL(V) || (!IS_OBJECT(V) && !IS_FUNCTION(V))) { | 362 if (IS_NULL(V) || !IS_SPEC_OBJECT_OR_NULL(V)) { |
366 return 1; | 363 return 1; |
367 } | 364 } |
368 | 365 |
369 // Get the prototype of F; if it is not an object, throw an error. | 366 // Get the prototype of F; if it is not an object, throw an error. |
370 var O = F.prototype; | 367 var O = F.prototype; |
371 if (IS_NULL(O) || (!IS_OBJECT(O) && !IS_FUNCTION(O))) { | 368 if (IS_NULL(O) || !IS_SPEC_OBJECT_OR_NULL(O)) { |
372 throw %MakeTypeError('instanceof_nonobject_proto', [O]); | 369 throw %MakeTypeError('instanceof_nonobject_proto', [O]); |
373 } | 370 } |
374 | 371 |
375 // Return whether or not O is in the prototype chain of V. | 372 // Return whether or not O is in the prototype chain of V. |
376 return %IsInPrototypeChain(O, V) ? 0 : 1; | 373 return %IsInPrototypeChain(O, V) ? 0 : 1; |
377 } | 374 } |
378 | 375 |
379 | 376 |
380 // Get an array of property keys for the given object. Used in | 377 // Get an array of property keys for the given object. Used in |
381 // for-in statements. | 378 // for-in statements. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 - - - C o n v e r s i o n s - - - | 472 - - - C o n v e r s i o n s - - - |
476 ------------------------------------- | 473 ------------------------------------- |
477 */ | 474 */ |
478 | 475 |
479 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 476 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
480 // (1) for number hint, and (2) for string hint. | 477 // (1) for number hint, and (2) for string hint. |
481 function ToPrimitive(x, hint) { | 478 function ToPrimitive(x, hint) { |
482 // Fast case check. | 479 // Fast case check. |
483 if (IS_STRING(x)) return x; | 480 if (IS_STRING(x)) return x; |
484 // Normal behavior. | 481 // Normal behavior. |
485 if (!IS_OBJECT(x) && !IS_FUNCTION(x)) return x; | 482 if (!IS_SPEC_OBJECT_OR_NULL(x)) return x; |
486 if (x == null) return x; // check for null, undefined | 483 if (x == null) return x; // check for null, undefined |
487 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 484 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
488 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 485 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
489 } | 486 } |
490 | 487 |
491 | 488 |
492 // ECMA-262, section 9.2, page 30 | 489 // ECMA-262, section 9.2, page 30 |
493 function ToBoolean(x) { | 490 function ToBoolean(x) { |
494 if (IS_BOOLEAN(x)) return x; | 491 if (IS_BOOLEAN(x)) return x; |
495 if (IS_STRING(x)) return x.length != 0; | 492 if (IS_STRING(x)) return x.length != 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 577 |
581 | 578 |
582 /* --------------------------------- | 579 /* --------------------------------- |
583 - - - U t i l i t i e s - - - | 580 - - - U t i l i t i e s - - - |
584 --------------------------------- | 581 --------------------------------- |
585 */ | 582 */ |
586 | 583 |
587 // Returns if the given x is a primitive value - not an object or a | 584 // Returns if the given x is a primitive value - not an object or a |
588 // function. | 585 // function. |
589 function IsPrimitive(x) { | 586 function IsPrimitive(x) { |
590 if (!IS_OBJECT(x) && !IS_FUNCTION(x)) { | 587 if (!IS_SPEC_OBJECT_OR_NULL(x)) { |
591 return true; | 588 return true; |
592 } else { | 589 } else { |
593 // Even though the type of null is "object", null is still | 590 // Even though the type of null is "object", null is still |
594 // considered a primitive value. | 591 // considered a primitive value. |
595 return IS_NULL(x); | 592 return IS_NULL(x); |
596 } | 593 } |
597 } | 594 } |
598 | 595 |
599 | 596 |
600 // ECMA-262, section 8.6.2.6, page 28. | 597 // ECMA-262, section 8.6.2.6, page 28. |
(...skipping 27 matching lines...) Expand all Loading... |
628 throw %MakeTypeError('cannot_convert_to_primitive', []); | 625 throw %MakeTypeError('cannot_convert_to_primitive', []); |
629 } | 626 } |
630 | 627 |
631 | 628 |
632 // NOTE: Setting the prototype for Array must take place as early as | 629 // NOTE: Setting the prototype for Array must take place as early as |
633 // possible due to code generation for array literals. When | 630 // possible due to code generation for array literals. When |
634 // generating code for a array literal a boilerplate array is created | 631 // generating code for a array literal a boilerplate array is created |
635 // that is cloned when running the code. It is essiential that the | 632 // that is cloned when running the code. It is essiential that the |
636 // boilerplate gets the right prototype. | 633 // boilerplate gets the right prototype. |
637 %FunctionSetPrototype($Array, new $Array(0)); | 634 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |