LibJS: Stop propagating small OOM errors from Intl abstract operations

This commit is contained in:
Timothy Flynn 2023-08-30 11:08:15 -04:00 committed by Andreas Kling
parent c24d317d8f
commit b6ff25bd26
Notes: sideshowbarker 2024-07-17 01:11:48 +09:00
18 changed files with 74 additions and 73 deletions

View File

@ -20,7 +20,7 @@
namespace JS::Intl {
// 6.2.2 IsStructurallyValidLanguageTag ( locale ), https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag
ThrowCompletionOr<Optional<::Locale::LocaleID>> is_structurally_valid_language_tag(VM& vm, StringView locale)
Optional<::Locale::LocaleID> is_structurally_valid_language_tag(StringView locale)
{
auto contains_duplicate_variant = [&](auto& variants) {
if (variants.is_empty())
@ -41,16 +41,16 @@ ThrowCompletionOr<Optional<::Locale::LocaleID>> is_structurally_valid_language_t
// locale can be generated from the EBNF grammar for unicode_locale_id in Unicode Technical Standard #35 LDML § 3.2 Unicode Locale Identifier;
auto locale_id = ::Locale::parse_unicode_locale_id(locale);
if (!locale_id.has_value())
return OptionalNone {};
return {};
// locale does not use any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance;
// https://unicode.org/reports/tr35/#BCP_47_Conformance
if (locale.contains('_') || locale_id->language_id.is_root || !locale_id->language_id.language.has_value())
return OptionalNone {};
return {};
// the unicode_language_id within locale contains no duplicate unicode_variant_subtag subtags; and
if (contains_duplicate_variant(locale_id->language_id.variants))
return OptionalNone {};
return {};
// if locale contains an extensions* component, that component
Vector<char> unique_keys;
@ -64,16 +64,16 @@ ThrowCompletionOr<Optional<::Locale::LocaleID>> is_structurally_valid_language_t
[](::Locale::OtherExtension const& ext) { return static_cast<char>(to_ascii_lowercase(ext.key)); });
if (unique_keys.contains_slow(key))
return OptionalNone {};
return {};
TRY_OR_THROW_OOM(vm, unique_keys.try_append(key));
unique_keys.append(key);
// if a transformed_extensions component that contains a tlang component is present, then
// the tlang component contains no duplicate unicode_variant_subtag subtags.
if (auto* transformed = extension.get_pointer<::Locale::TransformedExtension>()) {
auto& language = transformed->language;
if (language.has_value() && contains_duplicate_variant(language->variants))
return Optional<::Locale::LocaleID> {};
return {};
}
}
@ -81,7 +81,7 @@ ThrowCompletionOr<Optional<::Locale::LocaleID>> is_structurally_valid_language_t
}
// 6.2.3 CanonicalizeUnicodeLocaleId ( locale ), https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid
ThrowCompletionOr<String> canonicalize_unicode_locale_id(VM& vm, ::Locale::LocaleID& locale)
String canonicalize_unicode_locale_id(::Locale::LocaleID& locale)
{
// Note: This implementation differs from the spec in how Step 3 is implemented. The spec assumes
// the input to this method is a string, and is written such that operations are performed on parts
@ -101,13 +101,13 @@ ThrowCompletionOr<String> canonicalize_unicode_locale_id(VM& vm, ::Locale::Local
auto attributes = move(locale_extension.attributes);
for (auto& attribute : attributes) {
if (!locale_extension.attributes.contains_slow(attribute))
TRY_OR_THROW_OOM(vm, locale_extension.attributes.try_append(move(attribute)));
locale_extension.attributes.append(move(attribute));
}
auto keywords = move(locale_extension.keywords);
for (auto& keyword : keywords) {
if (!any_of(locale_extension.keywords, [&](auto const& k) { return k.key == keyword.key; }))
TRY_OR_THROW_OOM(vm, locale_extension.keywords.try_append(move(keyword)));
locale_extension.keywords.append(move(keyword));
}
break;
@ -245,16 +245,16 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM& vm, Value locales
}
// v. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
auto locale_id = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, tag));
auto locale_id = is_structurally_valid_language_tag(tag);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
// vi. Let canonicalizedTag be ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*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))
TRY_OR_THROW_OOM(vm, seen.try_append(move(canonicalized_tag)));
seen.append(move(canonicalized_tag));
}
// d. Increase k by 1.
@ -295,7 +295,7 @@ struct MatcherResult {
};
// 9.2.3 LookupMatcher ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-lookupmatcher
static ThrowCompletionOr<MatcherResult> lookup_matcher(VM& vm, Vector<String> const& requested_locales)
static MatcherResult lookup_matcher(Vector<String> const& requested_locales)
{
// 1. Let result be a new Record.
MatcherResult result {};
@ -315,7 +315,7 @@ static ThrowCompletionOr<MatcherResult> lookup_matcher(VM& vm, Vector<String> co
// c. If availableLocale is not undefined, then
if (available_locale.has_value()) {
// i. Set result.[[locale]] to availableLocale.
result.locale = TRY_OR_THROW_OOM(vm, String::from_utf8(*available_locale));
result.locale = MUST(String::from_utf8(*available_locale));
// ii. If locale and noExtensionsLocale are not the same String value, then
if (locale != no_extensions_locale) {
@ -331,29 +331,30 @@ static ThrowCompletionOr<MatcherResult> lookup_matcher(VM& vm, Vector<String> co
// 3. Let defLocale be ! DefaultLocale().
// 4. Set result.[[locale]] to defLocale.
result.locale = TRY_OR_THROW_OOM(vm, String::from_utf8(::Locale::default_locale()));
result.locale = MUST(String::from_utf8(::Locale::default_locale()));
// 5. Return result.
return result;
}
// 9.2.4 BestFitMatcher ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-bestfitmatcher
static ThrowCompletionOr<MatcherResult> best_fit_matcher(VM& vm, Vector<String> const& requested_locales)
static MatcherResult best_fit_matcher(Vector<String> const& requested_locales)
{
// The algorithm is implementation dependent, but should produce results that a typical user of the requested locales would
// perceive as at least as good as those produced by the LookupMatcher abstract operation.
return lookup_matcher(vm, requested_locales);
return lookup_matcher(requested_locales);
}
// 9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, extension ), https://tc39.es/ecma402/#sec-insert-unicode-extension-and-canonicalize
ThrowCompletionOr<String> insert_unicode_extension_and_canonicalize(VM& vm, ::Locale::LocaleID locale, ::Locale::LocaleExtension extension)
String insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale, ::Locale::LocaleExtension extension)
{
// Note: This implementation differs from the spec in how the extension is inserted. The spec assumes
// the input to this method is a string, and is written such that operations are performed on parts
// 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 MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, locale));
locale.extensions.append(move(extension));
return JS::Intl::canonicalize_unicode_locale_id(locale);
}
template<typename T>
@ -377,7 +378,7 @@ static auto& find_key_in_value(T& value, StringView key)
}
// 9.2.7 ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData ), https://tc39.es/ecma402/#sec-resolvelocale
ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys)
LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys)
{
// 1. Let matcher be options.[[localeMatcher]].
auto const& matcher = options.locale_matcher;
@ -386,12 +387,12 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// 2. If matcher is "lookup", then
if (matcher.is_string() && (matcher.as_string().utf8_string_view()) == "lookup"sv) {
// a. Let r be ! LookupMatcher(availableLocales, requestedLocales).
matcher_result = MUST_OR_THROW_OOM(lookup_matcher(vm, requested_locales));
matcher_result = lookup_matcher(requested_locales);
}
// 3. Else,
else {
// a. Let r be ! BestFitMatcher(availableLocales, requestedLocales).
matcher_result = MUST_OR_THROW_OOM(best_fit_matcher(vm, requested_locales));
matcher_result = best_fit_matcher(requested_locales);
}
// 4. Let foundLocale be r.[[locale]].
@ -434,7 +435,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// alphabetically, so we get the locale's preferred value from LibUnicode.
Optional<String> value;
if (auto preference = ::Locale::get_preferred_keyword_value_for_locale(found_locale, key); preference.has_value())
value = TRY_OR_THROW_OOM(vm, String::from_utf8(*preference));
value = MUST(String::from_utf8(*preference));
// g. Let supportedExtensionAddition be "".
Optional<::Locale::Keyword> supported_extension_addition {};
@ -457,7 +458,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
value = move(requested_value);
// ii. Let supportedExtensionAddition be the string-concatenation of "-", key, "-", and value.
supported_extension_addition = ::Locale::Keyword { TRY_OR_THROW_OOM(vm, String::from_utf8(key)), move(entry.value) };
supported_extension_addition = ::Locale::Keyword { MUST(String::from_utf8(key)), move(entry.value) };
}
}
// 4. Else if keyLocaleData contains "true", then
@ -466,7 +467,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
value = "true"_string;
// b. Let supportedExtensionAddition be the string-concatenation of "-" and key.
supported_extension_addition = ::Locale::Keyword { TRY_OR_THROW_OOM(vm, String::from_utf8(key)), {} };
supported_extension_addition = ::Locale::Keyword { MUST(String::from_utf8(key)), {} };
}
break;
@ -504,7 +505,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// k. Set supportedExtension to the string-concatenation of supportedExtension and supportedExtensionAddition.
if (supported_extension_addition.has_value())
TRY_OR_THROW_OOM(vm, supported_extension.keywords.try_append(supported_extension_addition.release_value()));
supported_extension.keywords.append(supported_extension_addition.release_value());
}
// 10. If supportedExtension is not "-u", then
@ -513,7 +514,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 = MUST_OR_THROW_OOM(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(supported_extension)));
found_locale = insert_unicode_extension_and_canonicalize(locale_id.release_value(), move(supported_extension));
}
// 11. Set result.[[locale]] to foundLocale.
@ -524,7 +525,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
}
// 9.2.8 LookupSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-lookupsupportedlocales
static ThrowCompletionOr<Vector<String>> lookup_supported_locales(VM& vm, Vector<String> const& requested_locales)
static Vector<String> lookup_supported_locales(Vector<String> const& requested_locales)
{
// 1. Let subset be a new empty List.
Vector<String> subset;
@ -543,7 +544,7 @@ static ThrowCompletionOr<Vector<String>> lookup_supported_locales(VM& vm, Vector
// c. If availableLocale is not undefined, append locale to the end of subset.
if (available_locale.has_value())
TRY_OR_THROW_OOM(vm, subset.try_append(locale));
subset.append(locale);
}
// 3. Return subset.
@ -551,7 +552,7 @@ static ThrowCompletionOr<Vector<String>> lookup_supported_locales(VM& vm, Vector
}
// 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-bestfitsupportedlocales
static ThrowCompletionOr<Vector<String>> best_fit_supported_locales(VM& vm, Vector<String> const& requested_locales)
static Vector<String> best_fit_supported_locales(Vector<String> const& requested_locales)
{
// The BestFitSupportedLocales abstract operation returns the subset of the provided BCP 47
// language priority list requestedLocales for which availableLocales has a matching locale
@ -559,7 +560,7 @@ static ThrowCompletionOr<Vector<String>> best_fit_supported_locales(VM& vm, Vect
// list as in requestedLocales. The steps taken are implementation dependent.
// :yakbrain:
return lookup_supported_locales(vm, requested_locales);
return lookup_supported_locales(requested_locales);
}
// 9.2.10 SupportedLocales ( availableLocales, requestedLocales, options ), https://tc39.es/ecma402/#sec-supportedlocales
@ -578,12 +579,12 @@ ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<String> const& reques
// 3. If matcher is "best fit", then
if (matcher.as_string().utf8_string_view() == "best fit"sv) {
// a. Let supportedLocales be BestFitSupportedLocales(availableLocales, requestedLocales).
supported_locales = TRY(best_fit_supported_locales(vm, requested_locales));
supported_locales = best_fit_supported_locales(requested_locales);
}
// 4. Else,
else {
// a. Let supportedLocales be LookupSupportedLocales(availableLocales, requestedLocales).
supported_locales = TRY(lookup_supported_locales(vm, requested_locales));
supported_locales = lookup_supported_locales(requested_locales);
}
// 5. Return CreateArrayFromList(supportedLocales).
@ -668,7 +669,7 @@ ThrowCompletionOr<Optional<int>> get_number_option(VM& vm, Object const& options
}
// 9.2.17 PartitionPattern ( pattern ), https://tc39.es/ecma402/#sec-partitionpattern
ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM& vm, StringView pattern)
Vector<PatternPartition> partition_pattern(StringView pattern)
{
// 1. Let result be a new empty List.
Vector<PatternPartition> result;
@ -697,14 +698,14 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM& vm, StringView
auto literal = pattern.substring_view(next_index, *begin_index - next_index);
// ii. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(literal)) }));
result.append({ "literal"sv, MUST(String::from_utf8(literal)) });
}
// d. Let p be the substring of pattern from position beginIndex, exclusive, to position endIndex, exclusive.
auto partition = pattern.substring_view(*begin_index + 1, end_index - *begin_index - 1);
// e. Append a new Record { [[Type]]: p, [[Value]]: undefined } as the last element of the list result.
TRY_OR_THROW_OOM(vm, result.try_append({ partition, {} }));
result.append({ partition, {} });
// f. Set nextIndex to endIndex + 1.
next_index = end_index + 1;
@ -719,7 +720,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM& vm, StringView
auto literal = pattern.substring_view(next_index);
// b. Append a new Record { [[Type]]: "literal", [[Value]]: literal } as the last element of the list result.
TRY_OR_THROW_OOM(vm, result.try_append({ "literal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(literal)) }));
result.append({ "literal"sv, MUST(String::from_utf8(literal)) });
}
// 8. Return result.

View File

@ -56,10 +56,10 @@ struct PatternPartition {
};
struct PatternPartitionWithSource : public PatternPartition {
static ThrowCompletionOr<Vector<PatternPartitionWithSource>> create_from_parent_list(VM& vm, Vector<PatternPartition> partitions)
static Vector<PatternPartitionWithSource> create_from_parent_list(Vector<PatternPartition> partitions)
{
Vector<PatternPartitionWithSource> result;
TRY_OR_THROW_OOM(vm, result.try_ensure_capacity(partitions.size()));
result.ensure_capacity(partitions.size());
for (auto& partition : partitions) {
PatternPartitionWithSource partition_with_source {};
@ -81,20 +81,20 @@ struct PatternPartitionWithSource : public PatternPartition {
using StringOrBoolean = Variant<StringView, bool>;
ThrowCompletionOr<Optional<::Locale::LocaleID>> is_structurally_valid_language_tag(VM&, StringView locale);
ThrowCompletionOr<String> canonicalize_unicode_locale_id(VM&, ::Locale::LocaleID& locale);
Optional<::Locale::LocaleID> is_structurally_valid_language_tag(StringView locale);
String canonicalize_unicode_locale_id(::Locale::LocaleID& locale);
bool is_well_formed_currency_code(StringView currency);
bool is_well_formed_unit_identifier(StringView unit_identifier);
ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM&, Value locales);
Optional<StringView> best_available_locale(StringView locale);
ThrowCompletionOr<String> insert_unicode_extension_and_canonicalize(VM&, ::Locale::LocaleID locale_id, ::Locale::LocaleExtension extension);
ThrowCompletionOr<LocaleResult> resolve_locale(VM&, Vector<String> const& requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys);
String insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale_id, ::Locale::LocaleExtension extension);
LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys);
ThrowCompletionOr<Array*> supported_locales(VM&, Vector<String> const& requested_locales, Value options);
ThrowCompletionOr<Object*> coerce_options_to_object(VM&, Value options);
ThrowCompletionOr<StringOrBoolean> get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, ReadonlySpan<StringView> string_values, StringOrBoolean fallback);
ThrowCompletionOr<Optional<int>> default_number_option(VM&, Value value, int minimum, int maximum, Optional<int> fallback);
ThrowCompletionOr<Optional<int>> get_number_option(VM&, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional<int> fallback);
ThrowCompletionOr<Vector<PatternPartition>> partition_pattern(VM&, StringView pattern);
Vector<PatternPartition> partition_pattern(StringView pattern);
template<size_t Size>
ThrowCompletionOr<StringOrBoolean> get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&string_values)[Size], StringOrBoolean fallback)

View File

@ -75,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 = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, relevant_extension_keys));
auto result = resolve_locale(requested_locales, opt, relevant_extension_keys);
// 20. Set collator.[[Locale]] to r.[[locale]].
collator.set_locale(move(result.locale));

