OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 res[i] = TO_STRING(func_result); | 451 res[i] = TO_STRING(func_result); |
452 match_start += elem.length; | 452 match_start += elem.length; |
453 } | 453 } |
454 } | 454 } |
455 } else { | 455 } else { |
456 for (var i = 0; i < len; i++) { | 456 for (var i = 0; i < len; i++) { |
457 var elem = res[i]; | 457 var elem = res[i]; |
458 if (!%_IsSmi(elem)) { | 458 if (!%_IsSmi(elem)) { |
459 // elem must be an Array. | 459 // elem must be an Array. |
460 // Use the apply argument as backing for global RegExp properties. | 460 // Use the apply argument as backing for global RegExp properties. |
461 var func_result = %Apply(replace, UNDEFINED, elem, 0, elem.length); | 461 var func_result = %reflect_apply(replace, UNDEFINED, elem); |
462 // Overwrite the i'th element in the results with the string we got | 462 // Overwrite the i'th element in the results with the string we got |
463 // back from the callback function. | 463 // back from the callback function. |
464 res[i] = TO_STRING(func_result); | 464 res[i] = TO_STRING(func_result); |
465 } | 465 } |
466 } | 466 } |
467 } | 467 } |
468 var result = %StringBuilderConcat(res, len, subject); | 468 var result = %StringBuilderConcat(res, len, subject); |
469 resultArray.length = 0; | 469 resultArray.length = 0; |
470 reusableReplaceArray = resultArray; | 470 reusableReplaceArray = resultArray; |
471 return result; | 471 return result; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 // Don't call directly to avoid exposing the built-in global object. | 505 // Don't call directly to avoid exposing the built-in global object. |
506 replacement = replace(s, index, subject); | 506 replacement = replace(s, index, subject); |
507 } else { | 507 } else { |
508 var parameters = new InternalArray(m + 2); | 508 var parameters = new InternalArray(m + 2); |
509 for (var j = 0; j < m; j++) { | 509 for (var j = 0; j < m; j++) { |
510 parameters[j] = CaptureString(subject, matchInfo, j); | 510 parameters[j] = CaptureString(subject, matchInfo, j); |
511 } | 511 } |
512 parameters[j] = index; | 512 parameters[j] = index; |
513 parameters[j + 1] = subject; | 513 parameters[j + 1] = subject; |
514 | 514 |
515 replacement = %Apply(replace, UNDEFINED, parameters, 0, j + 2); | 515 replacement = %reflect_apply(replace, UNDEFINED, parameters); |
516 } | 516 } |
517 | 517 |
518 result += replacement; // The add method converts to string if necessary. | 518 result += replacement; // The add method converts to string if necessary. |
519 // Can't use matchInfo any more from here, since the function could | 519 // Can't use matchInfo any more from here, since the function could |
520 // overwrite it. | 520 // overwrite it. |
521 return result + %_SubString(subject, endOfMatch, subject.length); | 521 return result + %_SubString(subject, endOfMatch, subject.length); |
522 } | 522 } |
523 | 523 |
524 | 524 |
525 function RegExpReplace(string, replace) { | 525 function RegExpReplace(string, replace) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 // Exports | 772 // Exports |
773 | 773 |
774 utils.Export(function(to) { | 774 utils.Export(function(to) { |
775 to.RegExpExec = DoRegExpExec; | 775 to.RegExpExec = DoRegExpExec; |
776 to.RegExpExecNoTests = RegExpExecNoTests; | 776 to.RegExpExecNoTests = RegExpExecNoTests; |
777 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 777 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
778 to.RegExpTest = RegExpTest; | 778 to.RegExpTest = RegExpTest; |
779 }); | 779 }); |
780 | 780 |
781 }) | 781 }) |
OLD | NEW |