| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // ECMA-262, section 15.5.4.4 | 63 // ECMA-262, section 15.5.4.4 |
| 64 function StringCharAt(pos) { | 64 function StringCharAt(pos) { |
| 65 var char_code = %_FastCharCodeAt(this, pos); | 65 var char_code = %_FastCharCodeAt(this, pos); |
| 66 if (!%_IsSmi(char_code)) { | 66 if (!%_IsSmi(char_code)) { |
| 67 var subject = TO_STRING_INLINE(this); | 67 var subject = TO_STRING_INLINE(this); |
| 68 var index = TO_INTEGER(pos); | 68 var index = TO_INTEGER(pos); |
| 69 if (index >= subject.length || index < 0) return ""; | 69 if (index >= subject.length || index < 0) return ""; |
| 70 char_code = %StringCharCodeAt(subject, index); | 70 char_code = %StringCharCodeAt(subject, index); |
| 71 } | 71 } |
| 72 return %CharFromCode(char_code); | 72 return %_CharFromCode(char_code); |
| 73 } | 73 } |
| 74 | 74 |
| 75 | 75 |
| 76 // ECMA-262 section 15.5.4.5 | 76 // ECMA-262 section 15.5.4.5 |
| 77 function StringCharCodeAt(pos) { | 77 function StringCharCodeAt(pos) { |
| 78 var fast_answer = %_FastCharCodeAt(this, pos); | 78 var fast_answer = %_FastCharCodeAt(this, pos); |
| 79 if (%_IsSmi(fast_answer)) { | 79 if (%_IsSmi(fast_answer)) { |
| 80 return fast_answer; | 80 return fast_answer; |
| 81 } | 81 } |
| 82 var subject = TO_STRING_INLINE(this); | 82 var subject = TO_STRING_INLINE(this); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // SubString is an internal function that returns the sub string of 'string'. | 177 // SubString is an internal function that returns the sub string of 'string'. |
| 178 // If resulting string is of length 1, we use the one character cache | 178 // If resulting string is of length 1, we use the one character cache |
| 179 // otherwise we call the runtime system. | 179 // otherwise we call the runtime system. |
| 180 function SubString(string, start, end) { | 180 function SubString(string, start, end) { |
| 181 // Use the one character string cache. | 181 // Use the one character string cache. |
| 182 if (start + 1 == end) { | 182 if (start + 1 == end) { |
| 183 var char_code = %_FastCharCodeAt(string, start); | 183 var char_code = %_FastCharCodeAt(string, start); |
| 184 if (!%_IsSmi(char_code)) { | 184 if (!%_IsSmi(char_code)) { |
| 185 char_code = %StringCharCodeAt(string, start); | 185 char_code = %StringCharCodeAt(string, start); |
| 186 } | 186 } |
| 187 return %CharFromCode(char_code); | 187 return %_CharFromCode(char_code); |
| 188 } | 188 } |
| 189 return %_SubString(string, start, end); | 189 return %_SubString(string, start, end); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 |
| 193 // This has the same size as the lastMatchInfo array, and can be used for | 193 // This has the same size as the lastMatchInfo array, and can be used for |
| 194 // functions that expect that structure to be returned. It is used when the | 194 // functions that expect that structure to be returned. It is used when the |
| 195 // needle is a string rather than a regexp. In this case we can't update | 195 // needle is a string rather than a regexp. In this case we can't update |
| 196 // lastMatchArray without erroneously affecting the properties on the global | 196 // lastMatchArray without erroneously affecting the properties on the global |
| 197 // RegExp object. | 197 // RegExp object. |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 return %StringTrim(TO_STRING_INLINE(this), true, false); | 719 return %StringTrim(TO_STRING_INLINE(this), true, false); |
| 720 } | 720 } |
| 721 | 721 |
| 722 function StringTrimRight() { | 722 function StringTrimRight() { |
| 723 return %StringTrim(TO_STRING_INLINE(this), false, true); | 723 return %StringTrim(TO_STRING_INLINE(this), false, true); |
| 724 } | 724 } |
| 725 | 725 |
| 726 // ECMA-262, section 15.5.3.2 | 726 // ECMA-262, section 15.5.3.2 |
| 727 function StringFromCharCode(code) { | 727 function StringFromCharCode(code) { |
| 728 var n = %_ArgumentsLength(); | 728 var n = %_ArgumentsLength(); |
| 729 if (n == 1) return %CharFromCode(ToNumber(code) & 0xffff) | 729 if (n == 1) return %_CharFromCode(ToNumber(code) & 0xffff) |
| 730 | 730 |
| 731 // NOTE: This is not super-efficient, but it is necessary because we | 731 // NOTE: This is not super-efficient, but it is necessary because we |
| 732 // want to avoid converting to numbers from within the virtual | 732 // want to avoid converting to numbers from within the virtual |
| 733 // machine. Maybe we can find another way of doing this? | 733 // machine. Maybe we can find another way of doing this? |
| 734 var codes = new $Array(n); | 734 var codes = new $Array(n); |
| 735 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); | 735 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); |
| 736 return %StringFromCharCodeArray(codes); | 736 return %StringFromCharCodeArray(codes); |
| 737 } | 737 } |
| 738 | 738 |
| 739 | 739 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 "small", StringSmall, | 904 "small", StringSmall, |
| 905 "strike", StringStrike, | 905 "strike", StringStrike, |
| 906 "sub", StringSub, | 906 "sub", StringSub, |
| 907 "sup", StringSup, | 907 "sup", StringSup, |
| 908 "toJSON", StringToJSON | 908 "toJSON", StringToJSON |
| 909 )); | 909 )); |
| 910 } | 910 } |
| 911 | 911 |
| 912 | 912 |
| 913 SetupString(); | 913 SetupString(); |
| OLD | NEW |