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_SPEC_OBJECT_OR_NULL(y)) { | 83 if (IS_SPEC_OBJECT(y)) { |
84 return %_ObjectEquals(x, y) ? 0 : 1; | 84 return %_ObjectEquals(x, y) ? 0 : 1; |
85 } | 85 } |
86 | 86 |
87 x = %ToPrimitive(x, NO_HINT); | 87 x = %ToPrimitive(x, NO_HINT); |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // ECMA-262, section 11.9.4, page 56. | 92 // ECMA-262, section 11.9.4, page 56. |
93 function STRICT_EQUALS(x) { | 93 function STRICT_EQUALS(x) { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 */ | 338 */ |
339 | 339 |
340 // ECMA-262, section 11.4.1, page 46. | 340 // ECMA-262, section 11.4.1, page 46. |
341 function DELETE(key) { | 341 function DELETE(key) { |
342 return %DeleteProperty(%ToObject(this), %ToString(key)); | 342 return %DeleteProperty(%ToObject(this), %ToString(key)); |
343 } | 343 } |
344 | 344 |
345 | 345 |
346 // ECMA-262, section 11.8.7, page 54. | 346 // ECMA-262, section 11.8.7, page 54. |
347 function IN(x) { | 347 function IN(x) { |
348 if (x == null || !IS_SPEC_OBJECT_OR_NULL(x)) { | 348 if (!IS_SPEC_OBJECT(x)) { |
349 throw %MakeTypeError('invalid_in_operator_use', [this, x]); | 349 throw %MakeTypeError('invalid_in_operator_use', [this, x]); |
350 } | 350 } |
351 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); | 351 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 // ECMA-262, section 11.8.6, page 54. To make the implementation more | 355 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
356 // efficient, the return value should be zero if the 'this' is an | 356 // efficient, the return value should be zero if the 'this' is an |
357 // instance of F, and non-zero if not. This makes it possible to avoid | 357 // instance of F, and non-zero if not. This makes it possible to avoid |
358 // an expensive ToBoolean conversion in the generated code. | 358 // an expensive ToBoolean conversion in the generated code. |
359 function INSTANCE_OF(F) { | 359 function INSTANCE_OF(F) { |
360 var V = this; | 360 var V = this; |
361 if (!IS_FUNCTION(F)) { | 361 if (!IS_FUNCTION(F)) { |
362 throw %MakeTypeError('instanceof_function_expected', [V]); | 362 throw %MakeTypeError('instanceof_function_expected', [V]); |
363 } | 363 } |
364 | 364 |
365 // If V is not an object, return false. | 365 // If V is not an object, return false. |
366 if (IS_NULL(V) || !IS_SPEC_OBJECT_OR_NULL(V)) { | 366 if (!IS_SPEC_OBJECT(V)) { |
367 return 1; | 367 return 1; |
368 } | 368 } |
369 | 369 |
370 // Get the prototype of F; if it is not an object, throw an error. | 370 // Get the prototype of F; if it is not an object, throw an error. |
371 var O = F.prototype; | 371 var O = F.prototype; |
372 if (IS_NULL(O) || !IS_SPEC_OBJECT_OR_NULL(O)) { | 372 if (!IS_SPEC_OBJECT(O)) { |
373 throw %MakeTypeError('instanceof_nonobject_proto', [O]); | 373 throw %MakeTypeError('instanceof_nonobject_proto', [O]); |
374 } | 374 } |
375 | 375 |
376 // Return whether or not O is in the prototype chain of V. | 376 // Return whether or not O is in the prototype chain of V. |
377 return %IsInPrototypeChain(O, V) ? 0 : 1; | 377 return %IsInPrototypeChain(O, V) ? 0 : 1; |
378 } | 378 } |
379 | 379 |
380 | 380 |
381 // Get an array of property keys for the given object. Used in | 381 // Get an array of property keys for the given object. Used in |
382 // for-in statements. | 382 // for-in statements. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 - - - C o n v e r s i o n s - - - | 476 - - - C o n v e r s i o n s - - - |
477 ------------------------------------- | 477 ------------------------------------- |
478 */ | 478 */ |
479 | 479 |
480 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 480 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
481 // (1) for number hint, and (2) for string hint. | 481 // (1) for number hint, and (2) for string hint. |
482 function ToPrimitive(x, hint) { | 482 function ToPrimitive(x, hint) { |
483 // Fast case check. | 483 // Fast case check. |
484 if (IS_STRING(x)) return x; | 484 if (IS_STRING(x)) return x; |
485 // Normal behavior. | 485 // Normal behavior. |
486 if (!IS_SPEC_OBJECT_OR_NULL(x)) return x; | 486 if (!IS_SPEC_OBJECT(x)) return x; |
487 if (x == null) return x; // check for null, undefined | |
488 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 487 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
489 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 488 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
490 } | 489 } |
491 | 490 |
492 | 491 |
493 // ECMA-262, section 9.2, page 30 | 492 // ECMA-262, section 9.2, page 30 |
494 function ToBoolean(x) { | 493 function ToBoolean(x) { |
495 if (IS_BOOLEAN(x)) return x; | 494 if (IS_BOOLEAN(x)) return x; |
496 if (IS_STRING(x)) return x.length != 0; | 495 if (IS_STRING(x)) return x.length != 0; |
497 if (x == null) return false; | 496 if (x == null) return false; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 575 |
577 | 576 |
578 /* --------------------------------- | 577 /* --------------------------------- |
579 - - - U t i l i t i e s - - - | 578 - - - U t i l i t i e s - - - |
580 --------------------------------- | 579 --------------------------------- |
581 */ | 580 */ |
582 | 581 |
583 // Returns if the given x is a primitive value - not an object or a | 582 // Returns if the given x is a primitive value - not an object or a |
584 // function. | 583 // function. |
585 function IsPrimitive(x) { | 584 function IsPrimitive(x) { |
586 if (!IS_SPEC_OBJECT_OR_NULL(x)) { | 585 // Even though the type of null is "object", null is still |
587 return true; | 586 // considered a primitive value. IS_SPEC_OBJECT handles this correctly |
588 } else { | 587 // (i.e., it will return false if x is null). |
589 // Even though the type of null is "object", null is still | 588 return !IS_SPEC_OBJECT(x); |
590 // considered a primitive value. | |
591 return IS_NULL(x); | |
592 } | |
593 } | 589 } |
594 | 590 |
595 | 591 |
596 // ECMA-262, section 8.6.2.6, page 28. | 592 // ECMA-262, section 8.6.2.6, page 28. |
597 function DefaultNumber(x) { | 593 function DefaultNumber(x) { |
598 if (IS_FUNCTION(x.valueOf)) { | 594 if (IS_FUNCTION(x.valueOf)) { |
599 var v = x.valueOf(); | 595 var v = x.valueOf(); |
600 if (%IsPrimitive(v)) return v; | 596 if (%IsPrimitive(v)) return v; |
601 } | 597 } |
602 | 598 |
(...skipping 21 matching lines...) Expand all Loading... |
624 throw %MakeTypeError('cannot_convert_to_primitive', []); | 620 throw %MakeTypeError('cannot_convert_to_primitive', []); |
625 } | 621 } |
626 | 622 |
627 | 623 |
628 // NOTE: Setting the prototype for Array must take place as early as | 624 // NOTE: Setting the prototype for Array must take place as early as |
629 // possible due to code generation for array literals. When | 625 // possible due to code generation for array literals. When |
630 // generating code for a array literal a boilerplate array is created | 626 // generating code for a array literal a boilerplate array is created |
631 // that is cloned when running the code. It is essiential that the | 627 // that is cloned when running the code. It is essiential that the |
632 // boilerplate gets the right prototype. | 628 // boilerplate gets the right prototype. |
633 %FunctionSetPrototype($Array, new $Array(0)); | 629 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |