Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: src/runtime.js

Issue 118553003: Upgrade Symbol implementation to match current ES6 behavior. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Remove uninteresting equality test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime.cc ('k') | src/stub-cache.cc » ('j') | src/symbol.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)) {
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
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
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';
558 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); 561 return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x));
559 } 562 }
560 563
561 564
562 // ES6 symbols 565 // ES6 symbols
563 function ToName(x) { 566 function ToName(x) {
564 return IS_SYMBOL(x) ? x : %ToString(x); 567 return IS_SYMBOL(x) ? x : %ToString(x);
565 } 568 }
566 569
567 570
568 // ECMA-262, section 9.9, page 36. 571 // ECMA-262, section 9.9, page 36.
569 function ToObject(x) { 572 function ToObject(x) {
570 if (IS_STRING(x)) return new $String(x); 573 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); 574 if (IS_NUMBER(x)) return new $Number(x);
573 if (IS_BOOLEAN(x)) return new $Boolean(x); 575 if (IS_BOOLEAN(x)) return new $Boolean(x);
576 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x);
574 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { 577 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) {
575 throw %MakeTypeError('undefined_or_null_to_object', []); 578 throw %MakeTypeError('undefined_or_null_to_object', []);
576 } 579 }
577 return x; 580 return x;
578 } 581 }
579 582
580 583
581 // ECMA-262, section 9.4, page 34. 584 // ECMA-262, section 9.4, page 34.
582 function ToInteger(x) { 585 function ToInteger(x) {
583 if (%_IsSmi(x)) return x; 586 if (%_IsSmi(x)) return x;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 return i; 671 return i;
669 } 672 }
670 673
671 674
672 // NOTE: Setting the prototype for Array must take place as early as 675 // NOTE: Setting the prototype for Array must take place as early as
673 // possible due to code generation for array literals. When 676 // possible due to code generation for array literals. When
674 // generating code for a array literal a boilerplate array is created 677 // generating code for a array literal a boilerplate array is created
675 // that is cloned when running the code. It is essential that the 678 // that is cloned when running the code. It is essential that the
676 // boilerplate gets the right prototype. 679 // boilerplate gets the right prototype.
677 %FunctionSetPrototype($Array, new $Array(0)); 680 %FunctionSetPrototype($Array, new $Array(0));
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/stub-cache.cc » ('j') | src/symbol.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698