summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-19 10:53:20 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-19 20:57:30 +0000
commitca62aeb6bd184adb2644e5d179f60cb3a42171b4 (patch)
tree33230228acafff94573e17adad17025b405a9dcb /Userland/Libraries/LibJS/Runtime
parent618714e29ab8669700c3b690afb1ebce3540956f (diff)
downloadserenity-ca62aeb6bd184adb2644e5d179f60cb3a42171b4.zip
LibLocale+LibJS: Port locale parsing and processing to String
In order to prevent this commit from having to refactor almost all of Intl, the goal here is to update the internal parsing/canonicalization of locales within LibLocale only. Call sites which are already equiped to handle String and OOM errors do so, however.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp24
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp51
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp20
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp4
6 files changed, 63 insertions, 60 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
index c5bc4ba8cc..b3a386ff58 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp
@@ -29,7 +29,7 @@ Optional<::Locale::LocaleID> is_structurally_valid_language_tag(StringView local
quick_sort(variants);
for (size_t i = 0; i < variants.size() - 1; ++i) {
- if (variants[i].equals_ignoring_case(variants[i + 1]))
+ if (variants[i].equals_ignoring_case(variants[i + 1]).release_value_but_fixme_should_propagate_errors())
return true;
}
@@ -39,7 +39,7 @@ Optional<::Locale::LocaleID> is_structurally_valid_language_tag(StringView local
// IsStructurallyValidLanguageTag returns true if all of the following conditions hold, false otherwise:
// 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);
+ auto locale_id = ::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors();
if (!locale_id.has_value())
return {};
@@ -114,11 +114,11 @@ DeprecatedString canonicalize_unicode_locale_id(::Locale::LocaleID& locale)
// 1. Let localeId be the string locale after performing the algorithm to transform it to canonical syntax per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers.
// 2. Let localeId be the string localeId after performing the algorithm to transform it to canonical form.
- auto locale_id = ::Locale::canonicalize_unicode_locale_id(locale);
+ auto locale_id = ::Locale::canonicalize_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors();
VERIFY(locale_id.has_value());
// 4. Return localeId.
- return locale_id.release_value();
+ return locale_id->to_deprecated_string();
}
// 6.3.1 IsWellFormedCurrencyCode ( currency ), https://tc39.es/ecma402/#sec-iswellformedcurrencycode
@@ -301,7 +301,7 @@ static MatcherResult lookup_matcher(Vector<DeprecatedString> const& requested_lo
// 2. For each element locale of requestedLocales, do
for (auto const& locale : requested_locales) {
- auto locale_id = ::Locale::parse_unicode_locale_id(locale);
+ auto locale_id = ::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors();
VERIFY(locale_id.has_value());
// a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed.
@@ -453,10 +453,10 @@ ThrowCompletionOr<LocaleResult> resolve_locale(Vector<DeprecatedString> const& r
// a. If keyLocaleData contains requestedValue, then
if (key_locale_data.contains_slow(requested_value)) {
// i. Let value be requestedValue.
- value = move(requested_value);
+ value = requested_value.to_deprecated_string();
// ii. Let supportedExtensionAddition be the string-concatenation of "-", key, "-", and value.
- supported_extension_addition = ::Locale::Keyword { key, move(entry.value) };
+ supported_extension_addition = ::Locale::Keyword { String::from_utf8(key).release_value_but_fixme_should_propagate_errors(), move(entry.value) };
}
}
// 4. Else if keyLocaleData contains "true", then
@@ -465,7 +465,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(Vector<DeprecatedString> const& r
value = "true"sv;
// b. Let supportedExtensionAddition be the string-concatenation of "-" and key.
- supported_extension_addition = ::Locale::Keyword { key, {} };
+ supported_extension_addition = ::Locale::Keyword { String::from_utf8(key).release_value_but_fixme_should_propagate_errors(), {} };
}
break;
@@ -480,7 +480,9 @@ ThrowCompletionOr<LocaleResult> resolve_locale(Vector<DeprecatedString> const& r
if (options_value.has_value()) {
// 1. Let optionsValue be the string optionsValue after performing the algorithm steps to transform Unicode extension values to canonical syntax per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions.
// 2. Let optionsValue be the string optionsValue after performing the algorithm steps to replace Unicode extension values with their canonical form per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions.
- ::Locale::canonicalize_unicode_extension_values(key, *options_value, true);
+ auto options_value_string = String::from_deprecated_string(*options_value).release_value_but_fixme_should_propagate_errors();
+ ::Locale::canonicalize_unicode_extension_values(key, options_value_string, true).release_value_but_fixme_should_propagate_errors();
+ options_value = options_value_string.to_deprecated_string();
// 3. If optionsValue is the empty String, then
if (options_value->is_empty()) {
@@ -508,7 +510,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(Vector<DeprecatedString> const& r
// 10. If supportedExtension is not "-u", then
if (!supported_extension.keywords.is_empty()) {
- auto locale_id = ::Locale::parse_unicode_locale_id(found_locale);
+ auto locale_id = ::Locale::parse_unicode_locale_id(found_locale).release_value_but_fixme_should_propagate_errors();
VERIFY(locale_id.has_value());
// a. Set foundLocale to InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedExtension).
@@ -530,7 +532,7 @@ Vector<DeprecatedString> lookup_supported_locales(Vector<DeprecatedString> const
// 2. For each element locale of requestedLocales, do
for (auto const& locale : requested_locales) {
- auto locale_id = ::Locale::parse_unicode_locale_id(locale);
+ auto locale_id = ::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors();
VERIFY(locale_id.has_value());
// a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
index f928d527ae..05443188f1 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
@@ -106,7 +106,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// 1. If type is "language", then
if (type == DisplayNames::Type::Language) {
// a. If code does not match the unicode_language_id production, throw a RangeError exception.
- if (!::Locale::parse_unicode_language_id(code).has_value())
+ if (!TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_language_id(code)).has_value())
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "language"sv);
// b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception.
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
index 5dfa3ee110..9143ad0ff5 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
@@ -36,17 +36,17 @@ Locale::Locale(::Locale::LocaleID const& locale_id, Object& prototype)
for (auto const& keyword : extension.get<::Locale::LocaleExtension>().keywords) {
if (keyword.key == "ca"sv) {
- set_calendar(keyword.value);
+ set_calendar(keyword.value.to_deprecated_string());
} else if (keyword.key == "co"sv) {
- set_collation(keyword.value);
+ set_collation(keyword.value.to_deprecated_string());
} else if (keyword.key == "hc"sv) {
- set_hour_cycle(keyword.value);
+ set_hour_cycle(keyword.value.to_deprecated_string());
} else if (keyword.key == "kf"sv) {
- set_case_first(keyword.value);
+ set_case_first(keyword.value.to_deprecated_string());
} else if (keyword.key == "kn"sv) {
set_numeric(keyword.value.is_empty());
} else if (keyword.key == "nu"sv) {
- set_numbering_system(keyword.value);
+ set_numbering_system(keyword.value.to_deprecated_string());
}
}
@@ -81,7 +81,7 @@ Array* calendars_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical calendar identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "ca"sv);
@@ -100,7 +100,7 @@ Array* collations_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical collation identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, ordered as if an Array of the same values had been sorted, using %Array.prototype.sort% using undefined as comparefn, of those in common use for string comparison in locale. The values "standard" and "search" must be excluded from list.
auto list = ::Locale::get_keywords_for_locale(locale, "co"sv);
@@ -119,7 +119,7 @@ Array* hour_cycles_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format ("h11", "h12") or the 24-hour format ("h23", "h24"), sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "hc"sv);
@@ -138,7 +138,7 @@ Array* numbering_systems_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical numbering system identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for formatting numeric values in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "nu"sv);
@@ -174,7 +174,7 @@ StringView character_direction_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 3. If the default general ordering of characters (characterOrder) within a line in locale is right-to-left, return "rtl".
// NOTE: LibUnicode handles both LTR and RTL character orders in this call, not just RTL. We then fallback to LTR
@@ -235,7 +235,7 @@ WeekInfo week_info_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production.
- VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
+ VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 3. Return a record whose fields are defined by Table 1, with values based on locale.
WeekInfo week_info {};
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
index 307b64b98e..403890276d 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
@@ -6,6 +6,7 @@
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
+#include <AK/String.h>
#include <AK/TypeCasts.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/GlobalObject.h>
@@ -17,26 +18,26 @@
namespace JS::Intl {
struct LocaleAndKeys {
- DeprecatedString locale;
- Optional<DeprecatedString> ca;
- Optional<DeprecatedString> co;
- Optional<DeprecatedString> hc;
- Optional<DeprecatedString> kf;
- Optional<DeprecatedString> kn;
- Optional<DeprecatedString> nu;
+ String locale;
+ Optional<String> ca;
+ Optional<String> co;
+ Optional<String> hc;
+ Optional<String> kf;
+ Optional<String> kn;
+ Optional<String> nu;
};
// Note: This is not an AO in the spec. This just serves to abstract very similar steps in ApplyOptionsToTag and the Intl.Locale constructor.
-static ThrowCompletionOr<Optional<DeprecatedString>> get_string_option(VM& vm, Object const& options, PropertyKey const& property, Function<bool(StringView)> validator, Span<StringView const> values = {})
+static ThrowCompletionOr<Optional<String>> get_string_option(VM& vm, Object const& options, PropertyKey const& property, Function<bool(StringView)> validator, Span<StringView const> values = {})
{
auto option = TRY(get_option(vm, options, property, OptionType::String, values, Empty {}));
if (option.is_undefined())
- return Optional<DeprecatedString> {};
+ return Optional<String> {};
if (validator && !validator(TRY(option.as_string().utf8_string_view())))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, option, property);
- return TRY(option.as_string().deprecated_string());
+ return TRY(option.as_string().utf8_string());
}
// 14.1.2 ApplyOptionsToTag ( tag, options ), https://tc39.es/ecma402/#sec-apply-options-to-tag
@@ -69,7 +70,7 @@ static ThrowCompletionOr<DeprecatedString> apply_options_to_tag(VM& vm, StringVi
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);
+ locale_id = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(canonicalized_tag));
VERIFY(locale_id.has_value());
// 12. Let languageId be the substring of tag corresponding to the unicode_language_id production.
@@ -109,10 +110,10 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
{
// 1. Assert: Type(tag) is String.
// 2. Assert: tag matches the unicode_locale_id production.
- auto locale_id = ::Locale::parse_unicode_locale_id(tag);
+ auto locale_id = ::Locale::parse_unicode_locale_id(tag).release_value_but_fixme_should_propagate_errors();
VERIFY(locale_id.has_value());
- Vector<DeprecatedString> attributes;
+ Vector<String> attributes;
Vector<::Locale::Keyword> keywords;
// 3. If tag contains a substring that is a Unicode locale extension sequence, then
@@ -134,7 +135,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// a. Let attributes be a new empty List.
// b. Let keywords be a new empty List.
- auto field_from_key = [](LocaleAndKeys& value, StringView key) -> Optional<DeprecatedString>& {
+ auto field_from_key = [](LocaleAndKeys& value, StringView key) -> Optional<String>& {
if (key == "ca"sv)
return value.ca;
if (key == "co"sv)
@@ -156,7 +157,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 6. For each element key of relevantExtensionKeys, do
for (auto const& key : relevant_extension_keys) {
// a. Let value be undefined.
- Optional<DeprecatedString> value {};
+ Optional<String> value {};
::Locale::Keyword* entry = nullptr;
// b. If keywords contains an element whose [[Key]] is the same as key, then
@@ -188,7 +189,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// iv. Else,
else {
// 1. Append the Record { [[Key]]: key, [[Value]]: value } to keywords.
- keywords.append({ key, *value });
+ keywords.append({ String::from_utf8(key).release_value_but_fixme_should_propagate_errors(), *value });
}
}
@@ -198,7 +199,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 7. Let locale be the String value that is tag with any Unicode locale extension sequences removed.
locale_id->remove_extension_type<::Locale::LocaleExtension>();
- auto locale = locale_id->to_deprecated_string();
+ auto locale = locale_id->to_string().release_value_but_fixme_should_propagate_errors();
// 8. Let newExtension be a Unicode BCP 47 U Extension based on attributes and keywords.
::Locale::LocaleExtension new_extension { move(attributes), move(keywords) };
@@ -206,7 +207,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 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 = insert_unicode_extension_and_canonicalize(locale_id.release_value(), move(new_extension));
+ locale = String::from_deprecated_string(insert_unicode_extension_and_canonicalize(locale_id.release_value(), move(new_extension))).release_value_but_fixme_should_propagate_errors();
}
// 10. Set result.[[locale]] to locale.
@@ -313,7 +314,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
// 24. If kn is not undefined, set kn to ! ToString(kn).
// 25. Set opt.[[kn]] to kn.
if (!kn.is_undefined())
- opt.kn = TRY(kn.to_deprecated_string(vm));
+ opt.kn = TRY(kn.to_string(vm));
// 26. Let numberingSystem be ? GetOption(options, "numberingSystem", string, empty, undefined).
// 27. If numberingSystem is not undefined, then
@@ -325,22 +326,22 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
auto result = apply_unicode_extension_to_tag(tag, move(opt), relevant_extension_keys);
// 30. Set locale.[[Locale]] to r.[[locale]].
- locale->set_locale(move(result.locale));
+ locale->set_locale(result.locale.to_deprecated_string());
// 31. Set locale.[[Calendar]] to r.[[ca]].
if (result.ca.has_value())
- locale->set_calendar(result.ca.release_value());
+ locale->set_calendar(result.ca->to_deprecated_string());
// 32. Set locale.[[Collation]] to r.[[co]].
if (result.co.has_value())
- locale->set_collation(result.co.release_value());
+ locale->set_collation(result.co->to_deprecated_string());
// 33. Set locale.[[HourCycle]] to r.[[hc]].
if (result.hc.has_value())
- locale->set_hour_cycle(result.hc.release_value());
+ locale->set_hour_cycle(result.hc->to_deprecated_string());
// 34. If relevantExtensionKeys contains "kf", then
if (relevant_extension_keys.span().contains_slow("kf"sv)) {
// a. Set locale.[[CaseFirst]] to r.[[kf]].
if (result.kf.has_value())
- locale->set_case_first(result.kf.release_value());
+ locale->set_case_first(result.kf->to_deprecated_string());
}
// 35. If relevantExtensionKeys contains "kn", then
@@ -359,7 +360,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
// 36. Set locale.[[NumberingSystem]] to r.[[nu]].
if (result.nu.has_value())
- locale->set_numbering_system(result.nu.release_value());
+ locale->set_numbering_system(result.nu->to_deprecated_string());
// 37. Return locale.
return locale;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
index fd50f1fa16..382bcb8f5b 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp
@@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
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]].
@@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
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]].
@@ -111,7 +111,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
VERIFY(locale.has_value());
// 4. Return the substring of locale corresponding to the unicode_language_id production.
@@ -160,13 +160,13 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::language)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
// 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value());
// 5. Return the substring of locale corresponding to the unicode_language_subtag production of the unicode_language_id.
- return PrimitiveString::create(vm, *locale->language_id.language);
+ return PrimitiveString::create(vm, locale->language_id.language.release_value());
}
// 14.3.14 get Intl.Locale.prototype.script, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.script
@@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
// 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value());
@@ -187,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
return js_undefined();
// 6. Return the substring of locale corresponding to the unicode_script_subtag production of the unicode_language_id.
- return PrimitiveString::create(vm, *locale->language_id.script);
+ return PrimitiveString::create(vm, locale->language_id.script.release_value());
}
// 14.3.15 get Intl.Locale.prototype.region, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.region
@@ -198,7 +198,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
// 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value());
@@ -208,7 +208,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
return js_undefined();
// 6. Return the substring of locale corresponding to the unicode_region_subtag production of the unicode_language_id.
- return PrimitiveString::create(vm, *locale->language_id.region);
+ return PrimitiveString::create(vm, locale->language_id.region.release_value());
}
#define JS_ENUMERATE_LOCALE_INFO_PROPERTIES \
@@ -238,7 +238,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
- auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale());
+ auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
// 4. If the unicode_language_id production of locale does not contain the ["-" unicode_region_subtag] sequence, return undefined.
if (!locale.has_value() || !locale->language_id.region.has_value())
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index a16dc23480..6e964016b7 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -890,12 +890,12 @@ static ThrowCompletionOr<String> transform_case(VM& vm, String const& string, Va
// 2. If requestedLocales is not an empty List, then
if (!requested_locales.is_empty()) {
// a. Let requestedLocale be requestedLocales[0].
- requested_locale = Locale::parse_unicode_locale_id(requested_locales[0]);
+ requested_locale = TRY_OR_THROW_OOM(vm, Locale::parse_unicode_locale_id(requested_locales[0]));
}
// 3. Else,
else {
// a. Let requestedLocale be ! DefaultLocale().
- requested_locale = Locale::parse_unicode_locale_id(Locale::default_locale());
+ requested_locale = TRY_OR_THROW_OOM(vm, Locale::parse_unicode_locale_id(Locale::default_locale()));
}
VERIFY(requested_locale.has_value());