View File

@ -741,7 +741,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 = MUST_OR_THROW_OOM(partition_pattern(vm, date_time_format.pattern()));
auto pattern_parts = partition_pattern(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));
@ -988,11 +988,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
auto const& pattern = date_time_format.pattern();
// b. Let patternParts be PartitionPattern(pattern).
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
auto pattern_parts = partition_pattern(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));
auto result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_result)));
auto result = PatternPartitionWithSource::create_from_parent_list(move(raw_result));
// d. For each Record { [[Type]], [[Value]] } r in result, do
for (auto& part : result) {
@ -1045,11 +1045,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
auto time = ((source == "startRange") || (source == "shared")) ? start : end;
// e. Let patternParts be PartitionPattern(pattern).
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
auto pattern_parts = partition_pattern(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()));
auto part_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_part_result)));
auto part_result = PatternPartitionWithSource::create_from_parent_list(move(raw_part_result));
// g. For each Record { [[Type]], [[Value]] } r in partResult, do
for (auto& part : part_result) {

View File

@ -144,7 +144,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 17. Let localeData be %DateTimeFormat%.[[LocaleData]].
// 18. Let r be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]], localeData).
auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, DateTimeFormat::relevant_extension_keys()));
auto result = resolve_locale(requested_locales, opt, DateTimeFormat::relevant_extension_keys());
// 19. Set dateTimeFormat.[[Locale]] to r.[[locale]].
date_time_format->set_locale(move(result.locale));

