| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 if (%_ArgumentsLength() === 0) { | 523 if (%_ArgumentsLength() === 0) { |
| 524 return [subject]; | 524 return [subject]; |
| 525 } | 525 } |
| 526 | 526 |
| 527 var length = subject.length; | 527 var length = subject.length; |
| 528 if (!IS_REGEXP(separator)) { | 528 if (!IS_REGEXP(separator)) { |
| 529 separator = TO_STRING_INLINE(separator); | 529 separator = TO_STRING_INLINE(separator); |
| 530 var separator_length = separator.length; | 530 var separator_length = separator.length; |
| 531 | 531 |
| 532 // If the separator string is empty then return the elements in the subject. | 532 // If the separator string is empty then return the elements in the subject. |
| 533 if (separator_length === 0) { | 533 if (separator_length === 0) return %StringToArray(subject); |
| 534 var result = $Array(length); | |
| 535 for (var i = 0; i < length; i++) result[i] = subject[i]; | |
| 536 return result; | |
| 537 } | |
| 538 | 534 |
| 539 var result = []; | 535 var result = []; |
| 540 var start_index = 0; | 536 var start_index = 0; |
| 541 var index; | 537 var index; |
| 542 while (true) { | 538 while (true) { |
| 543 if (start_index + separator_length > length || | 539 if (start_index + separator_length > length || |
| 544 (index = %StringIndexOf(subject, separator, start_index)) === -1) { | 540 (index = %StringIndexOf(subject, separator, start_index)) === -1) { |
| 545 result.push(SubString(subject, start_index, length)); | 541 result.push(SubString(subject, start_index, length)); |
| 546 break; | 542 break; |
| 547 } | 543 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 return %StringTrim(TO_STRING_INLINE(this), true, false); | 715 return %StringTrim(TO_STRING_INLINE(this), true, false); |
| 720 } | 716 } |
| 721 | 717 |
| 722 function StringTrimRight() { | 718 function StringTrimRight() { |
| 723 return %StringTrim(TO_STRING_INLINE(this), false, true); | 719 return %StringTrim(TO_STRING_INLINE(this), false, true); |
| 724 } | 720 } |
| 725 | 721 |
| 726 // ECMA-262, section 15.5.3.2 | 722 // ECMA-262, section 15.5.3.2 |
| 727 function StringFromCharCode(code) { | 723 function StringFromCharCode(code) { |
| 728 var n = %_ArgumentsLength(); | 724 var n = %_ArgumentsLength(); |
| 729 if (n == 1) return %CharFromCode(ToNumber(code) & 0xffff) | 725 if (n == 1) return %_CharFromCode(ToNumber(code) & 0xffff) |
| 730 | 726 |
| 731 // NOTE: This is not super-efficient, but it is necessary because we | 727 // NOTE: This is not super-efficient, but it is necessary because we |
| 732 // want to avoid converting to numbers from within the virtual | 728 // want to avoid converting to numbers from within the virtual |
| 733 // machine. Maybe we can find another way of doing this? | 729 // machine. Maybe we can find another way of doing this? |
| 734 var codes = new $Array(n); | 730 var codes = new $Array(n); |
| 735 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); | 731 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); |
| 736 return %StringFromCharCodeArray(codes); | 732 return %StringFromCharCodeArray(codes); |
| 737 } | 733 } |
| 738 | 734 |
| 739 | 735 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 "small", StringSmall, | 900 "small", StringSmall, |
| 905 "strike", StringStrike, | 901 "strike", StringStrike, |
| 906 "sub", StringSub, | 902 "sub", StringSub, |
| 907 "sup", StringSup, | 903 "sup", StringSup, |
| 908 "toJSON", StringToJSON | 904 "toJSON", StringToJSON |
| 909 )); | 905 )); |
| 910 } | 906 } |
| 911 | 907 |
| 912 | 908 |
| 913 SetupString(); | 909 SetupString(); |
| OLD | NEW |