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