Chromium Code Reviews| 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); |
|
Franzi
2016/09/20 17:03:28
Converting the previous code, this would be greate
petermarshall
2016/09/22 13:54:24
The runtime functions need to have a fixed number
|
| - |
| - 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) { |