| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // ECMA-262 section 15.5.4.10 | 170 // ECMA-262 section 15.5.4.10 |
| 171 function StringMatch(regexp) { | 171 function StringMatch(regexp) { |
| 172 var subject = TO_STRING_INLINE(this); | 172 var subject = TO_STRING_INLINE(this); |
| 173 if (IS_REGEXP(regexp)) { | 173 if (IS_REGEXP(regexp)) { |
| 174 if (!regexp.global) return regexp.exec(subject); | 174 if (!regexp.global) return regexp.exec(subject); |
| 175 | 175 |
| 176 var cache = regExpCache; | 176 var cache = regExpCache; |
| 177 var saveAnswer = false; | 177 var saveAnswer = false; |
| 178 | 178 |
| 179 if (%_ObjectEquals(cache.type, 'match') && | 179 if (%_ObjectEquals(cache.type, 'match') && |
| 180 %_ObjectEquals(cache.regExp, regexp) && | 180 %_IsRegExpEquivalent(cache.regExp, regexp) && |
| 181 %_ObjectEquals(cache.subject, subject)) { | 181 %_ObjectEquals(cache.subject, subject)) { |
| 182 if (cache.answerSaved) { | 182 if (cache.answerSaved) { |
| 183 return CloneDenseArray(cache.answer); | 183 return CloneDenseArray(cache.answer); |
| 184 } else { | 184 } else { |
| 185 saveAnswer = true; | 185 saveAnswer = true; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); | 188 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); |
| 189 // lastMatchInfo is defined in regexp.js. | 189 // lastMatchInfo is defined in regexp.js. |
| 190 var result = %StringMatch(subject, regexp, lastMatchInfo); | 190 var result = %StringMatch(subject, regexp, lastMatchInfo); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // suffix | 267 // suffix |
| 268 builder.addSpecialSlice(end, subject.length); | 268 builder.addSpecialSlice(end, subject.length); |
| 269 | 269 |
| 270 return builder.generate(); | 270 return builder.generate(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 // Helper function for regular expressions in String.prototype.replace. | 274 // Helper function for regular expressions in String.prototype.replace. |
| 275 function StringReplaceRegExp(subject, regexp, replace) { | 275 function StringReplaceRegExp(subject, regexp, replace) { |
| 276 var cache = regExpCache; | 276 var cache = regExpCache; |
| 277 if (%_ObjectEquals(cache.regExp, regexp) && | 277 if (%_ObjectEquals(cache.type, 'replace') && |
| 278 %_ObjectEquals(cache.type, 'replace') && | 278 %_IsRegExpEquivalent(cache.regExp, regexp) && |
| 279 %_ObjectEquals(cache.replaceString, replace) && | 279 %_ObjectEquals(cache.replaceString, replace) && |
| 280 %_ObjectEquals(cache.subject, subject)) { | 280 %_ObjectEquals(cache.subject, subject)) { |
| 281 return cache.answer; | 281 return cache.answer; |
| 282 } | 282 } |
| 283 replace = TO_STRING_INLINE(replace); | 283 replace = TO_STRING_INLINE(replace); |
| 284 var answer = %StringReplaceRegExpWithString(subject, | 284 var answer = %StringReplaceRegExpWithString(subject, |
| 285 regexp, | 285 regexp, |
| 286 replace, | 286 replace, |
| 287 lastMatchInfo); | 287 lastMatchInfo); |
| 288 cache.subject = subject; | 288 cache.subject = subject; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 602 |
| 603 var result = %StringSplit(subject, separator, limit); | 603 var result = %StringSplit(subject, separator, limit); |
| 604 | 604 |
| 605 return result; | 605 return result; |
| 606 } | 606 } |
| 607 | 607 |
| 608 var cache = regExpCache; | 608 var cache = regExpCache; |
| 609 var saveAnswer = false; | 609 var saveAnswer = false; |
| 610 | 610 |
| 611 if (%_ObjectEquals(cache.type, 'split') && | 611 if (%_ObjectEquals(cache.type, 'split') && |
| 612 %_ObjectEquals(cache.regExp, separator) && | 612 %_IsRegExpEquivalent(cache.regExp, separator) && |
| 613 %_ObjectEquals(cache.subject, subject)) { | 613 %_ObjectEquals(cache.subject, subject) && |
| 614 %_ObjectEquals(cache.lastIndex, limit)) { |
| 614 if (cache.answerSaved) { | 615 if (cache.answerSaved) { |
| 615 return CloneDenseArray(cache.answer); | 616 return CloneDenseArray(cache.answer); |
| 616 } else { | 617 } else { |
| 617 saveAnswer = true; | 618 saveAnswer = true; |
| 618 } | 619 } |
| 619 } | 620 } |
| 620 | 621 |
| 621 cache.type = 'split'; | 622 cache.type = 'split'; |
| 622 cache.regExp = separator; | 623 cache.regExp = separator; |
| 623 cache.subject = subject; | 624 cache.subject = subject; |
| 625 // Reuse lastIndex field for split limit when type is "split". |
| 626 cache.lastIndex = limit; |
| 624 | 627 |
| 625 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); | 628 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); |
| 626 | 629 |
| 627 if (length === 0) { | 630 if (length === 0) { |
| 628 cache.answerSaved = true; | 631 cache.answerSaved = true; |
| 629 if (splitMatch(separator, subject, 0, 0) != null) { | 632 if (splitMatch(separator, subject, 0, 0) != null) { |
| 630 cache.answer = []; | 633 cache.answer = []; |
| 631 return []; | 634 return []; |
| 632 } | 635 } |
| 633 cache.answer = [subject]; | 636 cache.answer = [subject]; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 "small", StringSmall, | 1000 "small", StringSmall, |
| 998 "strike", StringStrike, | 1001 "strike", StringStrike, |
| 999 "sub", StringSub, | 1002 "sub", StringSub, |
| 1000 "sup", StringSup, | 1003 "sup", StringSup, |
| 1001 "toJSON", StringToJSON | 1004 "toJSON", StringToJSON |
| 1002 )); | 1005 )); |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 | 1008 |
| 1006 SetupString(); | 1009 SetupString(); |
| OLD | NEW |