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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return fast_answer; | 80 return fast_answer; |
81 } | 81 } |
82 var subject = ToString(this); | 82 var subject = ToString(this); |
83 var index = TO_INTEGER(pos); | 83 var index = TO_INTEGER(pos); |
84 return %StringCharCodeAt(subject, index); | 84 return %StringCharCodeAt(subject, index); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 // ECMA-262, section 15.5.4.6 | 88 // ECMA-262, section 15.5.4.6 |
89 function StringConcat() { | 89 function StringConcat() { |
90 var len = %_ArgumentsLength() + 1; | 90 var len = %_ArgumentsLength(); |
91 var parts = new $Array(len); | 91 var this_as_string = IS_STRING(this) ? this : ToString(this); |
92 parts[0] = IS_STRING(this) ? this : ToString(this); | 92 if (len === 1) { |
93 for (var i = 1; i < len; i++) { | 93 return this_as_string + %_Arguments(0); |
94 var part = %_Arguments(i - 1); | |
95 parts[i] = IS_STRING(part) ? part : ToString(part); | |
96 } | 94 } |
97 return %StringBuilderConcat(parts, len, ""); | 95 var parts = new $Array(len + 1); |
| 96 parts[0] = this_as_string; |
| 97 for (var i = 0; i < len; i++) { |
| 98 var part = %_Arguments(i); |
| 99 parts[i + 1] = IS_STRING(part) ? part : ToString(part); |
| 100 } |
| 101 return %StringBuilderConcat(parts, len + 1, ""); |
98 } | 102 } |
99 | 103 |
100 // Match ES3 and Safari | 104 // Match ES3 and Safari |
101 %FunctionSetLength(StringConcat, 1); | 105 %FunctionSetLength(StringConcat, 1); |
102 | 106 |
103 | 107 |
104 // ECMA-262 section 15.5.4.7 | 108 // ECMA-262 section 15.5.4.7 |
105 function StringIndexOf(searchString /* position */) { // length == 1 | 109 function StringIndexOf(searchString /* position */) { // length == 1 |
106 var subject_str = ToString(this); | 110 var subject_str = ToString(this); |
107 var pattern_str = ToString(searchString); | 111 var pattern_str = ToString(searchString); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 "small", StringSmall, | 896 "small", StringSmall, |
893 "strike", StringStrike, | 897 "strike", StringStrike, |
894 "sub", StringSub, | 898 "sub", StringSub, |
895 "sup", StringSup, | 899 "sup", StringSup, |
896 "toJSON", StringToJSON | 900 "toJSON", StringToJSON |
897 )); | 901 )); |
898 } | 902 } |
899 | 903 |
900 | 904 |
901 SetupString(); | 905 SetupString(); |
OLD | NEW |