mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
LibJS: Throw on a regex searchString in String.startsWith
As is required by the specification: "Let isRegExp be ? IsRegExp(searchString). If isRegExp is true, throw a TypeError exception."
This commit is contained in:
parent
b1e5330e64
commit
63af67ea01
Notes:
sideshowbarker
2024-07-18 19:21:07 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/63af67ea010 Pull-request: https://github.com/SerenityOS/serenity/pull/6517
1 changed files with 11 additions and 1 deletions
|
@ -180,7 +180,17 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
|
|||
if (string.is_null())
|
||||
return {};
|
||||
|
||||
auto search_string = vm.argument(0).to_string(global_object);
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = search_string_value.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (search_is_regexp) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto search_string = search_string_value.to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue