mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +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
1 changed files with 11 additions and 1 deletions
|
@ -180,7 +180,17 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
|
||||||
if (string.is_null())
|
if (string.is_null())
|
||||||
return {};
|
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())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue