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

LibJS+LibLocale: Port remaining locale APIs to String

This commit is contained in:
Timothy Flynn 2023-01-21 10:04:12 -05:00 committed by Linus Groh
parent d73a143004
commit 20536897e4
6 changed files with 58 additions and 50 deletions

View file

@ -52,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 5. Let fields be displayNames.[[Fields]].
// 6. If fields has a field [[<code>]], return fields.[[<code>]].
Optional<StringView> result;
Optional<DeprecatedString> formatted_result;
Optional<String> formatted_result;
switch (display_names->type()) {
case DisplayNames::Type::Language:
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
}
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());
formatted_result = TRY_OR_THROW_OOM(vm, ::Locale::format_locale_for_display(display_names->locale(), locale.release_value()));
break;
case DisplayNames::Type::Region:
result = ::Locale::get_locale_territory_mapping(display_names->locale(), code_string);

View file

@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
VERIFY(locale.has_value());
// 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set maximal to loc.[[Locale]].
if (auto maximal = ::Locale::add_likely_subtags(locale->language_id); maximal.has_value())
if (auto maximal = TRY_OR_THROW_OOM(vm, ::Locale::add_likely_subtags(locale->language_id)); maximal.has_value())
locale->language_id = maximal.release_value();
// 4. Return ! Construct(%Locale%, maximal).
@ -85,7 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
VERIFY(locale.has_value());
// 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set minimal to loc.[[Locale]].
if (auto minimal = ::Locale::remove_likely_subtags(locale->language_id); minimal.has_value())
if (auto minimal = TRY_OR_THROW_OOM(vm, ::Locale::remove_likely_subtags(locale->language_id)); minimal.has_value())
locale->language_id = minimal.release_value();
// 4. Return ! Construct(%Locale%, minimal).