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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); | 74 if (IS_BOOLEAN(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
75 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal | 75 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal |
76 y = %ToPrimitive(y, NO_HINT); | 76 y = %ToPrimitive(y, NO_HINT); |
77 } | 77 } |
78 } else if (IS_SYMBOL(x)) { | 78 } else if (IS_SYMBOL(x)) { |
79 while (true) { | 79 while (true) { |
80 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 80 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
81 if (!IS_SPEC_OBJECT(y)) return 1; // not equal | 81 if (!IS_SPEC_OBJECT(y)) return 1; // not equal |
82 y = %ToPrimitive(y, NO_HINT); | 82 y = %ToPrimitive(y, NO_HINT); |
83 } | 83 } |
| 84 } else if (IS_SYMBOL_WRAPPER(x) && IS_SYMBOL_WRAPPER(y)) { |
| 85 return %_ObjectEquals(x, y) ? 0 : 1; |
84 } else if (IS_BOOLEAN(x)) { | 86 } else if (IS_BOOLEAN(x)) { |
85 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; | 87 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; |
86 if (IS_NULL_OR_UNDEFINED(y)) return 1; | 88 if (IS_NULL_OR_UNDEFINED(y)) return 1; |
87 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); | 89 if (IS_NUMBER(y)) return %NumberEquals(%ToNumber(x), y); |
88 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); | 90 if (IS_STRING(y)) return %NumberEquals(%ToNumber(x), %ToNumber(y)); |
89 if (IS_SYMBOL(y)) return 1; // not equal | 91 if (IS_SYMBOL(y)) return 1; // not equal |
90 // y is object. | 92 // y is object. |
91 x = %ToNumber(x); | 93 x = %ToNumber(x); |
92 y = %ToPrimitive(y, NO_HINT); | 94 y = %ToPrimitive(y, NO_HINT); |
93 } else if (IS_NULL_OR_UNDEFINED(x)) { | 95 } else if (IS_NULL_OR_UNDEFINED(x)) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 ------------------------------------- | 497 ------------------------------------- |
496 */ | 498 */ |
497 | 499 |
498 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 500 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
499 // (1) for number hint, and (2) for string hint. | 501 // (1) for number hint, and (2) for string hint. |
500 function ToPrimitive(x, hint) { | 502 function ToPrimitive(x, hint) { |
501 // Fast case check. | 503 // Fast case check. |
502 if (IS_STRING(x)) return x; | 504 if (IS_STRING(x)) return x; |
503 // Normal behavior. | 505 // Normal behavior. |
504 if (!IS_SPEC_OBJECT(x)) return x; | 506 if (!IS_SPEC_OBJECT(x)) return x; |
505 if (IS_SYMBOL_WRAPPER(x)) return %_ValueOf(x); | 507 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError('symbol_to_primitive', []); |
506 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 508 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
507 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 509 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
508 } | 510 } |
509 | 511 |
510 | 512 |
511 // ECMA-262, section 9.2, page 30 | 513 // ECMA-262, section 9.2, page 30 |
512 function ToBoolean(x) { | 514 function ToBoolean(x) { |
513 if (IS_BOOLEAN(x)) return x; | 515 if (IS_BOOLEAN(x)) return x; |
514 if (IS_STRING(x)) return x.length != 0; | 516 if (IS_STRING(x)) return x.length != 0; |
515 if (x == null) return false; | 517 if (x == null) return false; |
(...skipping 26 matching lines...) Expand all Loading... |
542 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 544 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
543 } | 545 } |
544 | 546 |
545 | 547 |
546 // ECMA-262, section 9.8, page 35. | 548 // ECMA-262, section 9.8, page 35. |
547 function ToString(x) { | 549 function ToString(x) { |
548 if (IS_STRING(x)) return x; | 550 if (IS_STRING(x)) return x; |
549 if (IS_NUMBER(x)) return %_NumberToString(x); | 551 if (IS_NUMBER(x)) return %_NumberToString(x); |
550 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 552 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
551 if (IS_UNDEFINED(x)) return 'undefined'; | 553 if (IS_UNDEFINED(x)) return 'undefined'; |
| 554 if (IS_SYMBOL(x)) throw %MakeTypeError('symbol_to_string', []); |
552 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 555 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
553 } | 556 } |
554 | 557 |
555 function NonStringToString(x) { | 558 function NonStringToString(x) { |
556 if (IS_NUMBER(x)) return %_NumberToString(x); | 559 if (IS_NUMBER(x)) return %_NumberToString(x); |
557 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 560 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
558 if (IS_UNDEFINED(x)) return 'undefined'; | 561 if (IS_UNDEFINED(x)) return 'undefined'; |
559 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 562 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); |
560 } | 563 } |
561 | 564 |
562 | 565 |
563 // ES6 symbols | 566 // ES6 symbols |
564 function ToName(x) { | 567 function ToName(x) { |
565 return IS_SYMBOL(x) ? x : %ToString(x); | 568 return IS_SYMBOL(x) ? x : %ToString(x); |
566 } | 569 } |
567 | 570 |
568 | 571 |
569 // ECMA-262, section 9.9, page 36. | 572 // ECMA-262, section 9.9, page 36. |
570 function ToObject(x) { | 573 function ToObject(x) { |
571 if (IS_STRING(x)) return new $String(x); | 574 if (IS_STRING(x)) return new $String(x); |
572 if (IS_SYMBOL(x)) return new $Symbol(x); | 575 if (IS_SYMBOL(x)) return new $SymbolWrapper(x); |
573 if (IS_NUMBER(x)) return new $Number(x); | 576 if (IS_NUMBER(x)) return new $Number(x); |
574 if (IS_BOOLEAN(x)) return new $Boolean(x); | 577 if (IS_BOOLEAN(x)) return new $Boolean(x); |
575 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 578 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
576 throw %MakeTypeError('undefined_or_null_to_object', []); | 579 throw %MakeTypeError('undefined_or_null_to_object', []); |
577 } | 580 } |
578 return x; | 581 return x; |
579 } | 582 } |
580 | 583 |
581 | 584 |
582 // ECMA-262, section 9.4, page 34. | 585 // ECMA-262, section 9.4, page 34. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 return i; | 672 return i; |
670 } | 673 } |
671 | 674 |
672 | 675 |
673 // NOTE: Setting the prototype for Array must take place as early as | 676 // NOTE: Setting the prototype for Array must take place as early as |
674 // possible due to code generation for array literals. When | 677 // possible due to code generation for array literals. When |
675 // generating code for a array literal a boilerplate array is created | 678 // generating code for a array literal a boilerplate array is created |
676 // that is cloned when running the code. It is essential that the | 679 // that is cloned when running the code. It is essential that the |
677 // boilerplate gets the right prototype. | 680 // boilerplate gets the right prototype. |
678 %FunctionSetPrototype($Array, new $Array(0)); | 681 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |