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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 | 520 |
521 // ECMA-262, section 9.3, page 31. | 521 // ECMA-262, section 9.3, page 31. |
522 function ToNumber(x) { | 522 function ToNumber(x) { |
523 if (IS_NUMBER(x)) return x; | 523 if (IS_NUMBER(x)) return x; |
524 if (IS_STRING(x)) { | 524 if (IS_STRING(x)) { |
525 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 525 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
526 : %StringToNumber(x); | 526 : %StringToNumber(x); |
527 } | 527 } |
528 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 528 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
529 if (IS_UNDEFINED(x)) return $NaN; | 529 if (IS_UNDEFINED(x)) return NAN; |
530 if (IS_SYMBOL(x)) return $NaN; | 530 if (IS_SYMBOL(x)) return NAN; |
531 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 531 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
532 } | 532 } |
533 | 533 |
534 function NonNumberToNumber(x) { | 534 function NonNumberToNumber(x) { |
535 if (IS_STRING(x)) { | 535 if (IS_STRING(x)) { |
536 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) | 536 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) |
537 : %StringToNumber(x); | 537 : %StringToNumber(x); |
538 } | 538 } |
539 if (IS_BOOLEAN(x)) return x ? 1 : 0; | 539 if (IS_BOOLEAN(x)) return x ? 1 : 0; |
540 if (IS_UNDEFINED(x)) return $NaN; | 540 if (IS_UNDEFINED(x)) return NAN; |
541 if (IS_SYMBOL(x)) return $NaN; | 541 if (IS_SYMBOL(x)) return NAN; |
542 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 542 return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); |
543 } | 543 } |
544 | 544 |
545 | 545 |
546 // ECMA-262, section 9.8, page 35. | 546 // ECMA-262, section 9.8, page 35. |
547 function ToString(x) { | 547 function ToString(x) { |
548 if (IS_STRING(x)) return x; | 548 if (IS_STRING(x)) return x; |
549 if (IS_NUMBER(x)) return %_NumberToString(x); | 549 if (IS_NUMBER(x)) return %_NumberToString(x); |
550 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 550 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
551 if (IS_UNDEFINED(x)) return 'undefined'; | 551 if (IS_UNDEFINED(x)) return 'undefined'; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 return i; | 667 return i; |
668 } | 668 } |
669 | 669 |
670 | 670 |
671 // 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 |
672 // possible due to code generation for array literals. When | 672 // possible due to code generation for array literals. When |
673 // generating code for a array literal a boilerplate array is created | 673 // generating code for a array literal a boilerplate array is created |
674 // 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 |
675 // boilerplate gets the right prototype. | 675 // boilerplate gets the right prototype. |
676 %FunctionSetPrototype($Array, new $Array(0)); | 676 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |