OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (start < 0) return subject; | 259 if (start < 0) return subject; |
260 var end = start + search.length; | 260 var end = start + search.length; |
261 | 261 |
262 var builder = new ReplaceResultBuilder(subject); | 262 var builder = new ReplaceResultBuilder(subject); |
263 // prefix | 263 // prefix |
264 builder.addSpecialSlice(0, start); | 264 builder.addSpecialSlice(0, start); |
265 | 265 |
266 // Compute the string to replace with. | 266 // Compute the string to replace with. |
267 if (IS_SPEC_FUNCTION(replace)) { | 267 if (IS_SPEC_FUNCTION(replace)) { |
268 var receiver = %GetDefaultReceiver(replace); | 268 var receiver = %GetDefaultReceiver(replace); |
269 // Prepare break slots for debugger step in. | |
270 if (%DebugCallbackSupportsStepping(replace)) { | |
271 %DebugPrepareStepInIfStepping(replace); | |
272 } | |
273 builder.add(%_CallFunction(receiver, | 269 builder.add(%_CallFunction(receiver, |
274 search, | 270 search, |
275 start, | 271 start, |
276 subject, | 272 subject, |
277 replace)); | 273 replace)); |
278 } else { | 274 } else { |
279 reusableMatchInfo[CAPTURE0] = start; | 275 reusableMatchInfo[CAPTURE0] = start; |
280 reusableMatchInfo[CAPTURE1] = end; | 276 reusableMatchInfo[CAPTURE1] = end; |
281 replace = TO_STRING_INLINE(replace); | 277 replace = TO_STRING_INLINE(replace); |
282 ExpandReplacement(replace, subject, reusableMatchInfo, builder); | 278 ExpandReplacement(replace, subject, reusableMatchInfo, builder); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 // No matches at all. | 427 // No matches at all. |
432 reusableReplaceArray = resultArray; | 428 reusableReplaceArray = resultArray; |
433 return subject; | 429 return subject; |
434 } | 430 } |
435 var len = res.length; | 431 var len = res.length; |
436 var i = 0; | 432 var i = 0; |
437 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { | 433 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { |
438 var match_start = 0; | 434 var match_start = 0; |
439 var override = new InternalArray(null, 0, subject); | 435 var override = new InternalArray(null, 0, subject); |
440 var receiver = %GetDefaultReceiver(replace); | 436 var receiver = %GetDefaultReceiver(replace); |
441 if (%DebugCallbackSupportsStepping(replace)) { | 437 while (i < len) { |
442 while (i < len) { | 438 var elem = res[i]; |
443 var elem = res[i]; | 439 if (%_IsSmi(elem)) { |
444 if (%_IsSmi(elem)) { | 440 if (elem > 0) { |
445 if (elem > 0) { | 441 match_start = (elem >> 11) + (elem & 0x7ff); |
446 match_start = (elem >> 11) + (elem & 0x7ff); | |
447 } else { | |
448 match_start = res[++i] - elem; | |
449 } | |
450 } else { | 442 } else { |
451 override[0] = elem; | 443 match_start = res[++i] - elem; |
452 override[1] = match_start; | |
453 lastMatchInfoOverride = override; | |
454 %DebugPrepareStepInIfStepping(replace); | |
455 var func_result = | |
456 %_CallFunction(receiver, elem, match_start, subject, replace); | |
457 res[i] = TO_STRING_INLINE(func_result); | |
458 match_start += elem.length; | |
459 } | 444 } |
460 i++; | 445 } else { |
| 446 override[0] = elem; |
| 447 override[1] = match_start; |
| 448 lastMatchInfoOverride = override; |
| 449 var func_result = |
| 450 %_CallFunction(receiver, elem, match_start, subject, replace); |
| 451 res[i] = TO_STRING_INLINE(func_result); |
| 452 match_start += elem.length; |
461 } | 453 } |
462 } else { | 454 i++; |
463 // This is a duplicate of the previous loop sans debug stepping. | |
464 while (i < len) { | |
465 var elem = res[i]; | |
466 if (%_IsSmi(elem)) { | |
467 if (elem > 0) { | |
468 match_start = (elem >> 11) + (elem & 0x7ff); | |
469 } else { | |
470 match_start = res[++i] - elem; | |
471 } | |
472 } else { | |
473 override[0] = elem; | |
474 override[1] = match_start; | |
475 lastMatchInfoOverride = override; | |
476 var func_result = | |
477 %_CallFunction(receiver, elem, match_start, subject, replace); | |
478 res[i] = TO_STRING_INLINE(func_result); | |
479 match_start += elem.length; | |
480 } | |
481 i++; | |
482 } | |
483 // End of duplicate. | |
484 } | 455 } |
485 } else { | 456 } else { |
486 var receiver = %GetDefaultReceiver(replace); | 457 var receiver = %GetDefaultReceiver(replace); |
487 while (i < len) { | 458 while (i < len) { |
488 var elem = res[i]; | 459 var elem = res[i]; |
489 if (!%_IsSmi(elem)) { | 460 if (!%_IsSmi(elem)) { |
490 // elem must be an Array. | 461 // elem must be an Array. |
491 // Use the apply argument as backing for global RegExp properties. | 462 // Use the apply argument as backing for global RegExp properties. |
492 lastMatchInfoOverride = elem; | 463 lastMatchInfoOverride = elem; |
493 var func_result = %Apply(replace, receiver, elem, 0, elem.length); | 464 var func_result = %Apply(replace, receiver, elem, 0, elem.length); |
(...skipping 19 matching lines...) Expand all Loading... |
513 var endOfMatch = matchInfo[CAPTURE1]; | 484 var endOfMatch = matchInfo[CAPTURE1]; |
514 // Compute the parameter list consisting of the match, captures, index, | 485 // Compute the parameter list consisting of the match, captures, index, |
515 // and subject for the replace function invocation. | 486 // and subject for the replace function invocation. |
516 // The number of captures plus one for the match. | 487 // The number of captures plus one for the match. |
517 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; | 488 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; |
518 var replacement; | 489 var replacement; |
519 var receiver = %GetDefaultReceiver(replace); | 490 var receiver = %GetDefaultReceiver(replace); |
520 if (m == 1) { | 491 if (m == 1) { |
521 // No captures, only the match, which is always valid. | 492 // No captures, only the match, which is always valid. |
522 var s = SubString(subject, index, endOfMatch); | 493 var s = SubString(subject, index, endOfMatch); |
523 // Prepare break slots for debugger step in. | |
524 if (%DebugCallbackSupportsStepping(replace)) { | |
525 %DebugPrepareStepInIfStepping(replace); | |
526 } | |
527 // Don't call directly to avoid exposing the built-in global object. | 494 // Don't call directly to avoid exposing the built-in global object. |
528 replacement = %_CallFunction(receiver, s, index, subject, replace); | 495 replacement = %_CallFunction(receiver, s, index, subject, replace); |
529 } else { | 496 } else { |
530 var parameters = new InternalArray(m + 2); | 497 var parameters = new InternalArray(m + 2); |
531 for (var j = 0; j < m; j++) { | 498 for (var j = 0; j < m; j++) { |
532 parameters[j] = CaptureString(subject, matchInfo, j); | 499 parameters[j] = CaptureString(subject, matchInfo, j); |
533 } | 500 } |
534 parameters[j] = index; | 501 parameters[j] = index; |
535 parameters[j + 1] = subject; | 502 parameters[j + 1] = subject; |
536 | 503 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 "fixed", StringFixed, | 1011 "fixed", StringFixed, |
1045 "italics", StringItalics, | 1012 "italics", StringItalics, |
1046 "small", StringSmall, | 1013 "small", StringSmall, |
1047 "strike", StringStrike, | 1014 "strike", StringStrike, |
1048 "sub", StringSub, | 1015 "sub", StringSub, |
1049 "sup", StringSup | 1016 "sup", StringSup |
1050 )); | 1017 )); |
1051 } | 1018 } |
1052 | 1019 |
1053 SetUpString(); | 1020 SetUpString(); |
OLD | NEW |