summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-20 14:26:48 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-20 20:31:38 +0000
commit95d1678553b7d3c1c46247b84f84e8bf3bff083f (patch)
treee7733f50d77349e723b1cd4149e66cf497e6cca0
parent52b76060f9cea7e045419290e04d861f7125486d (diff)
downloadserenity-95d1678553b7d3c1c46247b84f84e8bf3bff083f.zip
LibJS: Mark infallible operations that may throw only due to OOM
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp2
18 files changed, 48 insertions, 69 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index 6b64f02602..83f29af207 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -231,8 +231,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
auto input_string = TRY(vm.argument(0).to_deprecated_string(vm));
// 2. Let trimmedString be ! TrimString(inputString, start).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto trimmed_string = TRY(trim_string(vm, PrimitiveString::create(vm, input_string), TrimMode::Left));
+ auto trimmed_string = MUST_OR_THROW_OOM(trim_string(vm, PrimitiveString::create(vm, input_string), TrimMode::Left));
if (trimmed_string.is_empty())
return js_nan();
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
index f0722a4499..e6255318b9 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
@@ -245,13 +245,12 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
}
// v. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
- auto locale_id = TRY(is_structurally_valid_language_tag(vm, tag));
+ auto locale_id = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, tag));
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
// vi. Let canonicalizedTag be ! CanonicalizeUnicodeLocaleId(tag).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto canonicalized_tag = TRY(canonicalize_unicode_locale_id(vm, *locale_id));
+ auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
// vii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
if (!seen.contains_slow(canonicalized_tag))
@@ -354,7 +353,7 @@ ThrowCompletionOr<String> insert_unicode_extension_and_canonicalize(VM& vm, ::Lo
// of that string. LibUnicode gives us the parsed locale in a structure, so we can mutate that
// structure directly.
TRY_OR_THROW_OOM(vm, locale.extensions.try_append(move(extension)));
- return canonicalize_unicode_locale_id(vm, locale);
+ return MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, locale));
}
template<typename T>
@@ -387,14 +386,12 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// 2. If matcher is "lookup", then
if (matcher.is_string() && (TRY(matcher.as_string().utf8_string_view()) == "lookup"sv)) {
// a. Let r be ! LookupMatcher(availableLocales, requestedLocales).
- // NOTE: We TRY this operation only to propagate OOM errors.
- matcher_result = TRY(lookup_matcher(vm, requested_locales));
+ matcher_result = MUST_OR_THROW_OOM(lookup_matcher(vm, requested_locales));
}
// 3. Else,
else {
// a. Let r be ! BestFitMatcher(availableLocales, requestedLocales).
- // NOTE: We TRY this operation only to propagate OOM errors.
- matcher_result = TRY(best_fit_matcher(vm, requested_locales));
+ matcher_result = MUST_OR_THROW_OOM(best_fit_matcher(vm, requested_locales));
}
// 4. Let foundLocale be r.[[locale]].
@@ -516,7 +513,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
VERIFY(locale_id.has_value());
// a. Set foundLocale to InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedExtension).
- found_locale = TRY(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(supported_extension)));
+ found_locale = MUST_OR_THROW_OOM(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(supported_extension)));
}
// 11. Set result.[[locale]] to foundLocale.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp
index 1718d76356..dc0534536a 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp
@@ -62,10 +62,8 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 14. If numeric is not undefined, then
// a. Let numeric be ! ToString(numeric).
// 15. Set opt.[[kn]] to numeric.
- if (!numeric.is_undefined()) {
- // NOTE: We TRY this operation only to propagate OOM errors.
- opt.kn = TRY(numeric.to_string(vm));
- }
+ if (!numeric.is_undefined())
+ opt.kn = MUST_OR_THROW_OOM(numeric.to_string(vm));
// 16. Let caseFirst be ? GetOption(options, "caseFirst", string, ยซ "upper", "lower", "false" ยป, undefined).
// 17. Set opt.[[kf]] to caseFirst.
@@ -77,7 +75,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
auto relevant_extension_keys = Collator::relevant_extension_keys();
// 19. Let r be ResolveLocale(%Collator%.[[AvailableLocales]], requestedLocales, opt, relevantExtensionKeys, localeData).
- auto result = TRY(resolve_locale(vm, requested_locales, opt, relevant_extension_keys));
+ auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, relevant_extension_keys));
// 20. Set collator.[[Locale]] to r.[[locale]].
collator.set_locale(move(result.locale));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
index 9d88f9fad9..29f03eb5d6 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
@@ -621,7 +621,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
value = floor(value * pow(10, static_cast<int>(*fractional_second_digits) - 3));
// iii. Let fv be FormatNumeric(nf3, v).
- auto formatted_value = TRY(format_numeric(vm, *number_format3, Value(value)));
+ auto formatted_value = MUST_OR_THROW_OOM(format_numeric(vm, *number_format3, Value(value)));
// iv. Append a new Record { [[Type]]: "fractionalSecond", [[Value]]: fv } as the last element of result.
result.append({ "fractionalSecond"sv, move(formatted_value) });
@@ -705,13 +705,13 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
// viii. If f is "numeric", then
case ::Locale::CalendarPatternStyle::Numeric:
// 1. Let fv be FormatNumeric(nf, v).
- formatted_value = TRY(format_numeric(vm, *number_format, Value(value)));
+ formatted_value = MUST_OR_THROW_OOM(format_numeric(vm, *number_format, Value(value)));
break;
// ix. Else if f is "2-digit", then
case ::Locale::CalendarPatternStyle::TwoDigit:
// 1. Let fv be FormatNumeric(nf2, v).
- formatted_value = TRY(format_numeric(vm, *number_format2, Value(value)));
+ formatted_value = MUST_OR_THROW_OOM(format_numeric(vm, *number_format2, Value(value)));
// 2. If the "length" property of fv is greater than 2, let fv be the substring of fv containing the last two characters.
// NOTE: The first length check here isn't enough, but lets us avoid UTF-16 transcoding when the formatted value is ASCII.
@@ -820,7 +820,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
ThrowCompletionOr<Vector<PatternPartition>> partition_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, double time)
{
// 1. Let patternParts be PartitionPattern(dateTimeFormat.[[Pattern]]).
- auto pattern_parts = TRY(partition_pattern(vm, date_time_format.pattern()));
+ auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, date_time_format.pattern()));
// 2. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined).
auto result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), time, nullptr));
@@ -1067,7 +1067,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
auto const& pattern = date_time_format.pattern();
// b. Let patternParts be PartitionPattern(pattern).
- auto pattern_parts = TRY(partition_pattern(vm, pattern));
+ auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
// c. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined).
auto raw_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), start, nullptr));
@@ -1124,7 +1124,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
auto time = ((source == "startRange") || (source == "shared")) ? start : end;
// e. Let patternParts be PartitionPattern(pattern).
- auto pattern_parts = TRY(partition_pattern(vm, pattern));
+ auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
// f. Let partResult be ? FormatDateTimePattern(dateTimeFormat, patternParts, z, rangePattern).
auto raw_part_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), time, &range_pattern.value()));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp
index 52781e3aff..b67e35f8c9 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp
@@ -144,7 +144,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
// 16. Let localeData be %DateTimeFormat%.[[LocaleData]].
// 17. Let r be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]], localeData).
- auto result = TRY(resolve_locale(vm, requested_locales, opt, DateTimeFormat::relevant_extension_keys()));
+ auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, DateTimeFormat::relevant_extension_keys()));
// 18. Set dateTimeFormat.[[Locale]] to r.[[locale]].
date_time_format.set_locale(move(result.locale));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
index 14dddfdc36..a851732a39 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
@@ -110,13 +110,12 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "language"sv);
// b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception.
- auto locale_id = TRY(is_structurally_valid_language_tag(vm, code));
+ auto locale_id = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, code));
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, code);
// c. Return ! CanonicalizeUnicodeLocaleId(code).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto canonicalized_tag = TRY(canonicalize_unicode_locale_id(vm, *locale_id));
+ auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
return PrimitiveString::create(vm, move(canonicalized_tag));
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
index d8ae16a5a6..01f74a9eb7 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp
@@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
break;
}
- if (auto locale = TRY(is_structurally_valid_language_tag(vm, code_string)); locale.has_value())
+ if (auto locale = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, code_string)); locale.has_value())
formatted_result = ::Locale::format_locale_for_display(display_names->locale(), locale.release_value());
break;
case DisplayNames::Type::Region:
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
index f3c3b7e526..ee6921ec29 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
@@ -445,8 +445,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
// 3. Let dataLocaleData be %DurationFormat%.[[LocaleData]].[[<dataLocale>]].
// 4. Let num be ! FormatNumeric(nf, ๐”ฝ(value)).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto number = TRY(format_numeric(vm, *number_format, MathematicalValue(value)));
+ auto number = MUST_OR_THROW_OOM(format_numeric(vm, *number_format, MathematicalValue(value)));
// 5. Append the new Record { [[Type]]: unit, [[Value]]: num} to the end of result.
result.append({ unit, number });
@@ -505,8 +504,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
// 5. Let parts be ! PartitionNumberPattern(nf, ๐”ฝ(value)).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto parts = TRY(partition_number_pattern(vm, *number_format, MathematicalValue(value)));
+ auto parts = MUST_OR_THROW_OOM(partition_number_pattern(vm, *number_format, MathematicalValue(value)));
// 6. Let concat be an empty String.
StringBuilder concat;
@@ -566,8 +564,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// 10. Set result to ! CreatePartsFromList(lf, result).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto final_result = TRY(create_parts_from_list(vm, *list_format, string_result));
+ auto final_result = MUST_OR_THROW_OOM(create_parts_from_list(vm, *list_format, string_result));
// 11. Return result.
return final_result;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
index 204b312beb..12161f3867 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
@@ -77,7 +77,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
opt.nu = numbering_system.is_undefined() ? Optional<String>() : TRY(numbering_system.as_string().utf8_string());
// 9. Let r be ResolveLocale(%DurationFormat%.[[AvailableLocales]], requestedLocales, opt, %DurationFormat%.[[RelevantExtensionKeys]], %DurationFormat%.[[LocaleData]]).
- auto result = TRY(resolve_locale(vm, requested_locales, opt, DurationFormat::relevant_extension_keys()));
+ auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, DurationFormat::relevant_extension_keys()));
// 10. Let locale be r.[[locale]].
auto locale = move(result.locale);
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
index 913cfe7a70..a8600a8f5b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
@@ -43,7 +43,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
auto record = TRY(to_duration_record(vm, vm.argument(0)));
// 4. Let parts be PartitionDurationFormatPattern(df, record).
- auto parts = TRY(partition_duration_format_pattern(vm, *duration_format, record));
+ auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, *duration_format, record));
// 5. Let result be a new empty String.
StringBuilder result;
@@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto record = TRY(to_duration_record(vm, vm.argument(0)));
// 4. Let parts be PartitionDurationFormatPattern(df, record).
- auto parts = TRY(partition_duration_format_pattern(vm, *duration_format, record));
+ auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, *duration_format, record));
// 5. Let result be ! ArrayCreate(0).
auto result = MUST(Array::create(realm, 0));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
index 017106556a..2b5b0b522c 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp
@@ -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));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
index b3ea2e24e7..18c94ef60e 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp
@@ -46,8 +46,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
auto string_list = TRY(string_list_from_iterable(vm, list));
// 4. Return ! FormatList(lf, stringList).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto formatted = TRY(format_list(vm, *list_format, string_list));
+ auto formatted = MUST_OR_THROW_OOM(format_list(vm, *list_format, string_list));
return PrimitiveString::create(vm, move(formatted));
}
@@ -64,8 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
auto string_list = TRY(string_list_from_iterable(vm, list));
// 4. Return ! FormatListToParts(lf, stringList).
- // NOTE: We TRY this operation only to propagate OOM errors.
- return TRY(format_list_to_parts(vm, *list_format, string_list));
+ return MUST_OR_THROW_OOM(format_list_to_parts(vm, *list_format, string_list));
}
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
index e0d8fc3a3b..e6b002a512 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
@@ -47,7 +47,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
// 2. Assert: Type(options) is Object.
// 3. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
- auto locale_id = TRY(is_structurally_valid_language_tag(vm, tag));
+ auto locale_id = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, tag));
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
@@ -67,8 +67,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
auto region = TRY(get_string_option(vm, options, vm.names.region, ::Locale::is_unicode_region_subtag));
// 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto canonicalized_tag = TRY(canonicalize_unicode_locale_id(vm, *locale_id));
+ auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
// 11. Assert: tag matches the unicode_locale_id production.
locale_id = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(canonicalized_tag));
@@ -103,7 +102,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
// 16. Set tag to tag with the substring corresponding to the unicode_language_id production replaced by the string languageId.
// 17. Return ! CanonicalizeUnicodeLocaleId(tag).
- return canonicalize_unicode_locale_id(vm, *locale_id);
+ return MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
}
// 14.1.3 ApplyUnicodeExtensionToTag ( tag, options, relevantExtensionKeys ), https://tc39.es/ecma402/#sec-apply-unicode-extension-to-tag
@@ -208,7 +207,7 @@ static ThrowCompletionOr<LocaleAndKeys> apply_unicode_extension_to_tag(VM& vm, S
// 9. If newExtension is not the empty String, then
if (!new_extension.attributes.is_empty() || !new_extension.keywords.is_empty()) {
// a. Let locale be ! InsertUnicodeExtensionAndCanonicalize(locale, newExtension).
- locale = TRY(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(new_extension)));
+ locale = MUST_OR_THROW_OOM(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(new_extension)));
}
// 10. Set result.[[locale]] to locale.
@@ -324,8 +323,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
opt.nu = TRY(get_string_option(vm, *options, vm.names.numberingSystem, ::Locale::is_type_identifier));
// 29. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto result = TRY(apply_unicode_extension_to_tag(vm, tag, move(opt), relevant_extension_keys));
+ auto result = MUST_OR_THROW_OOM(apply_unicode_extension_to_tag(vm, tag, move(opt), relevant_extension_keys));
// 30. Set locale.[[Locale]] to r.[[locale]].
locale->set_locale(move(result.locale));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
index 5cd19a0f6d..a6a05826ac 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
@@ -69,8 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
locale->language_id = maximal.release_value();
// 4. Return ! Construct(%Locale%, maximal).
- // NOTE: We TRY this operation only to propagate OOM errors.
- return TRY(Locale::create(realm, locale.release_value()));
+ return MUST_OR_THROW_OOM(Locale::create(realm, locale.release_value()));
}
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
@@ -90,8 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
locale->language_id = minimal.release_value();
// 4. Return ! Construct(%Locale%, minimal).
- // NOTE: We TRY this operation only to propagate OOM errors.
- return TRY(Locale::create(realm, locale.release_value()));
+ return MUST_OR_THROW_OOM(Locale::create(realm, locale.release_value()));
}
// 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
index 32bd9b8656..d153870c2d 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
@@ -581,7 +581,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
Vector<PatternPartition> result;
// 8. Let patternParts be PartitionPattern(pattern).
- auto pattern_parts = TRY(pattern->visit([&](auto const& p) { return partition_pattern(vm, p); }));
+ auto pattern_parts = MUST_OR_THROW_OOM(pattern->visit([&](auto const& p) { return partition_pattern(vm, p); }));
// 9. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do
for (auto& pattern_part : pattern_parts) {
@@ -597,7 +597,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
// c. Else if p is equal to "number", then
else if (part == "number"sv) {
// i. Let notationSubParts be PartitionNotationSubPattern(numberFormat, x, n, exponent).
- auto notation_sub_parts = TRY(partition_notation_sub_pattern(vm, number_format, number, formatted_string, exponent));
+ auto notation_sub_parts = MUST_OR_THROW_OOM(partition_notation_sub_pattern(vm, number_format, number, formatted_string, exponent));
// ii. Append all elements of notationSubParts to result.
result.extend(move(notation_sub_parts));
}
@@ -742,7 +742,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
return Vector<PatternPartition> {};
// b. Let patternParts be PartitionPattern(notationSubPattern).
- auto pattern_parts = TRY(partition_pattern(vm, *notation_sub_pattern));
+ auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, *notation_sub_pattern));
// c. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do
for (auto& pattern_part : pattern_parts) {
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp
index 68f0bf7a32..30e4dbb816 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp
@@ -112,7 +112,7 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat&
// 9. Let localeData be %NumberFormat%.[[LocaleData]].
// 10. Let r be ResolveLocale(%NumberFormat%.[[AvailableLocales]], requestedLocales, opt, %NumberFormat%.[[RelevantExtensionKeys]], localeData).
- auto result = TRY(resolve_locale(vm, requested_locales, opt, NumberFormat::relevant_extension_keys()));
+ auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, NumberFormat::relevant_extension_keys()));
// 11. Set numberFormat.[[Locale]] to r.[[locale]].
number_format.set_locale(move(result.locale));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
index 21738faebb..801627e6e5 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp
@@ -174,8 +174,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
auto patterns = find_patterns_for_tense_or_number(tense);
// 20. Let fv be ! PartitionNumberPattern(relativeTimeFormat.[[NumberFormat]], value).
- // NOTE: We TRY this operation only to propagate OOM errors.
- auto value_partitions = TRY(partition_number_pattern(vm, relative_time_format.number_format(), Value(value)));
+ auto value_partitions = MUST_OR_THROW_OOM(partition_number_pattern(vm, relative_time_format.number_format(), Value(value)));
// 21. Let pr be ! ResolvePlural(relativeTimeFormat.[[PluralRules]], value).
auto plurality = resolve_plural(relative_time_format.plural_rules(), Value(value));
@@ -186,14 +185,14 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
return Vector<PatternPartitionWithUnit> {};
// 23. Return ! MakePartsList(pattern, unit, fv).
- return make_parts_list(vm, pattern->pattern, ::Locale::time_unit_to_string(time_unit), move(value_partitions));
+ return MUST_OR_THROW_OOM(make_parts_list(vm, pattern->pattern, ::Locale::time_unit_to_string(time_unit), move(value_partitions)));
}
// 17.5.3 MakePartsList ( pattern, unit, parts ), https://tc39.es/ecma402/#sec-makepartslist
ThrowCompletionOr<Vector<PatternPartitionWithUnit>> make_parts_list(VM& vm, StringView pattern, StringView unit, Vector<PatternPartition> parts)
{
// 1. Let patternParts be PartitionPattern(pattern).
- 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<PatternPartitionWithUnit> result;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp
index 2381a3b575..0f59839606 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp
@@ -110,7 +110,7 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
// 9. Let localeData be %RelativeTimeFormat%.[[LocaleData]].
// 10. Let r be ResolveLocale(%RelativeTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %RelativeTimeFormat%.[[RelevantExtensionKeys]], localeData).
- auto result = TRY(resolve_locale(vm, requested_locales, opt, RelativeTimeFormat::relevant_extension_keys()));
+ auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, RelativeTimeFormat::relevant_extension_keys()));
// 11. Let locale be r.[[locale]].
auto locale = move(result.locale);