LibJS: Convert the RegExpCreate AO to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-23 03:52:23 +03:00 committed by Andreas Kling
parent d9f5e2d461
commit 844be7a0a5
5 changed files with 11 additions and 17 deletions

View file

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

View file

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

View file

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

View file

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

View file

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