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)
This commit is contained in:
Idan Horowitz 2021-04-20 15:24:49 +03:00 committed by Linus Groh
parent 81d7d68416
commit b1e5330e64
Notes: sideshowbarker 2024-07-18 19:21:11 +09:00

View file

@ -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;