mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Convert is_regexp to ThrowCompletionOr
This commit is contained in:
parent
1db7e096e2
commit
a90107b02a
Notes:
sideshowbarker
2024-07-18 03:31:10 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/a90107b02a4 Pull-request: https://github.com/SerenityOS/serenity/pull/10190 Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg ✅
4 changed files with 9 additions and 23 deletions
|
@ -42,9 +42,7 @@ Value RegExpConstructor::call()
|
|||
auto pattern = vm.argument(0);
|
||||
auto flags = vm.argument(1);
|
||||
|
||||
bool pattern_is_regexp = pattern.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool pattern_is_regexp = TRY_OR_DISCARD(pattern.is_regexp(global_object));
|
||||
|
||||
if (pattern_is_regexp && flags.is_undefined()) {
|
||||
auto pattern_constructor = pattern.as_object().get(vm.names.constructor);
|
||||
|
@ -67,9 +65,7 @@ Value RegExpConstructor::construct(FunctionObject&)
|
|||
auto pattern = vm.argument(0);
|
||||
auto flags = vm.argument(1);
|
||||
|
||||
bool pattern_is_regexp = pattern.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool pattern_is_regexp = TRY_OR_DISCARD(pattern.is_regexp(global_object));
|
||||
|
||||
Value pattern_value;
|
||||
Value flags_value;
|
||||
|
|
|
@ -267,9 +267,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = search_string_value.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool search_is_regexp = TRY_OR_DISCARD(search_string_value.is_regexp(global_object));
|
||||
if (search_is_regexp) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
return {};
|
||||
|
@ -310,9 +308,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::ends_with)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = search_string_value.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool search_is_regexp = TRY_OR_DISCARD(search_string_value.is_regexp(global_object));
|
||||
if (search_is_regexp) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
return {};
|
||||
|
@ -646,9 +642,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes)
|
|||
|
||||
auto search_string_value = vm.argument(0);
|
||||
|
||||
bool search_is_regexp = search_string_value.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool search_is_regexp = TRY_OR_DISCARD(search_string_value.is_regexp(global_object));
|
||||
if (search_is_regexp) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IsNotA, "searchString", "string, but a regular expression");
|
||||
return {};
|
||||
|
@ -888,9 +882,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
|
|||
auto this_object = TRY_OR_DISCARD(require_object_coercible(global_object, vm.this_value(global_object)));
|
||||
auto regexp = vm.argument(0);
|
||||
if (!regexp.is_nullish()) {
|
||||
auto is_regexp = regexp.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_regexp = TRY_OR_DISCARD(regexp.is_regexp(global_object));
|
||||
if (is_regexp) {
|
||||
auto flags = regexp.as_object().get("flags");
|
||||
if (vm.exception())
|
||||
|
@ -985,9 +977,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
|
|||
auto replace_value = vm.argument(1);
|
||||
|
||||
if (!search_value.is_nullish()) {
|
||||
bool is_regexp = search_value.is_regexp(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
bool is_regexp = TRY_OR_DISCARD(search_value.is_regexp(global_object));
|
||||
|
||||
if (is_regexp) {
|
||||
auto flags = search_value.as_object().get(vm.names.flags);
|
||||
|
|
|
@ -242,7 +242,7 @@ bool Value::is_constructor() const
|
|||
}
|
||||
|
||||
// 7.2.8 IsRegExp ( argument ), https://tc39.es/ecma262/#sec-isregexp
|
||||
bool Value::is_regexp(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<bool> Value::is_regexp(GlobalObject& global_object) const
|
||||
{
|
||||
if (!is_object())
|
||||
return false;
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
ThrowCompletionOr<bool> is_array(GlobalObject&) const;
|
||||
bool is_function() const;
|
||||
bool is_constructor() const;
|
||||
bool is_regexp(GlobalObject&) const;
|
||||
ThrowCompletionOr<bool> is_regexp(GlobalObject&) const;
|
||||
|
||||
bool is_nan() const { return is_number() && __builtin_isnan(as_double()); }
|
||||
bool is_infinity() const { return is_number() && __builtin_isinf(as_double()); }
|
||||
|
|
Loading…
Reference in a new issue