| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 var start = %StringIndexOf(subject, search, 0); | 244 var start = %StringIndexOf(subject, search, 0); |
| 245 if (start < 0) return subject; | 245 if (start < 0) return subject; |
| 246 var end = start + search.length; | 246 var end = start + search.length; |
| 247 | 247 |
| 248 var builder = new ReplaceResultBuilder(subject); | 248 var builder = new ReplaceResultBuilder(subject); |
| 249 // prefix | 249 // prefix |
| 250 builder.addSpecialSlice(0, start); | 250 builder.addSpecialSlice(0, start); |
| 251 | 251 |
| 252 // Compute the string to replace with. | 252 // Compute the string to replace with. |
| 253 if (IS_FUNCTION(replace)) { | 253 if (IS_FUNCTION(replace)) { |
| 254 builder.add(%_CallFunction(%GetGlobalReceiver(), | 254 var receiver = |
| 255 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver(); |
| 256 builder.add(%_CallFunction(receiver, |
| 255 search, | 257 search, |
| 256 start, | 258 start, |
| 257 subject, | 259 subject, |
| 258 replace)); | 260 replace)); |
| 259 } else { | 261 } else { |
| 260 reusableMatchInfo[CAPTURE0] = start; | 262 reusableMatchInfo[CAPTURE0] = start; |
| 261 reusableMatchInfo[CAPTURE1] = end; | 263 reusableMatchInfo[CAPTURE1] = end; |
| 262 replace = TO_STRING_INLINE(replace); | 264 replace = TO_STRING_INLINE(replace); |
| 263 ExpandReplacement(replace, subject, reusableMatchInfo, builder); | 265 ExpandReplacement(replace, subject, reusableMatchInfo, builder); |
| 264 } | 266 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (IS_NULL(res)) { | 413 if (IS_NULL(res)) { |
| 412 // No matches at all. | 414 // No matches at all. |
| 413 reusableReplaceArray = resultArray; | 415 reusableReplaceArray = resultArray; |
| 414 return subject; | 416 return subject; |
| 415 } | 417 } |
| 416 var len = res.length; | 418 var len = res.length; |
| 417 var i = 0; | 419 var i = 0; |
| 418 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { | 420 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { |
| 419 var match_start = 0; | 421 var match_start = 0; |
| 420 var override = new InternalArray(null, 0, subject); | 422 var override = new InternalArray(null, 0, subject); |
| 421 var receiver = %GetGlobalReceiver(); | 423 var receiver = |
| 424 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver(); |
| 422 while (i < len) { | 425 while (i < len) { |
| 423 var elem = res[i]; | 426 var elem = res[i]; |
| 424 if (%_IsSmi(elem)) { | 427 if (%_IsSmi(elem)) { |
| 425 if (elem > 0) { | 428 if (elem > 0) { |
| 426 match_start = (elem >> 11) + (elem & 0x7ff); | 429 match_start = (elem >> 11) + (elem & 0x7ff); |
| 427 } else { | 430 } else { |
| 428 match_start = res[++i] - elem; | 431 match_start = res[++i] - elem; |
| 429 } | 432 } |
| 430 } else { | 433 } else { |
| 431 override[0] = elem; | 434 override[0] = elem; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 var endOfMatch = matchInfo[CAPTURE1]; | 471 var endOfMatch = matchInfo[CAPTURE1]; |
| 469 // Compute the parameter list consisting of the match, captures, index, | 472 // Compute the parameter list consisting of the match, captures, index, |
| 470 // and subject for the replace function invocation. | 473 // and subject for the replace function invocation. |
| 471 // The number of captures plus one for the match. | 474 // The number of captures plus one for the match. |
| 472 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; | 475 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; |
| 473 var replacement; | 476 var replacement; |
| 474 if (m == 1) { | 477 if (m == 1) { |
| 475 // No captures, only the match, which is always valid. | 478 // No captures, only the match, which is always valid. |
| 476 var s = SubString(subject, index, endOfMatch); | 479 var s = SubString(subject, index, endOfMatch); |
| 477 // Don't call directly to avoid exposing the built-in global object. | 480 // Don't call directly to avoid exposing the built-in global object. |
| 481 var receiver = |
| 482 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver(); |
| 478 replacement = | 483 replacement = |
| 479 %_CallFunction(%GetGlobalReceiver(), s, index, subject, replace); | 484 %_CallFunction(receiver, s, index, subject, replace); |
| 480 } else { | 485 } else { |
| 481 var parameters = new InternalArray(m + 2); | 486 var parameters = new InternalArray(m + 2); |
| 482 for (var j = 0; j < m; j++) { | 487 for (var j = 0; j < m; j++) { |
| 483 parameters[j] = CaptureString(subject, matchInfo, j); | 488 parameters[j] = CaptureString(subject, matchInfo, j); |
| 484 } | 489 } |
| 485 parameters[j] = index; | 490 parameters[j] = index; |
| 486 parameters[j + 1] = subject; | 491 parameters[j + 1] = subject; |
| 487 | 492 |
| 488 replacement = replace.apply(null, parameters); | 493 replacement = replace.apply(null, parameters); |
| 489 } | 494 } |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 "italics", StringItalics, | 990 "italics", StringItalics, |
| 986 "small", StringSmall, | 991 "small", StringSmall, |
| 987 "strike", StringStrike, | 992 "strike", StringStrike, |
| 988 "sub", StringSub, | 993 "sub", StringSub, |
| 989 "sup", StringSup | 994 "sup", StringSup |
| 990 )); | 995 )); |
| 991 } | 996 } |
| 992 | 997 |
| 993 | 998 |
| 994 SetupString(); | 999 SetupString(); |
| OLD | NEW |