From b1e5330e645fa3a674bad04724e032dee1887c81 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 20 Apr 2021 15:24:49 +0300 Subject: [PATCH] LibJS: Stop early-returning on missing searchString in String.startsWith A missing searchString is allowed by the specification and is treated as js_undefined. ("undefined test".startsWith() => true) --- Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index fdb2e3cec46..35cf8267643 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -179,11 +179,11 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with) auto string = ak_string_from(vm, global_object); if (string.is_null()) return {}; - if (!vm.argument_count()) - return Value(false); + auto search_string = vm.argument(0).to_string(global_object); if (vm.exception()) return {}; + auto string_length = string.length(); auto search_string_length = search_string.length(); size_t start = 0;