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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (%_ArgumentsLength() === 0) return 0; | 157 if (%_ArgumentsLength() === 0) return 0; |
158 | 158 |
159 var this_str = TO_STRING_INLINE(this); | 159 var this_str = TO_STRING_INLINE(this); |
160 var other_str = TO_STRING_INLINE(other); | 160 var other_str = TO_STRING_INLINE(other); |
161 return %StringLocaleCompare(this_str, other_str); | 161 return %StringLocaleCompare(this_str, other_str); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 // ECMA-262 section 15.5.4.10 | 165 // ECMA-262 section 15.5.4.10 |
166 function StringMatch(regexp) { | 166 function StringMatch(regexp) { |
167 if (!IS_REGEXP(regexp)) regexp = new ORIGINAL_REGEXP(regexp); | 167 if (!IS_REGEXP(regexp)) regexp = new $RegExp(regexp); |
168 var subject = TO_STRING_INLINE(this); | 168 var subject = TO_STRING_INLINE(this); |
169 | 169 |
170 if (!regexp.global) return regexp.exec(subject); | 170 if (!regexp.global) return regexp.exec(subject); |
171 | 171 |
172 var cache = regExpCache; | 172 var cache = regExpCache; |
173 | 173 |
174 if (%_ObjectEquals(cache.type, 'match') && | 174 if (%_ObjectEquals(cache.type, 'match') && |
175 %_ObjectEquals(cache.regExp, regexp) && | 175 %_ObjectEquals(cache.regExp, regexp) && |
176 %_ObjectEquals(cache.subject, subject)) { | 176 %_ObjectEquals(cache.subject, subject)) { |
177 var last = cache.answer; | 177 var last = cache.answer; |
178 if (last == null) { | 178 if (last == null) { |
179 return last; | 179 return last; |
180 } else { | 180 } else { |
181 return CloneRegexpAnswer(last); | 181 return CloneRegexpAnswer(last); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); | 185 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); |
186 // lastMatchInfo is defined in regexp-delay.js. | 186 // lastMatchInfo is defined in regexp.js. |
187 var result = %StringMatch(subject, regexp, lastMatchInfo); | 187 var result = %StringMatch(subject, regexp, lastMatchInfo); |
188 cache.type = 'match'; | 188 cache.type = 'match'; |
189 cache.regExp = regexp; | 189 cache.regExp = regexp; |
190 cache.subject = subject; | 190 cache.subject = subject; |
191 cache.answer = result; | 191 cache.answer = result; |
192 if (result == null) { | 192 if (result == null) { |
193 return result; | 193 return result; |
194 } else { | 194 } else { |
195 return CloneRegexpAnswer(result); | 195 return CloneRegexpAnswer(result); |
196 } | 196 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 parameters[j] = CaptureString(subject, matchInfo, j); | 516 parameters[j] = CaptureString(subject, matchInfo, j); |
517 } | 517 } |
518 parameters[j] = index; | 518 parameters[j] = index; |
519 parameters[j + 1] = subject; | 519 parameters[j + 1] = subject; |
520 return replace.apply(null, parameters); | 520 return replace.apply(null, parameters); |
521 } | 521 } |
522 | 522 |
523 | 523 |
524 // ECMA-262 section 15.5.4.12 | 524 // ECMA-262 section 15.5.4.12 |
525 function StringSearch(re) { | 525 function StringSearch(re) { |
526 var regexp = new ORIGINAL_REGEXP(re); | 526 var regexp = new $RegExp(re); |
527 var s = TO_STRING_INLINE(this); | 527 var s = TO_STRING_INLINE(this); |
528 var last_idx = regexp.lastIndex; // keep old lastIndex | 528 var last_idx = regexp.lastIndex; // keep old lastIndex |
529 regexp.lastIndex = 0; // ignore re.global property | 529 regexp.lastIndex = 0; // ignore re.global property |
530 var result = regexp.exec(s); | 530 var result = regexp.exec(s); |
531 regexp.lastIndex = last_idx; // restore lastIndex | 531 regexp.lastIndex = last_idx; // restore lastIndex |
532 if (result == null) | 532 if (result == null) |
533 return -1; | 533 return -1; |
534 else | 534 else |
535 return result.index; | 535 return result.index; |
536 } | 536 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 } | 889 } |
890 | 890 |
891 | 891 |
892 function StringSup() { | 892 function StringSup() { |
893 return "<sup>" + this + "</sup>"; | 893 return "<sup>" + this + "</sup>"; |
894 } | 894 } |
895 | 895 |
896 | 896 |
897 // ReplaceResultBuilder support. | 897 // ReplaceResultBuilder support. |
898 function ReplaceResultBuilder(str) { | 898 function ReplaceResultBuilder(str) { |
| 899 this.__proto__ = void 0; |
899 this.elements = new $Array(); | 900 this.elements = new $Array(); |
900 this.special_string = str; | 901 this.special_string = str; |
901 } | 902 } |
902 | 903 |
903 | 904 |
904 ReplaceResultBuilder.prototype.add = function(str) { | 905 ReplaceResultBuilder.prototype.add = function(str) { |
905 str = TO_STRING_INLINE(str); | 906 str = TO_STRING_INLINE(str); |
906 if (str.length > 0) { | 907 if (str.length > 0) { |
907 var elements = this.elements; | 908 var elements = this.elements; |
908 elements[elements.length] = str; | 909 elements[elements.length] = str; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 "small", StringSmall, | 986 "small", StringSmall, |
986 "strike", StringStrike, | 987 "strike", StringStrike, |
987 "sub", StringSub, | 988 "sub", StringSub, |
988 "sup", StringSup, | 989 "sup", StringSup, |
989 "toJSON", StringToJSON | 990 "toJSON", StringToJSON |
990 )); | 991 )); |
991 } | 992 } |
992 | 993 |
993 | 994 |
994 SetupString(); | 995 SetupString(); |
OLD | NEW |