@@ -1250,20 +1250,16 @@ static Object SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
1250
1250
// doesn't properly call the underlying exec method.
1251
1251
V8_WARN_UNUSED_RESULT MaybeHandle<String> RegExpReplace (
1252
1252
Isolate* isolate, Handle <JSRegExp> regexp, Handle <String> string,
1253
- Handle <Object> replace_obj ) {
1253
+ Handle <String> replace ) {
1254
1254
// Functional fast-paths are dispatched directly by replace builtin.
1255
1255
DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
1256
- DCHECK (!replace_obj->IsCallable ());
1257
1256
1258
1257
Factory* factory = isolate->factory ();
1259
1258
1260
1259
const int flags = regexp->GetFlags ();
1261
1260
const bool global = (flags & JSRegExp::kGlobal ) != 0 ;
1262
1261
const bool sticky = (flags & JSRegExp::kSticky ) != 0 ;
1263
1262
1264
- Handle <String> replace;
1265
- ASSIGN_RETURN_ON_EXCEPTION (isolate, replace,
1266
- Object::ToString (isolate, replace_obj), String);
1267
1263
replace = String::Flatten (isolate, replace);
1268
1264
1269
1265
Handle <RegExpMatchInfo> last_match_info = isolate->regexp_last_match_info ();
@@ -1363,18 +1359,23 @@ RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) {
1363
1359
CONVERT_ARG_HANDLE_CHECKED (String, subject, 1 );
1364
1360
CONVERT_ARG_HANDLE_CHECKED (RegExpMatchInfo, last_match_info, 2 );
1365
1361
CONVERT_ARG_HANDLE_CHECKED (JSArray, result_array, 3 );
1362
+
1363
+ DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
1366
1364
CHECK (result_array->HasObjectElements ());
1367
1365
1368
1366
subject = String::Flatten (isolate, subject);
1369
1367
CHECK (regexp->GetFlags () & JSRegExp::kGlobal );
1370
1368
1369
+ Object result;
1371
1370
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);
1374
1373
} 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);
1377
1376
}
1377
+ DCHECK (RegExpUtils::IsUnmodifiedRegExp (isolate, regexp));
1378
+ return result;
1378
1379
}
1379
1380
1380
1381
RUNTIME_FUNCTION (Runtime_StringReplaceNonGlobalRegExpWithFunction) {
@@ -1691,24 +1692,27 @@ RUNTIME_FUNCTION(Runtime_RegExpReplace) {
1691
1692
1692
1693
const bool functional_replace = replace_obj->IsCallable ();
1693
1694
1695
+ Handle <String> replace;
1696
+ if (!functional_replace) {
1697
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION (isolate, replace,
1698
+ Object::ToString (isolate, replace_obj));
1699
+ }
1700
+
1694
1701
// Fast-path for unmodified JSRegExps (and non-functional replace).
1695
1702
if (RegExpUtils::IsUnmodifiedRegExp (isolate, recv)) {
1696
1703
// We should never get here with functional replace because unmodified
1697
1704
// regexp and functional replace should be fully handled in CSA code.
1698
1705
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;
1702
1712
}
1703
1713
1704
1714
const uint32_t length = string->length ();
1705
1715
1706
- Handle <String> replace;
1707
- if (!functional_replace) {
1708
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION (isolate, replace,
1709
- Object::ToString (isolate, replace_obj));
1710
- }
1711
-
1712
1716
Handle <Object> global_obj;
1713
1717
ASSIGN_RETURN_FAILURE_ON_EXCEPTION (
1714
1718
isolate, global_obj,
0 commit comments