diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index 2c44ee867f7..511b3edfcbd 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -20,7 +20,7 @@ namespace JS::Intl { // 6.2.2 IsStructurallyValidLanguageTag ( locale ), https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag -ThrowCompletionOr> 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> 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 unique_keys; @@ -64,16 +64,16 @@ ThrowCompletionOr> is_structurally_valid_language_t [](::Locale::OtherExtension const& ext) { return static_cast(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> is_structurally_valid_language_t } // 6.2.3 CanonicalizeUnicodeLocaleId ( locale ), https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid -ThrowCompletionOr 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 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> 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(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 lookup_matcher(VM& vm, Vector const& requested_locales) +static MatcherResult lookup_matcher(Vector const& requested_locales) { // 1. Let result be a new Record. MatcherResult result {}; @@ -315,7 +315,7 @@ static ThrowCompletionOr lookup_matcher(VM& vm, Vector 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 lookup_matcher(VM& vm, Vector 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 best_fit_matcher(VM& vm, Vector const& requested_locales) +static MatcherResult best_fit_matcher(Vector 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 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 @@ -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 resolve_locale(VM& vm, Vector const& requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys) +LocaleResult resolve_locale(Vector const& requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys) { // 1. Let matcher be options.[[localeMatcher]]. auto const& matcher = options.locale_matcher; @@ -386,12 +387,12 @@ ThrowCompletionOr resolve_locale(VM& vm, Vector 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 resolve_locale(VM& vm, Vector const& req // alphabetically, so we get the locale's preferred value from LibUnicode. Optional 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 resolve_locale(VM& vm, Vector 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 resolve_locale(VM& vm, Vector 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 resolve_locale(VM& vm, Vector 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 resolve_locale(VM& vm, Vector 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 resolve_locale(VM& vm, Vector const& req } // 9.2.8 LookupSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-lookupsupportedlocales -static ThrowCompletionOr> lookup_supported_locales(VM& vm, Vector const& requested_locales) +static Vector lookup_supported_locales(Vector const& requested_locales) { // 1. Let subset be a new empty List. Vector subset; @@ -543,7 +544,7 @@ static ThrowCompletionOr> 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> lookup_supported_locales(VM& vm, Vector } // 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales ), https://tc39.es/ecma402/#sec-bestfitsupportedlocales -static ThrowCompletionOr> best_fit_supported_locales(VM& vm, Vector const& requested_locales) +static Vector best_fit_supported_locales(Vector 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> 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 supported_locales(VM& vm, Vector 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> get_number_option(VM& vm, Object const& options } // 9.2.17 PartitionPattern ( pattern ), https://tc39.es/ecma402/#sec-partitionpattern -ThrowCompletionOr> partition_pattern(VM& vm, StringView pattern) +Vector partition_pattern(StringView pattern) { // 1. Let result be a new empty List. Vector result; @@ -697,14 +698,14 @@ ThrowCompletionOr> 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> 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. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h index b6e7b6a6271..a4a3e1a0208 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h @@ -56,10 +56,10 @@ struct PatternPartition { }; struct PatternPartitionWithSource : public PatternPartition { - static ThrowCompletionOr> create_from_parent_list(VM& vm, Vector partitions) + static Vector create_from_parent_list(Vector partitions) { Vector 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; -ThrowCompletionOr> is_structurally_valid_language_tag(VM&, StringView locale); -ThrowCompletionOr 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> canonicalize_locale_list(VM&, Value locales); Optional best_available_locale(StringView locale); -ThrowCompletionOr insert_unicode_extension_and_canonicalize(VM&, ::Locale::LocaleID locale_id, ::Locale::LocaleExtension extension); -ThrowCompletionOr resolve_locale(VM&, Vector const& requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys); +String insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale_id, ::Locale::LocaleExtension extension); +LocaleResult resolve_locale(Vector const& requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys); ThrowCompletionOr supported_locales(VM&, Vector const& requested_locales, Value options); ThrowCompletionOr coerce_options_to_object(VM&, Value options); ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, ReadonlySpan string_values, StringOrBoolean fallback); ThrowCompletionOr> default_number_option(VM&, Value value, int minimum, int maximum, Optional fallback); ThrowCompletionOr> get_number_option(VM&, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional fallback); -ThrowCompletionOr> partition_pattern(VM&, StringView pattern); +Vector partition_pattern(StringView pattern); template ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&string_values)[Size], StringOrBoolean fallback) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp index 43c041f5828..ed3cb02c6b3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp @@ -75,7 +75,7 @@ static ThrowCompletionOr 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index 4a2e8aaddb5..8b3161a60c8 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -741,7 +741,7 @@ ThrowCompletionOr> format_date_time_pattern(VM& vm, Dat ThrowCompletionOr> 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> 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> 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) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp index ce2f3ad2c8a..4ba6eb3bf87 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp @@ -144,7 +144,7 @@ ThrowCompletionOr> 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp index 7c10ce70f66..f928d527ae0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp @@ -110,12 +110,12 @@ ThrowCompletionOr canonical_code_for_display_names(VM& vm, DisplayNames:: return vm.throw_completion(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(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)); } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp index 33ff5c332f2..db76370da8a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp @@ -76,7 +76,7 @@ ThrowCompletionOr> 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp index 59583839519..ab77ea05872 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 = 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: diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp index 34e2d2a70a5..429ec49616d 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp @@ -77,7 +77,7 @@ ThrowCompletionOr> DurationFormatConstructor::construct(Fun opt.nu = numbering_system.is_undefined() ? Optional() : 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); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index 255ef83f474..fec8c210001 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -49,7 +49,7 @@ StringView ListFormat::type_string() const ThrowCompletionOr> 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 result {}; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp index f14ceb083b4..04548407d66 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp @@ -71,7 +71,7 @@ ThrowCompletionOr> 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp index b5c3ce9f745..b4cc2ac2dbb 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp @@ -46,7 +46,7 @@ static ThrowCompletionOr 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(ErrorType::IntlInvalidLanguageTag, tag); @@ -66,7 +66,7 @@ static ThrowCompletionOr 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 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 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. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index 94b91bf3b51..fd46afd6db0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -593,7 +593,7 @@ ThrowCompletionOr> partition_number_pattern(VM& vm, Num Vector 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> partition_notation_sub_pattern(VM& v return Vector {}; // 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> 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp index 9990c5ba02c..a150a6871cc 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp @@ -111,7 +111,7 @@ ThrowCompletionOr 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp index dfb0a27b79d..5f971dd1ee5 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp @@ -101,7 +101,7 @@ ThrowCompletionOr 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)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index 54a7089f656..be5e136261b 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -194,7 +194,7 @@ ThrowCompletionOr> partition_relative_time_patt ThrowCompletionOr> make_parts_list(VM& vm, StringView pattern, StringView unit, Vector 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 result; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp index 231ada34154..ef8dc574237 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp @@ -110,7 +110,7 @@ ThrowCompletionOr 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); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp index 10d9cf32fa0..5320274e87a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp @@ -72,7 +72,7 @@ ThrowCompletionOr> 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));