From 71d6459b7f2e26a550df565c777760ccf6c9bd89 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 18 Apr 2020 21:08:23 +0100 Subject: [PATCH] LibJS: Use AK::String::index_of() for StringPrototype::index_of() --- Libraries/LibJS/Runtime/StringPrototype.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index dac1f057c2..54c4fede09 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -138,12 +138,7 @@ Value StringPrototype::index_of(Interpreter& interpreter) needle_value = interpreter.argument(0); auto needle = needle_value.to_string(); auto haystack = static_cast(this_object)->primitive_string()->string(); - - // FIXME: We should have a helper in AK::String for this. - auto* ptr = strstr(haystack.characters(), needle.characters()); - if (!ptr) - return Value(-1); - return Value((i32)(ptr - haystack.characters())); + return Value((i32)haystack.index_of(needle).value_or(-1)); } static StringObject* string_object_from(Interpreter& interpreter)