mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
LibJS+LibLocale: Propagate errors from find_regional_values_for_locale
This had quite the footprint.
This commit is contained in:
parent
b2097f4059
commit
5e29e04122
16 changed files with 184 additions and 183 deletions
|
@ -529,13 +529,13 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// 2. If x is not-a-number, then
|
||||
if (number.is_nan()) {
|
||||
// a. Let n be an implementation- and locale-dependent (ILD) String value indicating the NaN value.
|
||||
auto symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::NaN).value_or("NaN"sv);
|
||||
auto symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::NaN)).value_or("NaN"sv);
|
||||
formatted_string = TRY_OR_THROW_OOM(vm, String::from_utf8(symbol));
|
||||
}
|
||||
// 3. Else if x is positive-infinity, then
|
||||
else if (number.is_positive_infinity()) {
|
||||
// a. Let n be an ILD String value indicating positive infinity.
|
||||
auto symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Infinity).value_or("infinity"sv);
|
||||
auto symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Infinity)).value_or("infinity"sv);
|
||||
formatted_string = TRY_OR_THROW_OOM(vm, String::from_utf8(symbol));
|
||||
}
|
||||
// 4. Else if x is negative-infinity, then
|
||||
|
@ -543,7 +543,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// a. Let n be an ILD String value indicating negative infinity.
|
||||
// NOTE: The CLDR does not contain unique strings for negative infinity. The negative sign will
|
||||
// be inserted by the pattern returned from GetNumberFormatPattern.
|
||||
auto symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Infinity).value_or("infinity"sv);
|
||||
auto symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Infinity)).value_or("infinity"sv);
|
||||
formatted_string = TRY_OR_THROW_OOM(vm, String::from_utf8(symbol));
|
||||
}
|
||||
// 5. Else,
|
||||
|
@ -609,7 +609,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// d. Else if p is equal to "plusSign", then
|
||||
else if (part == "plusSign"sv) {
|
||||
// i. Let plusSignSymbol be the ILND String representing the plus sign.
|
||||
auto plus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PlusSign).value_or("+"sv);
|
||||
auto plus_sign_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PlusSign)).value_or("+"sv);
|
||||
// ii. Append a new Record { [[Type]]: "plusSign", [[Value]]: plusSignSymbol } as the last element of result.
|
||||
result.append({ "plusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(plus_sign_symbol)) });
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// e. Else if p is equal to "minusSign", then
|
||||
else if (part == "minusSign"sv) {
|
||||
// i. Let minusSignSymbol be the ILND String representing the minus sign.
|
||||
auto minus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign).value_or("-"sv);
|
||||
auto minus_sign_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign)).value_or("-"sv);
|
||||
// ii. Append a new Record { [[Type]]: "minusSign", [[Value]]: minusSignSymbol } as the last element of result.
|
||||
result.append({ "minusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(minus_sign_symbol)) });
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_number_pattern(VM& vm, Num
|
|||
// f. Else if p is equal to "percentSign" and numberFormat.[[Style]] is "percent", then
|
||||
else if ((part == "percentSign"sv) && (number_format.style() == NumberFormat::Style::Percent)) {
|
||||
// i. Let percentSignSymbol be the ILND String representing the percent sign.
|
||||
auto percent_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PercentSign).value_or("%"sv);
|
||||
auto percent_sign_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::PercentSign)).value_or("%"sv);
|
||||
// ii. Append a new Record { [[Type]]: "percentSign", [[Value]]: percentSignSymbol } as the last element of result.
|
||||
result.append({ "percentSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(percent_sign_symbol)) });
|
||||
}
|
||||
|
@ -725,7 +725,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 1. Let result be a new empty List.
|
||||
Vector<PatternPartition> result;
|
||||
|
||||
auto grouping_sizes = ::Locale::get_number_system_groupings(number_format.data_locale(), number_format.numbering_system());
|
||||
auto grouping_sizes = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_groupings(number_format.data_locale(), number_format.numbering_system()));
|
||||
if (!grouping_sizes.has_value())
|
||||
return Vector<PatternPartition> {};
|
||||
|
||||
|
@ -742,7 +742,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Let notationSubPattern be GetNotationSubPattern(numberFormat, exponent).
|
||||
auto notation_sub_pattern = get_notation_sub_pattern(number_format, exponent);
|
||||
auto notation_sub_pattern = MUST_OR_THROW_OOM(get_notation_sub_pattern(vm, number_format, exponent));
|
||||
if (!notation_sub_pattern.has_value())
|
||||
return Vector<PatternPartition> {};
|
||||
|
||||
|
@ -808,7 +808,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 7. Else,
|
||||
else {
|
||||
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
||||
auto group_sep_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Group).value_or(","sv);
|
||||
auto group_sep_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Group)).value_or(","sv);
|
||||
|
||||
// b. Let groups be a List whose elements are, in left to right order, the substrings defined by ILND set of locations within the integer, which may depend on the value of numberFormat.[[UseGrouping]].
|
||||
auto groups = separate_integer_into_groups(*grouping_sizes, integer, number_format.use_grouping());
|
||||
|
@ -835,7 +835,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 8. If fraction is not undefined, then
|
||||
if (fraction.has_value()) {
|
||||
// a. Let decimalSepSymbol be the ILND String representing the decimal separator.
|
||||
auto decimal_sep_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Decimal).value_or("."sv);
|
||||
auto decimal_sep_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Decimal)).value_or("."sv);
|
||||
// b. Append a new Record { [[Type]]: "decimal", [[Value]]: decimalSepSymbol } as the last element of result.
|
||||
result.append({ "decimal"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(decimal_sep_symbol)) });
|
||||
// c. Append a new Record { [[Type]]: "fraction", [[Value]]: fraction } as the last element of result.
|
||||
|
@ -859,7 +859,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// vi. Else if p is equal to "scientificSeparator", then
|
||||
else if (part == "scientificSeparator"sv) {
|
||||
// 1. Let scientificSeparator be the ILND String representing the exponent separator.
|
||||
auto scientific_separator = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Exponential).value_or("E"sv);
|
||||
auto scientific_separator = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::Exponential)).value_or("E"sv);
|
||||
// 2. Append a new Record { [[Type]]: "exponentSeparator", [[Value]]: scientificSeparator } as the last element of result.
|
||||
result.append({ "exponentSeparator"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(scientific_separator)) });
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_notation_sub_pattern(VM& v
|
|||
// 1. If exponent < 0, then
|
||||
if (exponent < 0) {
|
||||
// a. Let minusSignSymbol be the ILND String representing the minus sign.
|
||||
auto minus_sign_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign).value_or("-"sv);
|
||||
auto minus_sign_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::MinusSign)).value_or("-"sv);
|
||||
|
||||
// b. Append a new Record { [[Type]]: "exponentMinusSign", [[Value]]: minusSignSymbol } as the last element of result.
|
||||
result.append({ "exponentMinusSign"sv, TRY_OR_THROW_OOM(vm, String::from_utf8(minus_sign_symbol)) });
|
||||
|
@ -1292,7 +1292,7 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte
|
|||
// 7. If style is "percent", then
|
||||
case NumberFormat::Style::Percent:
|
||||
// a. Let patterns be patterns.[[percent]].
|
||||
patterns = ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Percent);
|
||||
patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Percent));
|
||||
break;
|
||||
|
||||
// 8. Else if style is "unit", then
|
||||
|
@ -1327,7 +1327,7 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte
|
|||
|
||||
// Handling of other [[CurrencyDisplay]] options will occur after [[SignDisplay]].
|
||||
if (number_format.currency_display() == NumberFormat::CurrencyDisplay::Name) {
|
||||
auto formats = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::CurrencyUnit);
|
||||
auto formats = TRY_OR_THROW_OOM(vm, ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::CurrencyUnit));
|
||||
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; }); it != formats.end()) {
|
||||
|
@ -1338,10 +1338,10 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte
|
|||
|
||||
switch (number_format.currency_sign()) {
|
||||
case NumberFormat::CurrencySign::Standard:
|
||||
patterns = ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Currency);
|
||||
patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Currency));
|
||||
break;
|
||||
case NumberFormat::CurrencySign::Accounting:
|
||||
patterns = ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Accounting);
|
||||
patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Accounting));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1351,7 +1351,7 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte
|
|||
case NumberFormat::Style::Decimal:
|
||||
// a. Assert: style is "decimal".
|
||||
// b. Let patterns be patterns.[[decimal]].
|
||||
patterns = ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Decimal);
|
||||
patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Decimal));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1453,7 +1453,7 @@ ThrowCompletionOr<Optional<Variant<StringView, String>>> get_number_format_patte
|
|||
}
|
||||
|
||||
// 15.5.12 GetNotationSubPattern ( numberFormat, exponent ), https://tc39.es/ecma402/#sec-getnotationsubpattern
|
||||
Optional<StringView> get_notation_sub_pattern(NumberFormat& number_format, int exponent)
|
||||
ThrowCompletionOr<Optional<StringView>> get_notation_sub_pattern(VM& vm, NumberFormat& number_format, int exponent)
|
||||
{
|
||||
// 1. Let localeData be %NumberFormat%.[[LocaleData]].
|
||||
// 2. Let dataLocale be numberFormat.[[DataLocale]].
|
||||
|
@ -1467,9 +1467,9 @@ Optional<StringView> get_notation_sub_pattern(NumberFormat& number_format, int e
|
|||
// 7. If notation is "scientific" or notation is "engineering", then
|
||||
if ((notation == NumberFormat::Notation::Scientific) || (notation == NumberFormat::Notation::Engineering)) {
|
||||
// a. Return notationSubPatterns.[[scientific]].
|
||||
auto notation_sub_patterns = ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Scientific);
|
||||
auto notation_sub_patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_standard_number_system_format(number_format.data_locale(), number_format.numbering_system(), ::Locale::StandardNumberFormatType::Scientific));
|
||||
if (!notation_sub_patterns.has_value())
|
||||
return {};
|
||||
return OptionalNone {};
|
||||
|
||||
return notation_sub_patterns->zero_format;
|
||||
}
|
||||
|
@ -1509,7 +1509,7 @@ ThrowCompletionOr<int> compute_exponent(VM& vm, NumberFormat& number_format, Mat
|
|||
int magnitude = number.logarithmic_floor();
|
||||
|
||||
// 4. Let exponent be ComputeExponentForMagnitude(numberFormat, magnitude).
|
||||
int exponent = compute_exponent_for_magnitude(number_format, magnitude);
|
||||
int exponent = MUST_OR_THROW_OOM(compute_exponent_for_magnitude(vm, number_format, magnitude));
|
||||
|
||||
// 5. Let x be x × 10^(-exponent).
|
||||
number = number.multiplied_by_power(-exponent);
|
||||
|
@ -1533,11 +1533,11 @@ ThrowCompletionOr<int> compute_exponent(VM& vm, NumberFormat& number_format, Mat
|
|||
}
|
||||
|
||||
// 10. Return ComputeExponentForMagnitude(numberFormat, magnitude + 1).
|
||||
return compute_exponent_for_magnitude(number_format, magnitude + 1);
|
||||
return MUST_OR_THROW_OOM(compute_exponent_for_magnitude(vm, number_format, magnitude + 1));
|
||||
}
|
||||
|
||||
// 15.5.14 ComputeExponentForMagnitude ( numberFormat, magnitude ), https://tc39.es/ecma402/#sec-computeexponentformagnitude
|
||||
int compute_exponent_for_magnitude(NumberFormat& number_format, int magnitude)
|
||||
ThrowCompletionOr<int> compute_exponent_for_magnitude(VM& vm, NumberFormat& number_format, int magnitude)
|
||||
{
|
||||
// 1. Let notation be numberFormat.[[Notation]].
|
||||
switch (number_format.notation()) {
|
||||
|
@ -1570,11 +1570,11 @@ int compute_exponent_for_magnitude(NumberFormat& number_format, int magnitude)
|
|||
Vector<::Locale::NumberFormat> format_rules;
|
||||
|
||||
if (number_format.style() == NumberFormat::Style::Currency)
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::CurrencyShort);
|
||||
format_rules = TRY_OR_THROW_OOM(vm, ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::CurrencyShort));
|
||||
else if (number_format.compact_display() == NumberFormat::CompactDisplay::Long)
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalLong);
|
||||
format_rules = TRY_OR_THROW_OOM(vm, ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalLong));
|
||||
else
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalShort);
|
||||
format_rules = TRY_OR_THROW_OOM(vm, ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalShort));
|
||||
|
||||
::Locale::NumberFormat const* best_number_format = nullptr;
|
||||
|
||||
|
@ -1782,7 +1782,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
|
|||
result = move(start_result);
|
||||
|
||||
// 8. Let rangeSeparator be an ILND String value used to separate two numbers.
|
||||
auto range_separator_symbol = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::RangeSeparator).value_or("-"sv);
|
||||
auto range_separator_symbol = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::RangeSeparator)).value_or("-"sv);
|
||||
auto range_separator = TRY_OR_THROW_OOM(vm, ::Locale::augment_range_pattern(range_separator_symbol, result.last().value, end_result[0].value));
|
||||
|
||||
// 9. Append a new Record { [[Type]]: "literal", [[Value]]: rangeSeparator, [[Source]]: "shared" } element to result.
|
||||
|
@ -1812,7 +1812,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> format_approximately(VM& v
|
|||
{
|
||||
// 1. Let i be an index into result, determined by an implementation-defined algorithm based on numberFormat and result.
|
||||
// 2. Let approximatelySign be an ILND String value used to signify that a number is approximate.
|
||||
auto approximately_sign = ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::ApproximatelySign).value_or("~"sv);
|
||||
auto approximately_sign = TRY_OR_THROW_OOM(vm, ::Locale::get_number_system_symbol(number_format.data_locale(), number_format.numbering_system(), ::Locale::NumericSymbol::ApproximatelySign)).value_or("~"sv);
|
||||
|
||||
// 3. Insert a new Record { [[Type]]: "approximatelySign", [[Value]]: approximatelySign } at index i in result.
|
||||
PatternPartitionWithSource partition;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue