diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.h | 2 |
4 files changed, 9 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp index bade8fb9ab..97b01f7988 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp @@ -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; diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 606343611b..5f52af546d 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -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); diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 6729c96a2f..0016c75c50 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -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; diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index e61d37b0a4..a3dd6ca38b 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -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()); } |