Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 9f824fbf482bd73fb0769625fec091a2d78b6019..7b39f82a931b60d559067d5cf5aad3f440c88c7f 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -11734,11 +11734,9 @@ Object* String::IndexOf(Isolate* isolate, Handle<Object> receiver, |
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
Object::ToInteger(isolate, position)); |
- double index = std::max(position->Number(), 0.0); |
- index = std::min(index, static_cast<double>(receiver_string->length())); |
- |
- return Smi::FromInt(String::IndexOf(isolate, receiver_string, search_string, |
- static_cast<uint32_t>(index))); |
+ uint32_t index = receiver_string->ToValidIndex(*position); |
+ return Smi::FromInt( |
+ String::IndexOf(isolate, receiver_string, search_string, index)); |
} |
namespace { |
@@ -11944,11 +11942,7 @@ Object* String::LastIndexOf(Isolate* isolate, Handle<Object> receiver, |
} else { |
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
Object::ToInteger(isolate, position)); |
- |
- double position_number = std::max(position->Number(), 0.0); |
- position_number = std::min(position_number, |
- static_cast<double>(receiver_string->length())); |
- start_index = static_cast<uint32_t>(position_number); |
+ start_index = receiver_string->ToValidIndex(*position); |
} |
uint32_t pattern_length = search_string->length(); |