summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-23 03:52:23 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-23 18:01:51 +0200
commit844be7a0a5f6b8708970b2eaf2acf2edb02561a9 (patch)
treec8a12dbc20dd3bad935cce9ff6c7a1ecbd941133 /Userland
parentd9f5e2d461b5559695bef56c14b063ac2b152fa1 (diff)
downloadserenity-844be7a0a5f6b8708970b2eaf2acf2edb02561a9.zip
LibJS: Convert the RegExpCreate AO to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp12
5 files changed, 11 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 7a0600055e..99e72bf0eb 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -184,7 +184,10 @@ void NewRegExp::execute_impl(Bytecode::Interpreter& interpreter) const
auto source = interpreter.current_executable().get_string(m_source_index);
auto flags = interpreter.current_executable().get_string(m_flags_index);
- interpreter.accumulator() = regexp_create(interpreter.global_object(), js_string(interpreter.vm(), source), js_string(interpreter.vm(), flags));
+ auto regexp_or_error = regexp_create(interpreter.global_object(), js_string(interpreter.vm(), source), js_string(interpreter.vm(), flags));
+ if (regexp_or_error.is_error())
+ return;
+ interpreter.accumulator() = regexp_or_error.value();
}
void CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp
index cf5de31032..5869283b59 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp
@@ -88,10 +88,7 @@ ThrowCompletionOr<Object*> RegExpConstructor::construct(FunctionObject&)
flags_value = flags;
}
- auto* regexp = regexp_create(global_object, pattern_value, flags_value);
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
- return regexp;
+ return TRY(regexp_create(global_object, pattern_value, flags_value));
}
// 22.2.4.2 get RegExp [ @@species ], https://tc39.es/ecma262/#sec-get-regexp-@@species
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
index f08c55ea62..fb8f455713 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
@@ -190,10 +190,10 @@ String RegExpObject::escape_regexp_pattern() const
}
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
-RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value flags)
+ThrowCompletionOr<RegExpObject*> regexp_create(GlobalObject& global_object, Value pattern, Value flags)
{
auto* regexp_object = RegExpObject::create(global_object);
- return TRY_OR_DISCARD(regexp_object->regexp_initialize(global_object, pattern, flags));
+ return TRY(regexp_object->regexp_initialize(global_object, pattern, flags));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.h b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
index d130a656cc..ae9155da83 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.h
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
@@ -14,7 +14,7 @@
namespace JS {
-RegExpObject* regexp_create(GlobalObject&, Value pattern, Value flags);
+ThrowCompletionOr<RegExpObject*> regexp_create(GlobalObject&, Value pattern, Value flags);
Result<regex::RegexOptions<ECMAScriptFlags>, String> regex_flags_from_string(StringView flags);
String parse_regex_pattern(StringView pattern, bool unicode);
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index c64d822d7e..756a3311e8 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -729,9 +729,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
auto string = TRY(this_object.to_utf16_string(global_object));
- auto* rx = regexp_create(global_object, regexp, js_undefined());
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto* rx = TRY(regexp_create(global_object, regexp, js_undefined()));
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_match(), js_string(vm, move(string))));
}
@@ -755,9 +753,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
auto string = TRY(this_object.to_utf16_string(global_object));
- auto* rx = regexp_create(global_object, regexp, js_string(vm, "g"));
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto* rx = TRY(regexp_create(global_object, regexp, js_string(vm, "g")));
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_match_all(), js_string(vm, move(string))));
}
@@ -884,9 +880,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
auto string = TRY(this_object.to_utf16_string(global_object));
- auto* rx = regexp_create(global_object, regexp, js_undefined());
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto* rx = TRY(regexp_create(global_object, regexp, js_undefined()));
return TRY(Value(rx).invoke(global_object, *vm.well_known_symbol_search(), js_string(vm, move(string))));
}