View File

@ -110,12 +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 = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, code));
auto locale_id = is_structurally_valid_language_tag(code);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, code);
// c. Return ! CanonicalizeUnicodeLocaleId(code).
auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
return PrimitiveString::create(vm, move(canonicalized_tag));
}

View File

@ -76,7 +76,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DisplayNamesConstructor::construct(Funct
opt.locale_matcher = matcher;
// 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]).
auto result = TRY(resolve_locale(vm, requested_locales, opt, {}));
auto result = resolve_locale(requested_locales, opt, {});
// 11. Let style be ? GetOption(options, "style", string, « "narrow", "short", "long" », "long").
auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv));

View File

@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
break;
}
if (auto locale = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, code_string)); locale.has_value())
if (auto locale = is_structurally_valid_language_tag(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

@ -77,7 +77,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
opt.nu = numbering_system.is_undefined() ? Optional<String>() : numbering_system.as_string().utf8_string();
// 9. Let r be ResolveLocale(%DurationFormat%.[[AvailableLocales]], requestedLocales, opt, %DurationFormat%.[[RelevantExtensionKeys]], %DurationFormat%.[[LocaleData]]).
auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, DurationFormat::relevant_extension_keys()));
auto result = resolve_locale(requested_locales, opt, DurationFormat::relevant_extension_keys());
// 10. Let locale be r.[[locale]].
auto locale = move(result.locale);

