1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:28:11 +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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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