@@ -1250,20 +1250,16 @@ static Object SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
12501250// doesn't properly call the underlying exec method.
12511251V8_WARN_UNUSED_RESULT MaybeHandle<String> RegExpReplace (
12521252 Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> string,
1253- Handle<Object> replace_obj ) {
1253+ Handle<String> replace ) {
12541254 // Functional fast-paths are dispatched directly by replace builtin.
12551255 DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
1256- DCHECK (!replace_obj->IsCallable ());
12571256
12581257 Factory* factory = isolate->factory ();
12591258
12601259 const int flags = regexp->GetFlags ();
12611260 const bool global = (flags & JSRegExp::kGlobal ) != 0 ;
12621261 const bool sticky = (flags & JSRegExp::kSticky ) != 0 ;
12631262
1264- Handle<String> replace;
1265- ASSIGN_RETURN_ON_EXCEPTION (isolate, replace,
1266- Object::ToString (isolate, replace_obj), String);
12671263 replace = String::Flatten (isolate, replace);
12681264
12691265 Handle<RegExpMatchInfo> last_match_info = isolate->regexp_last_match_info ();
@@ -1363,18 +1359,23 @@ RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) {
13631359 CONVERT_ARG_HANDLE_CHECKED (String, subject, 1 );
13641360 CONVERT_ARG_HANDLE_CHECKED (RegExpMatchInfo, last_match_info, 2 );
13651361 CONVERT_ARG_HANDLE_CHECKED (JSArray, result_array, 3 );
1362+
1363+ DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
13661364 CHECK (result_array->HasObjectElements ());
13671365
13681366 subject = String::Flatten (isolate, subject);
13691367 CHECK (regexp->GetFlags () & JSRegExp::kGlobal );
13701368
1369+ Object result;
13711370 if (regexp->CaptureCount () == 0 ) {
1372- return SearchRegExpMultiple<false >(isolate, subject, regexp,
1373- last_match_info, result_array);
1371+ result = SearchRegExpMultiple<false >(isolate, subject, regexp,
1372+ last_match_info, result_array);
13741373 } else {
1375- return SearchRegExpMultiple<true >(isolate, subject, regexp, last_match_info ,
1376- result_array);
1374+ result = SearchRegExpMultiple<true >(isolate, subject, regexp,
1375+ last_match_info, result_array);
13771376 }
1377+ DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
1378+ return result;
13781379}
13791380
13801381RUNTIME_FUNCTION (Runtime_StringReplaceNonGlobalRegExpWithFunction) {
@@ -1691,24 +1692,27 @@ RUNTIME_FUNCTION(Runtime_RegExpReplace) {
16911692
16921693 const bool functional_replace = replace_obj->IsCallable ();
16931694
1695+ Handle<String> replace;
1696+ if (!functional_replace) {
1697+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION (isolate, replace,
1698+ Object::ToString (isolate, replace_obj));
1699+ }
1700+
16941701 // Fast-path for unmodified JSRegExps (and non-functional replace).
16951702 if (RegExpUtils::IsUnmodifiedRegExp (isolate, recv)) {
16961703 // We should never get here with functional replace because unmodified
16971704 // regexp and functional replace should be fully handled in CSA code.
16981705 CHECK (!functional_replace);
1699- RETURN_RESULT_OR_FAILURE (
1700- isolate, RegExpReplace (isolate, Handle<JSRegExp>::cast (recv), string,
1701- replace_obj));
1706+ Handle<Object> result;
1707+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION (
1708+ isolate, result,
1709+ RegExpReplace (isolate, Handle<JSRegExp>::cast (recv), string, replace));
1710+ DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, recv));
1711+ return *result;
17021712 }
17031713
17041714 const uint32_t length = string->length ();
17051715
1706- Handle<String> replace;
1707- if (!functional_replace) {
1708- ASSIGN_RETURN_FAILURE_ON_EXCEPTION (isolate, replace,
1709- Object::ToString (isolate, replace_obj));
1710- }
1711-
17121716 Handle<Object> global_obj;
17131717 ASSIGN_RETURN_FAILURE_ON_EXCEPTION (
17141718 isolate, global_obj,
0 commit comments