Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Unified Diff: src/runtime/runtime-strings.cc

Issue 2351643002: [builtins] Move StringIndexOf to a builtin. (Closed)
Patch Set: Fix signed vs unsigned comparison Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-strings.cc
diff --git a/src/runtime/runtime-strings.cc b/src/runtime/runtime-strings.cc
index f5bda59b26fe9316b02aecdd80b3b60742876a8b..6a6f14a65b25e0a3aa75b46d5e12d73e11d500bb 100644
--- a/src/runtime/runtime-strings.cc
+++ b/src/runtime/runtime-strings.cc
@@ -43,16 +43,21 @@ MaybeHandle<String> StringReplaceOneCharWithString(
return subject;
} else {
- int index = String::IndexOf(isolate, subject, search, 0);
- if (index == -1) return subject;
+ Object* index = String::IndexOf(isolate, subject, search,
+ isolate->factory()->undefined_value());
+ int index_int = -1;
+ index->ToInt32(&index_int);
+
+ if (index_int == -1) return subject;
*found = true;
- Handle<String> first = isolate->factory()->NewSubString(subject, 0, index);
+ Handle<String> first =
+ isolate->factory()->NewSubString(subject, 0, index_int);
Handle<String> cons1;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, cons1, isolate->factory()->NewConsString(first, replace),
String);
- Handle<String> second =
- isolate->factory()->NewSubString(subject, index + 1, subject->length());
+ Handle<String> second = isolate->factory()->NewSubString(
+ subject, index_int + 1, subject->length());
return isolate->factory()->NewConsString(cons1, second);
}
}
@@ -90,17 +95,8 @@ RUNTIME_FUNCTION(Runtime_StringReplaceOneCharWithString) {
RUNTIME_FUNCTION(Runtime_StringIndexOf) {
HandleScope scope(isolate);
DCHECK(args.length() == 3);
-
- CONVERT_ARG_HANDLE_CHECKED(String, sub, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, pat, 1);
- CONVERT_ARG_HANDLE_CHECKED(Object, index, 2);
-
- uint32_t start_index = 0;
- if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
-
- CHECK(start_index <= static_cast<uint32_t>(sub->length()));
- int position = String::IndexOf(isolate, sub, pat, start_index);
- return Smi::FromInt(position);
+ return String::IndexOf(isolate, args.at<Object>(0), args.at<Object>(1),
+ args.at<Object>(2));
}
RUNTIME_FUNCTION(Runtime_StringLastIndexOf) {
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698