| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 var matchInfo = DoRegExpExec(regexp, subject, 0); | 373 var matchInfo = DoRegExpExec(regexp, subject, 0); |
| 374 if (IS_NULL(matchInfo)) return subject; | 374 if (IS_NULL(matchInfo)) return subject; |
| 375 | 375 |
| 376 var result = new ReplaceResultBuilder(subject); | 376 var result = new ReplaceResultBuilder(subject); |
| 377 // There's at least one match. If the regexp is global, we have to loop | 377 // There's at least one match. If the regexp is global, we have to loop |
| 378 // over all matches. The loop is not in C++ code here like the one in | 378 // over all matches. The loop is not in C++ code here like the one in |
| 379 // RegExp.prototype.exec, because of the interleaved function application. | 379 // RegExp.prototype.exec, because of the interleaved function application. |
| 380 // Unfortunately, that means this code is nearly duplicated, here and in | 380 // Unfortunately, that means this code is nearly duplicated, here and in |
| 381 // jsregexp.cc. | 381 // jsregexp.cc. |
| 382 if (regexp.global) { | 382 if (regexp.global) { |
| 383 var numberOfCaptures = NUMBER_OF_CAPTURES(matchInfo) >> 1; |
| 383 var previous = 0; | 384 var previous = 0; |
| 384 do { | 385 do { |
| 385 result.addSpecialSlice(previous, matchInfo[CAPTURE0]); | |
| 386 var startOfMatch = matchInfo[CAPTURE0]; | 386 var startOfMatch = matchInfo[CAPTURE0]; |
| 387 result.addSpecialSlice(previous, startOfMatch); |
| 387 previous = matchInfo[CAPTURE1]; | 388 previous = matchInfo[CAPTURE1]; |
| 388 result.add(ApplyReplacementFunction(replace, matchInfo, subject)); | 389 if (numberOfCaptures == 1) { |
| 390 var match = SubString(subject, startOfMatch, previous); |
| 391 // Don't call directly to avoid exposing the built-in global object. |
| 392 result.add(replace.call(null, match, startOfMatch, subject)); |
| 393 } else { |
| 394 result.add(ApplyReplacementFunction(replace, matchInfo, subject)); |
| 395 } |
| 389 // Can't use matchInfo any more from here, since the function could | 396 // Can't use matchInfo any more from here, since the function could |
| 390 // overwrite it. | 397 // overwrite it. |
| 391 // Continue with the next match. | 398 // Continue with the next match. |
| 392 // Increment previous if we matched an empty string, as per ECMA-262 | 399 // Increment previous if we matched an empty string, as per ECMA-262 |
| 393 // 15.5.4.10. | 400 // 15.5.4.10. |
| 394 if (previous == startOfMatch) { | 401 if (previous == startOfMatch) { |
| 395 // Add the skipped character to the output, if any. | 402 // Add the skipped character to the output, if any. |
| 396 if (previous < subject.length) { | 403 if (previous < subject.length) { |
| 397 result.addSpecialSlice(previous, previous + 1); | 404 result.addSpecialSlice(previous, previous + 1); |
| 398 } | 405 } |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 "small", StringSmall, | 892 "small", StringSmall, |
| 886 "strike", StringStrike, | 893 "strike", StringStrike, |
| 887 "sub", StringSub, | 894 "sub", StringSub, |
| 888 "sup", StringSup, | 895 "sup", StringSup, |
| 889 "toJSON", StringToJSON | 896 "toJSON", StringToJSON |
| 890 )); | 897 )); |
| 891 } | 898 } |
| 892 | 899 |
| 893 | 900 |
| 894 SetupString(); | 901 SetupString(); |
| OLD | NEW |