View File

@ -49,7 +49,7 @@ StringView ListFormat::type_string() const
ThrowCompletionOr<Vector<PatternPartition>> deconstruct_pattern(VM& vm, StringView pattern, Placeables placeables)
{
// 1. Let patternParts be ! PartitionPattern(pattern).
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
auto pattern_parts = partition_pattern(pattern);
// 2. Let result be a new empty List.
Vector<PatternPartition> result {};

View File

@ -71,7 +71,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ListFormatConstructor::construct(Functio
// 8. Let localeData be %ListFormat%.[[LocaleData]].
// 9. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]], requestedLocales, opt, %ListFormat%.[[RelevantExtensionKeys]], localeData).
auto result = TRY(resolve_locale(vm, requested_locales, opt, {}));
auto result = resolve_locale(requested_locales, opt, {});
// 10. Set listFormat.[[Locale]] to r.[[locale]].
list_format->set_locale(move(result.locale));

View File

@ -46,7 +46,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 = MUST_OR_THROW_OOM(is_structurally_valid_language_tag(vm, tag));
auto locale_id = is_structurally_valid_language_tag(tag);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
@ -66,7 +66,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).
auto canonicalized_tag = MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
// 11. Assert: tag matches the unicode_locale_id production.
locale_id = ::Locale::parse_unicode_locale_id(canonicalized_tag);
@ -101,7 +101,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 MUST_OR_THROW_OOM(canonicalize_unicode_locale_id(vm, *locale_id));
return JS::Intl::canonicalize_unicode_locale_id(*locale_id);
}
// 14.1.3 ApplyUnicodeExtensionToTag ( tag, options, relevantExtensionKeys ), https://tc39.es/ecma402/#sec-apply-unicode-extension-to-tag
@ -206,7 +206,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 = MUST_OR_THROW_OOM(insert_unicode_extension_and_canonicalize(vm, locale_id.release_value(), move(new_extension)));
locale = insert_unicode_extension_and_canonicalize(locale_id.release_value(), move(new_extension));
}
// 10. Set result.[[locale]] to locale.

