| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 712 } |
| 713 | 713 |
| 714 function StringTrimLeft() { | 714 function StringTrimLeft() { |
| 715 return %StringTrim(TO_STRING_INLINE(this), true, false); | 715 return %StringTrim(TO_STRING_INLINE(this), true, false); |
| 716 } | 716 } |
| 717 | 717 |
| 718 function StringTrimRight() { | 718 function StringTrimRight() { |
| 719 return %StringTrim(TO_STRING_INLINE(this), false, true); | 719 return %StringTrim(TO_STRING_INLINE(this), false, true); |
| 720 } | 720 } |
| 721 | 721 |
| 722 var static_charcode_array = new $Array(4); |
| 723 |
| 722 // ECMA-262, section 15.5.3.2 | 724 // ECMA-262, section 15.5.3.2 |
| 723 function StringFromCharCode(code) { | 725 function StringFromCharCode(code) { |
| 724 var n = %_ArgumentsLength(); | 726 var n = %_ArgumentsLength(); |
| 725 if (n == 1) return %_CharFromCode(ToNumber(code) & 0xffff) | 727 if (n == 1) { |
| 728 if (!%_IsSmi(code)) code = ToNumber(code); |
| 729 return %_CharFromCode(code & 0xffff); |
| 730 } |
| 726 | 731 |
| 727 // NOTE: This is not super-efficient, but it is necessary because we | 732 // NOTE: This is not super-efficient, but it is necessary because we |
| 728 // want to avoid converting to numbers from within the virtual | 733 // want to avoid converting to numbers from within the virtual |
| 729 // machine. Maybe we can find another way of doing this? | 734 // machine. Maybe we can find another way of doing this? |
| 730 var codes = new $Array(n); | 735 var codes = static_charcode_array; |
| 731 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); | 736 for (var i = 0; i < n; i++) { |
| 737 var code = %_Arguments(i); |
| 738 if (!%_IsSmi(code)) code = ToNumber(code); |
| 739 codes[i] = code; |
| 740 } |
| 741 codes.length = n; |
| 732 return %StringFromCharCodeArray(codes); | 742 return %StringFromCharCodeArray(codes); |
| 733 } | 743 } |
| 734 | 744 |
| 735 | 745 |
| 736 // Helper function for very basic XSS protection. | 746 // Helper function for very basic XSS protection. |
| 737 function HtmlEscape(str) { | 747 function HtmlEscape(str) { |
| 738 return TO_STRING_INLINE(str).replace(/</g, "<") | 748 return TO_STRING_INLINE(str).replace(/</g, "<") |
| 739 .replace(/>/g, ">") | 749 .replace(/>/g, ">") |
| 740 .replace(/"/g, """) | 750 .replace(/"/g, """) |
| 741 .replace(/'/g, "'"); | 751 .replace(/'/g, "'"); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 "small", StringSmall, | 910 "small", StringSmall, |
| 901 "strike", StringStrike, | 911 "strike", StringStrike, |
| 902 "sub", StringSub, | 912 "sub", StringSub, |
| 903 "sup", StringSup, | 913 "sup", StringSup, |
| 904 "toJSON", StringToJSON | 914 "toJSON", StringToJSON |
| 905 )); | 915 )); |
| 906 } | 916 } |
| 907 | 917 |
| 908 | 918 |
| 909 SetupString(); | 919 SetupString(); |
| OLD | NEW |