LibJS: Convert is_regexp to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-09-23 20:10:20 +03:00
parent 1db7e096e2
commit a90107b02a
Notes: sideshowbarker 2024-07-18 03:31:10 +09:00
4 changed files with 9 additions and 23 deletions

View file

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

View file

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

View file

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

View file

@ -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()); }