| 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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 525 |
| 526 // ECMA-262, section 9.3, page 31. | 526 // ECMA-262, section 9.3, page 31. |
| 527 function ToNumber(x) { | 527 function ToNumber(x) { |
| 528 if (IS_NUMBER(x)) return x; | 528 if (IS_NUMBER(x)) return x; |
| 529 if (IS_STRING(x)) { | 529 if (IS_STRING(x)) { |
| 530 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 530 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 531 : %StringToNumber(x); | 531 : %StringToNumber(x); |
| 532 } | 532 } |
| 533 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 533 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 534 if (IS_UNDEFINED(x)) return $NaN; | 534 if (IS_UNDEFINED(x)) return $NaN; |
| 535 if (IS_SYMBOL(x)) return $NaN; |
| 535 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 536 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 536 } | 537 } |
| 537 | 538 |
| 538 function NonNumberToNumber(x) { | 539 function NonNumberToNumber(x) { |
| 539 if (IS_STRING(x)) { | 540 if (IS_STRING(x)) { |
| 540 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 541 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
| 541 : %StringToNumber(x); | 542 : %StringToNumber(x); |
| 542 } | 543 } |
| 543 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 544 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
| 544 if (IS_UNDEFINED(x)) return $NaN; | 545 if (IS_UNDEFINED(x)) return $NaN; |
| 546 if (IS_SYMBOL(x)) return $NaN; |
| 545 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 547 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
| 546 } | 548 } |
| 547 | 549 |
| 548 | 550 |
| 549 // ECMA-262, section 9.8, page 35. | 551 // ECMA-262, section 9.8, page 35. |
| 550 function ToString(x) { | 552 function ToString(x) { |
| 551 if (IS_STRING(x)) return x; | 553 if (IS_STRING(x)) return x; |
| 552 if (IS_NUMBER(x)) return %_NumberToString(x); | 554 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 553 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 555 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 554 if (IS_UNDEFINED(x)) return 'undefined'; | 556 if (IS_UNDEFINED(x)) return 'undefined'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 565 | 567 |
| 566 // ES6 symbols | 568 // ES6 symbols |
| 567 function ToName(x) { | 569 function ToName(x) { |
| 568 return IS_SYMBOL(x) ? x : %ToString(x); | 570 return IS_SYMBOL(x) ? x : %ToString(x); |
| 569 } | 571 } |
| 570 | 572 |
| 571 | 573 |
| 572 // ECMA-262, section 9.9, page 36. | 574 // ECMA-262, section 9.9, page 36. |
| 573 function ToObject(x) { | 575 function ToObject(x) { |
| 574 if (IS_STRING(x)) return new $String(x); | 576 if (IS_STRING(x)) return new $String(x); |
| 577 if (IS_SYMBOL(x)) return new $Symbol(x); |
| 575 if (IS_NUMBER(x)) return new $Number(x); | 578 if (IS_NUMBER(x)) return new $Number(x); |
| 576 if (IS_BOOLEAN(x)) return new $Boolean(x); | 579 if (IS_BOOLEAN(x)) return new $Boolean(x); |
| 577 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { | 580 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { |
| 578 throw %MakeTypeError('null_to_object', []); | 581 throw %MakeTypeError('null_to_object', []); |
| 579 } | 582 } |
| 580 return x; | 583 return x; |
| 581 } | 584 } |
| 582 | 585 |
| 583 | 586 |
| 584 // ECMA-262, section 9.4, page 34. | 587 // ECMA-262, section 9.4, page 34. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 throw %MakeTypeError('cannot_convert_to_primitive', []); | 667 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 665 } | 668 } |
| 666 | 669 |
| 667 | 670 |
| 668 // NOTE: Setting the prototype for Array must take place as early as | 671 // NOTE: Setting the prototype for Array must take place as early as |
| 669 // possible due to code generation for array literals. When | 672 // possible due to code generation for array literals. When |
| 670 // generating code for a array literal a boilerplate array is created | 673 // generating code for a array literal a boilerplate array is created |
| 671 // that is cloned when running the code. It is essential that the | 674 // that is cloned when running the code. It is essential that the |
| 672 // boilerplate gets the right prototype. | 675 // boilerplate gets the right prototype. |
| 673 %FunctionSetPrototype($Array, new $Array(0)); | 676 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |