| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 function IsPrimitive(x) { | 587 function IsPrimitive(x) { |
| 588 // Even though the type of null is "object", null is still | 588 // Even though the type of null is "object", null is still |
| 589 // considered a primitive value. IS_SPEC_OBJECT handles this correctly | 589 // considered a primitive value. IS_SPEC_OBJECT handles this correctly |
| 590 // (i.e., it will return false if x is null). | 590 // (i.e., it will return false if x is null). |
| 591 return !IS_SPEC_OBJECT(x); | 591 return !IS_SPEC_OBJECT(x); |
| 592 } | 592 } |
| 593 | 593 |
| 594 | 594 |
| 595 // ECMA-262, section 8.6.2.6, page 28. | 595 // ECMA-262, section 8.6.2.6, page 28. |
| 596 function DefaultNumber(x) { | 596 function DefaultNumber(x) { |
| 597 if (IS_FUNCTION(x.valueOf)) { | 597 var valueOf = x.valueOf; |
| 598 var v = x.valueOf(); | 598 if (IS_FUNCTION(valueOf)) { |
| 599 var v = %_CallFunction(x, valueOf); |
| 599 if (%IsPrimitive(v)) return v; | 600 if (%IsPrimitive(v)) return v; |
| 600 } | 601 } |
| 601 | 602 |
| 602 if (IS_FUNCTION(x.toString)) { | 603 var toString = x.toString; |
| 603 var s = x.toString(); | 604 if (IS_FUNCTION(toString)) { |
| 605 var s = %_CallFunction(x, toString); |
| 604 if (%IsPrimitive(s)) return s; | 606 if (%IsPrimitive(s)) return s; |
| 605 } | 607 } |
| 606 | 608 |
| 607 throw %MakeTypeError('cannot_convert_to_primitive', []); | 609 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 608 } | 610 } |
| 609 | 611 |
| 610 | 612 |
| 611 // ECMA-262, section 8.6.2.6, page 28. | 613 // ECMA-262, section 8.6.2.6, page 28. |
| 612 function DefaultString(x) { | 614 function DefaultString(x) { |
| 613 if (IS_FUNCTION(x.toString)) { | 615 var toString = x.toString; |
| 614 var s = x.toString(); | 616 if (IS_FUNCTION(toString)) { |
| 617 var s = %_CallFunction(x, toString); |
| 615 if (%IsPrimitive(s)) return s; | 618 if (%IsPrimitive(s)) return s; |
| 616 } | 619 } |
| 617 | 620 |
| 618 if (IS_FUNCTION(x.valueOf)) { | 621 var valueOf = x.valueOf; |
| 619 var v = x.valueOf(); | 622 if (IS_FUNCTION(valueOf)) { |
| 623 var v = %_CallFunction(x, valueOf); |
| 620 if (%IsPrimitive(v)) return v; | 624 if (%IsPrimitive(v)) return v; |
| 621 } | 625 } |
| 622 | 626 |
| 623 throw %MakeTypeError('cannot_convert_to_primitive', []); | 627 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 624 } | 628 } |
| 625 | 629 |
| 626 | 630 |
| 627 // NOTE: Setting the prototype for Array must take place as early as | 631 // NOTE: Setting the prototype for Array must take place as early as |
| 628 // possible due to code generation for array literals. When | 632 // possible due to code generation for array literals. When |
| 629 // generating code for a array literal a boilerplate array is created | 633 // generating code for a array literal a boilerplate array is created |
| 630 // that is cloned when running the code. It is essiential that the | 634 // that is cloned when running the code. It is essiential that the |
| 631 // boilerplate gets the right prototype. | 635 // boilerplate gets the right prototype. |
| 632 %FunctionSetPrototype($Array, new $Array(0)); | 636 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |