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

Side by Side Diff: src/runtime.js

Issue 389263003: Make ToPrimitive throw on symbol wrappers (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/symbols.js » ('j') | no next file with comments »
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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this' and 9 // ALL CAPS. The compiled code passes the first argument in 'this' and
10 // it does not push the function onto the stack. This means that you 10 // it does not push the function onto the stack. This means that you
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 function IsPrimitive(x) { 600 function IsPrimitive(x) {
601 // Even though the type of null is "object", null is still 601 // Even though the type of null is "object", null is still
602 // considered a primitive value. IS_SPEC_OBJECT handles this correctly 602 // considered a primitive value. IS_SPEC_OBJECT handles this correctly
603 // (i.e., it will return false if x is null). 603 // (i.e., it will return false if x is null).
604 return !IS_SPEC_OBJECT(x); 604 return !IS_SPEC_OBJECT(x);
605 } 605 }
606 606
607 607
608 // ECMA-262, section 8.6.2.6, page 28. 608 // ECMA-262, section 8.6.2.6, page 28.
609 function DefaultNumber(x) { 609 function DefaultNumber(x) {
610 var valueOf = x.valueOf; 610 if (!IS_SYMBOL_WRAPPER(x)) {
611 if (IS_SPEC_FUNCTION(valueOf)) { 611 var valueOf = x.valueOf;
612 var v = %_CallFunction(x, valueOf); 612 if (IS_SPEC_FUNCTION(valueOf)) {
613 if (%IsPrimitive(v)) return v; 613 var v = %_CallFunction(x, valueOf);
614 if (%IsPrimitive(v)) return v;
615 }
616
617 var toString = x.toString;
618 if (IS_SPEC_FUNCTION(toString)) {
619 var s = %_CallFunction(x, toString);
620 if (%IsPrimitive(s)) return s;
621 }
614 } 622 }
615
616 var toString = x.toString;
617 if (IS_SPEC_FUNCTION(toString)) {
618 var s = %_CallFunction(x, toString);
619 if (%IsPrimitive(s)) return s;
620 }
621
622 throw %MakeTypeError('cannot_convert_to_primitive', []); 623 throw %MakeTypeError('cannot_convert_to_primitive', []);
623 } 624 }
624 625
625 // ECMA-262, section 8.6.2.6, page 28. 626 // ECMA-262, section 8.6.2.6, page 28.
626 function DefaultString(x) { 627 function DefaultString(x) {
627 var toString = x.toString; 628 if (!IS_SYMBOL_WRAPPER(x)) {
628 if (IS_SPEC_FUNCTION(toString)) { 629 var toString = x.toString;
629 var s = %_CallFunction(x, toString); 630 if (IS_SPEC_FUNCTION(toString)) {
630 if (%IsPrimitive(s)) return s; 631 var s = %_CallFunction(x, toString);
632 if (%IsPrimitive(s)) return s;
633 }
634
635 var valueOf = x.valueOf;
636 if (IS_SPEC_FUNCTION(valueOf)) {
637 var v = %_CallFunction(x, valueOf);
638 if (%IsPrimitive(v)) return v;
639 }
631 } 640 }
632
633 var valueOf = x.valueOf;
634 if (IS_SPEC_FUNCTION(valueOf)) {
635 var v = %_CallFunction(x, valueOf);
636 if (%IsPrimitive(v)) return v;
637 }
638
639 throw %MakeTypeError('cannot_convert_to_primitive', []); 641 throw %MakeTypeError('cannot_convert_to_primitive', []);
640 } 642 }
641 643
642 function ToPositiveInteger(x, rangeErrorName) { 644 function ToPositiveInteger(x, rangeErrorName) {
643 var i = TO_INTEGER(x); 645 var i = TO_INTEGER(x);
644 if (i < 0) throw MakeRangeError(rangeErrorName); 646 if (i < 0) throw MakeRangeError(rangeErrorName);
645 return i; 647 return i;
646 } 648 }
647 649
648 650
649 // NOTE: Setting the prototype for Array must take place as early as 651 // NOTE: Setting the prototype for Array must take place as early as
650 // possible due to code generation for array literals. When 652 // possible due to code generation for array literals. When
651 // generating code for a array literal a boilerplate array is created 653 // generating code for a array literal a boilerplate array is created
652 // that is cloned when running the code. It is essential that the 654 // that is cloned when running the code. It is essential that the
653 // boilerplate gets the right prototype. 655 // boilerplate gets the right prototype.
654 %FunctionSetPrototype($Array, new $Array(0)); 656 %FunctionSetPrototype($Array, new $Array(0));
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698