View File

@ -593,7 +593,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
Vector<PatternPartition> result;
// 8. Let patternParts be PartitionPattern(pattern).
auto pattern_parts = MUST_OR_THROW_OOM(pattern->visit([&](auto const& p) { return partition_pattern(vm, p); }));
auto pattern_parts = pattern->visit([](auto const& p) { return partition_pattern(p); });
// 9. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do
for (auto& pattern_part : pattern_parts) {
@ -766,7 +766,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
return Vector<PatternPartition> {};
// b. Let patternParts be PartitionPattern(notationSubPattern).
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, *notation_sub_pattern));
auto pattern_parts = partition_pattern(*notation_sub_pattern);
// c. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do
for (auto& pattern_part : pattern_parts) {
@ -1812,11 +1812,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
// 3. Let xResult be ? PartitionNumberPattern(numberFormat, x).
auto raw_start_result = TRY(partition_number_pattern(vm, number_format, move(start)));
auto start_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_start_result)));
auto start_result = PatternPartitionWithSource::create_from_parent_list(move(raw_start_result));
// 4. Let yResult be ? PartitionNumberPattern(numberFormat, y).
auto raw_end_result = TRY(partition_number_pattern(vm, number_format, move(end)));
auto end_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_end_result)));
auto end_result = PatternPartitionWithSource::create_from_parent_list(move(raw_end_result));
// 5. If ! FormatNumeric(numberFormat, x) is equal to ! FormatNumeric(numberFormat, y), then
auto formatted_start = MUST_OR_THROW_OOM(format_numeric(vm, number_format, start));

