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