1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

LibJS: Mark infallible operations that may throw only due to OOM

This commit is contained in:
Timothy Flynn 2023-01-20 14:26:48 -05:00 committed by Linus Groh
parent 52b76060f9
commit 95d1678553
18 changed files with 48 additions and 69 deletions

View file

@ -49,8 +49,7 @@ StringView ListFormat::type_string() const
ThrowCompletionOr<Vector<PatternPartition>> deconstruct_pattern(VM& vm, StringView pattern, Placeables placeables)
{
// 1. Let patternParts be ! PartitionPattern(pattern).
// NOTE: We TRY this operation only to propagate OOM errors.
auto pattern_parts = TRY(partition_pattern(vm, pattern));
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
// 2. Let result be a new empty List.
Vector<PatternPartition> result {};
@ -127,7 +126,7 @@ ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListF
placeables.set("1"sv, move(second));
// f. Return ! DeconstructPattern(pattern, placeables).
return deconstruct_pattern(vm, pattern, move(placeables));
return MUST_OR_THROW_OOM(deconstruct_pattern(vm, pattern, move(placeables)));
}
// 4. Let last be a new Record { [[Type]]: "element", [[Value]]: list[size - 1] }.
@ -173,8 +172,7 @@ ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListF
placeables.set("1"sv, move(parts));
// g. Set parts to ! DeconstructPattern(pattern, placeables).
// NOTE: We TRY this operation only to propagate OOM errors.
parts = TRY(deconstruct_pattern(vm, pattern, move(placeables)));
parts = MUST_OR_THROW_OOM(deconstruct_pattern(vm, pattern, move(placeables)));
// h. Decrement i by 1.
} while (i-- != 0);
@ -187,8 +185,7 @@ ThrowCompletionOr<Vector<PatternPartition>> create_parts_from_list(VM& vm, ListF
ThrowCompletionOr<DeprecatedString> format_list(VM& vm, ListFormat const& list_format, Vector<DeprecatedString> const& list)
{
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
// NOTE: We TRY this operation only to propagate OOM errors.
auto parts = TRY(create_parts_from_list(vm, list_format, list));
auto parts = MUST_OR_THROW_OOM(create_parts_from_list(vm, list_format, list));
// 2. Let result be an empty String.
StringBuilder result;
@ -209,8 +206,7 @@ ThrowCompletionOr<Array*> format_list_to_parts(VM& vm, ListFormat const& list_fo
auto& realm = *vm.current_realm();
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
// NOTE: We TRY this operation only to propagate OOM errors.
auto parts = TRY(create_parts_from_list(vm, list_format, list));
auto parts = MUST_OR_THROW_OOM(create_parts_from_list(vm, list_format, list));
// 2. Let result be ! ArrayCreate(0).
auto result = MUST(Array::create(realm, 0));