View File

@ -111,7 +111,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 = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, NumberFormat::relevant_extension_keys()));
auto result = resolve_locale(requested_locales, opt, NumberFormat::relevant_extension_keys());
// 11. Set numberFormat.[[Locale]] to r.[[locale]].
number_format.set_locale(move(result.locale));

View File

@ -101,7 +101,7 @@ ThrowCompletionOr<PluralRules*> initialize_plural_rules(VM& vm, PluralRules& plu
// 9. Let localeData be %PluralRules%.[[LocaleData]].
// 10. Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]], requestedLocales, opt, %PluralRules%.[[RelevantExtensionKeys]], localeData).
auto result = TRY(resolve_locale(vm, requested_locales, opt, {}));
auto result = resolve_locale(requested_locales, opt, {});
// 11. Set pluralRules.[[Locale]] to r.[[locale]].
plural_rules.set_locale(move(result.locale));

View File

@ -194,7 +194,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
ThrowCompletionOr<Vector<PatternPartitionWithUnit>> make_parts_list(VM& vm, StringView pattern, StringView unit, Vector<PatternPartition> parts)
{
// 1. Let patternParts be PartitionPattern(pattern).
auto pattern_parts = MUST_OR_THROW_OOM(partition_pattern(vm, pattern));
auto pattern_parts = partition_pattern(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 = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, RelativeTimeFormat::relevant_extension_keys()));
auto result = resolve_locale(requested_locales, opt, RelativeTimeFormat::relevant_extension_keys());
// 11. Let locale be r.[[locale]].
auto locale = move(result.locale);

View File

@ -72,7 +72,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> SegmenterConstructor::construct(Function
// 9. Let localeData be %Segmenter%.[[LocaleData]].
// 10. Let r be ResolveLocale(%Segmenter%.[[AvailableLocales]], requestedLocales, opt, %Segmenter%.[[RelevantExtensionKeys]], localeData).
auto result = TRY(resolve_locale(vm, requested_locales, opt, {}));
auto result = resolve_locale(requested_locales, opt, {});
// 11. Set segmenter.[[Locale]] to r.[[locale]].
segmenter->set_locale(move(result.locale));