diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-02 19:54:47 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-08 18:32:37 +0000 |
commit | 89da8de4cab589885fcaf8940b6e9022c637e24c (patch) | |
tree | 23c5f4ab5ba92f130d4730d5a5bca16449d61bf7 | |
parent | 858126d23638dff91d9eb07e05a3b69adb2965cc (diff) | |
download | serenity-89da8de4cab589885fcaf8940b6e9022c637e24c.zip |
LibJS+LibLocale: Propagate OOM from CLDR NumberFormat Vector operations
4 files changed, 13 insertions, 13 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp index 082a894c90..1ecd5b9521 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Tim Flynn <trflynn89@serenityos.org> + * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -798,7 +798,7 @@ namespace Locale { generator.append(R"~~~( struct NumberFormatImpl { - NumberFormat to_unicode_number_format() const { + ErrorOr<NumberFormat> to_unicode_number_format() const { NumberFormat number_format {}; number_format.magnitude = magnitude; @@ -808,9 +808,9 @@ struct NumberFormatImpl { number_format.positive_format = decode_string(positive_format); number_format.negative_format = decode_string(negative_format); - number_format.identifiers.ensure_capacity(identifiers.size()); + TRY(number_format.identifiers.try_ensure_capacity(identifiers.size())); for (@string_index_type@ identifier : identifiers) - number_format.identifiers.append(decode_string(identifier)); + number_format.identifiers.unchecked_append(decode_string(identifier)); return number_format; } @@ -1017,7 +1017,7 @@ ErrorOr<Optional<NumberFormat>> get_standard_number_system_format(StringView loc break; } - return s_number_formats[format_index].to_unicode_number_format(); + return TRY(s_number_formats[format_index].to_unicode_number_format()); } return OptionalNone {}; @@ -1046,10 +1046,10 @@ ErrorOr<Vector<NumberFormat>> get_compact_number_system_formats(StringView local } auto number_formats = s_number_format_lists.at(number_format_list_index); - formats.ensure_capacity(number_formats.size()); + TRY(formats.try_ensure_capacity(number_formats.size())); for (auto number_format : number_formats) - formats.append(s_number_formats[number_format].to_unicode_number_format()); + formats.unchecked_append(TRY(s_number_formats[number_format].to_unicode_number_format())); } return formats; @@ -1074,7 +1074,7 @@ static Unit const* find_units(StringView locale, StringView unit) return nullptr; } -Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style) +ErrorOr<Vector<NumberFormat>> get_unit_formats(StringView locale, StringView unit, Style style) { Vector<NumberFormat> formats; @@ -1096,10 +1096,10 @@ Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style } auto number_formats = s_number_format_lists.at(number_format_list_index); - formats.ensure_capacity(number_formats.size()); + TRY(formats.try_ensure_capacity(number_formats.size())); for (auto number_format : number_formats) - formats.append(s_number_formats[number_format].to_unicode_number_format()); + formats.unchecked_append(TRY(s_number_formats[number_format].to_unicode_number_format())); } return formats; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index 0ab18a721a..137f214454 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -1317,7 +1317,7 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte // i. Let unit be "fallback". // e. Let patterns be patterns.[[<unit>]]. // f. Let patterns be patterns.[[<unitDisplay>]]. - auto formats = ::Locale::get_unit_formats(number_format.data_locale(), number_format.unit(), number_format.unit_display()); + auto formats = TRY_OR_THROW_OOM(vm, ::Locale::get_unit_formats(number_format.data_locale(), number_format.unit(), number_format.unit_display())); auto plurality = MUST_OR_THROW_OOM(resolve_plural(vm, number_format, ::Locale::PluralForm::Cardinal, number.to_value(vm))); if (auto it = formats.find_if([&](auto& p) { return p.plurality == plurality.plural_category; }); it != formats.end()) diff --git a/Userland/Libraries/LibLocale/NumberFormat.cpp b/Userland/Libraries/LibLocale/NumberFormat.cpp index 812137541a..5de4905020 100644 --- a/Userland/Libraries/LibLocale/NumberFormat.cpp +++ b/Userland/Libraries/LibLocale/NumberFormat.cpp @@ -20,7 +20,7 @@ ErrorOr<Optional<StringView>> __attribute__((weak)) get_number_system_symbol(Str ErrorOr<Optional<NumberGroupings>> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return OptionalNone {}; } ErrorOr<Optional<NumberFormat>> __attribute__((weak)) get_standard_number_system_format(StringView, StringView, StandardNumberFormatType) { return OptionalNone {}; } ErrorOr<Vector<NumberFormat>> __attribute__((weak)) get_compact_number_system_formats(StringView, StringView, CompactNumberFormatType) { return Vector<NumberFormat> {}; } -Vector<NumberFormat> __attribute__((weak)) get_unit_formats(StringView, StringView, Style) { return {}; } +ErrorOr<Vector<NumberFormat>> __attribute__((weak)) get_unit_formats(StringView, StringView, Style) { return Vector<NumberFormat> {}; } Optional<Span<u32 const>> __attribute__((weak)) get_digits_for_number_system(StringView) { diff --git a/Userland/Libraries/LibLocale/NumberFormat.h b/Userland/Libraries/LibLocale/NumberFormat.h index 566af5500f..2c40532dfc 100644 --- a/Userland/Libraries/LibLocale/NumberFormat.h +++ b/Userland/Libraries/LibLocale/NumberFormat.h @@ -69,7 +69,7 @@ ErrorOr<String> replace_digits_for_number_system(StringView system, StringView n ErrorOr<Optional<NumberFormat>> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type); ErrorOr<Vector<NumberFormat>> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type); -Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style); +ErrorOr<Vector<NumberFormat>> get_unit_formats(StringView locale, StringView unit, Style style); ErrorOr<Optional<String>> augment_currency_format_pattern(StringView currency_display, StringView base_pattern); ErrorOr<Optional<String>> augment_range_pattern(StringView range_separator, StringView lower, StringView upper); |