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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 62 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
63 if (!IS_SPEC_OBJECT(y)) { | 63 if (!IS_SPEC_OBJECT(y)) { |
64 // String or boolean. | 64 // String or boolean. |
65 return %NumberEquals(x, %ToNumber(y)); | 65 return %NumberEquals(x, %ToNumber(y)); |
66 } | 66 } |
67 y = %ToPrimitive(y, NO_HINT); | 67 y = %ToPrimitive(y, NO_HINT); |
68 } | 68 } |
69 } else if (IS_STRING(x)) { | 69 } else if (IS_STRING(x)) { |
70 while (true) { | 70 while (true) { |
71 if (IS_STRING(y)) return %StringEquals(x, y); | 71 if (IS_STRING(y)) return %StringEquals(x, y); |
| 72 if (IS_SYMBOL(y)) return 1; // not equal |
72 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); | 73 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); |
73 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); | 74 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
74 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 75 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
75 y = %ToPrimitive(y, NO_HINT); | 76 y = %ToPrimitive(y, NO_HINT); |
76 } | 77 } |
| 78 } else if (IS_SYMBOL(x)) { |
| 79 while (true) { |
| 80 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
| 81 if (!IS_SPEC_OBJECT(y)) return 1; // not equal |
| 82 y = %ToPrimitive(y, NO_HINT); |
| 83 } |
77 } else if (IS_BOOLEAN(x)) { | 84 } else if (IS_BOOLEAN(x)) { |
78 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 85 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
79 if (IS_NULL_OR_UNDEFINED(y)) return 1; | 86 if (IS_NULL_OR_UNDEFINED(y)) return 1; |
80 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); | 87 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); |
81 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); | 88 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
| 89 if (IS_SYMBOL(y)) return 1; // not equal |
82 // y is object. | 90 // y is object. |
83 x = %ToNumber(x); | 91 x = %ToNumber(x); |
84 y = %ToPrimitive(y, NO_HINT); | 92 y = %ToPrimitive(y, NO_HINT); |
85 } else if (IS_NULL_OR_UNDEFINED(x)) { | 93 } else if (IS_NULL_OR_UNDEFINED(x)) { |
86 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; | 94 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; |
87 } else { | 95 } else { |
88 // x is an object. | 96 // x is an object. |
89 if (IS_SPEC_OBJECT(y)) { | 97 if (IS_SPEC_OBJECT(y)) { |
90 return %_ObjectEquals(x, y) ? 0 : 1; | 98 return %_ObjectEquals(x, y) ? 0 : 1; |
91 } | 99 } |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 ------------------------------------- | 509 ------------------------------------- |
502 */ | 510 */ |
503 | 511 |
504 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 512 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
505 // (1) for number hint, and (2) for string hint. | 513 // (1) for number hint, and (2) for string hint. |
506 function ToPrimitive(x, hint) { | 514 function ToPrimitive(x, hint) { |
507 // Fast case check. | 515 // Fast case check. |
508 if (IS_STRING(x)) return x; | 516 if (IS_STRING(x)) return x; |
509 // Normal behavior. | 517 // Normal behavior. |
510 if (!IS_SPEC_OBJECT(x)) return x; | 518 if (!IS_SPEC_OBJECT(x)) return x; |
| 519 if (IS_SYMBOL_WRAPPER(x)) return %_ValueOf(x); |
511 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 520 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
512 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 521 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
513 } | 522 } |
514 | 523 |
515 | 524 |
516 // ECMA-262, section 9.2, page 30 | 525 // ECMA-262, section 9.2, page 30 |
517 function ToBoolean(x) { | 526 function ToBoolean(x) { |
518 if (IS_BOOLEAN(x)) return x; | 527 if (IS_BOOLEAN(x)) return x; |
519 if (IS_STRING(x)) return x.length != 0; | 528 if (IS_STRING(x)) return x.length != 0; |
520 if (x == null) return false; | 529 if (x == null) return false; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 throw %MakeTypeError('cannot_convert_to_primitive', []); | 676 throw %MakeTypeError('cannot_convert_to_primitive', []); |
668 } | 677 } |
669 | 678 |
670 | 679 |
671 // NOTE: Setting the prototype for Array must take place as early as | 680 // NOTE: Setting the prototype for Array must take place as early as |
672 // possible due to code generation for array literals. When | 681 // possible due to code generation for array literals. When |
673 // generating code for a array literal a boilerplate array is created | 682 // generating code for a array literal a boilerplate array is created |
674 // that is cloned when running the code. It is essential that the | 683 // that is cloned when running the code. It is essential that the |
675 // boilerplate gets the right prototype. | 684 // boilerplate gets the right prototype. |
676 %FunctionSetPrototype($Array, new $Array(0)); | 685 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |