LibJS: Return OptionalNone in fallible functions in the Intl namespace
This commit is contained in:
parent
5349972f41
commit
be8907e6bb
Notes:
sideshowbarker
2024-07-17 05:13:53 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/be8907e6bb Pull-request: https://github.com/SerenityOS/serenity/pull/17095
2 changed files with 6 additions and 5 deletions
Userland/Libraries/LibJS/Runtime/Intl
|
@ -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 = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale));
|
||||
if (!locale_id.has_value())
|
||||
return Optional<::Locale::LocaleID> {};
|
||||
return OptionalNone {};
|
||||
|
||||
// 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 Optional<::Locale::LocaleID> {};
|
||||
return OptionalNone {};
|
||||
|
||||
// the unicode_language_id within locale contains no duplicate unicode_variant_subtag subtags; and
|
||||
if (TRY(contains_duplicate_variant(locale_id->language_id.variants)))
|
||||
return Optional<::Locale::LocaleID> {};
|
||||
return OptionalNone {};
|
||||
|
||||
// if locale contains an extensions* component, that component
|
||||
Vector<char> unique_keys;
|
||||
|
@ -64,7 +64,8 @@ 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 Optional<::Locale::LocaleID> {};
|
||||
return OptionalNone {};
|
||||
|
||||
TRY_OR_THROW_OOM(vm, unique_keys.try_append(key));
|
||||
|
||||
// if a transformed_extensions component that contains a tlang component is present, then
|
||||
|
|
|
@ -32,7 +32,7 @@ static ThrowCompletionOr<Optional<String>> get_string_option(VM& vm, Object cons
|
|||
{
|
||||
auto option = TRY(get_option(vm, options, property, OptionType::String, values, Empty {}));
|
||||
if (option.is_undefined())
|
||||
return Optional<String> {};
|
||||
return OptionalNone {};
|
||||
|
||||
if (validator && !validator(TRY(option.as_string().utf8_string_view())))
|
||||
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, option, property);
|
||||
|
|
Loading…
Add table
Reference in a new issue