summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-09-23 20:10:20 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-09-23 23:59:13 +0300
commita90107b02a4e8501593b582da2fe46cad123b372 (patch)
treee744cbac1c9e9361792f76fa844adb3166489cd1 /Userland/Libraries
parent1db7e096e24f004cbc86b20c5218b394a0ef5533 (diff)
downloadserenity-a90107b02a4e8501593b582da2fe46cad123b372.zip
LibJS: Convert is_regexp to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp20
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
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()); }