mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibJS: Stop propagating small OOM errors from Intl.NumberFormat
Note this also does the same for Intl.PluralRules. The only OOM errors propagated from Intl.PluralRules were from Intl.NumberFormat.
This commit is contained in:
parent
30a812b77b
commit
b3694653a7
16 changed files with 153 additions and 164 deletions
|
@ -92,13 +92,13 @@ PluralRules::PluralRules(Object& prototype)
|
|||
}
|
||||
|
||||
// 16.5.3 ResolvePlural ( pluralRules, n ), https://tc39.es/ecma402/#sec-resolveplural
|
||||
ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM& vm, PluralRules const& plural_rules, Value number)
|
||||
ResolvedPlurality resolve_plural(PluralRules const& plural_rules, Value number)
|
||||
{
|
||||
return resolve_plural(vm, plural_rules, plural_rules.type(), number);
|
||||
return resolve_plural(plural_rules, plural_rules.type(), number);
|
||||
}
|
||||
|
||||
// Non-standard overload of ResolvePlural to allow using the AO without an Intl.PluralRules object.
|
||||
ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM& vm, NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number)
|
||||
ResolvedPlurality resolve_plural(NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number)
|
||||
{
|
||||
// 1. Assert: Type(pluralRules) is Object.
|
||||
// 2. Assert: pluralRules has an [[InitializedPluralRules]] internal slot.
|
||||
|
@ -107,7 +107,7 @@ ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM& vm, NumberFormatBase con
|
|||
// 4. If n is not a finite Number, then
|
||||
if (!number.is_finite_number()) {
|
||||
// a. Return "other".
|
||||
return ResolvedPlurality { ::Locale::PluralCategory::Other, String {} };
|
||||
return { ::Locale::PluralCategory::Other, String {} };
|
||||
}
|
||||
|
||||
// 5. Let locale be pluralRules.[[Locale]].
|
||||
|
@ -116,7 +116,7 @@ ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM& vm, NumberFormatBase con
|
|||
// 6. Let type be pluralRules.[[Type]].
|
||||
|
||||
// 7. Let res be ! FormatNumericToString(pluralRules, n).
|
||||
auto result = MUST_OR_THROW_OOM(format_numeric_to_string(vm, number_format, number));
|
||||
auto result = format_numeric_to_string(number_format, number);
|
||||
|
||||
// 8. Let s be res.[[FormattedString]].
|
||||
auto string = move(result.formatted_string);
|
||||
|
@ -128,7 +128,7 @@ ThrowCompletionOr<ResolvedPlurality> resolve_plural(VM& vm, NumberFormatBase con
|
|||
auto plural_category = plural_rule_select(locale, type, number, move(operands));
|
||||
|
||||
// 11. Return the Record { [[PluralCategory]]: p, [[FormattedString]]: s }.
|
||||
return ResolvedPlurality { plural_category, move(string) };
|
||||
return { plural_category, move(string) };
|
||||
}
|
||||
|
||||
// 16.5.4 PluralRuleSelectRange ( locale, type, xp, yp ), https://tc39.es/ecma402/#sec-resolveplural
|
||||
|
@ -152,10 +152,10 @@ ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM& vm, PluralR
|
|||
return vm.throw_completion<RangeError>(ErrorType::NumberIsNaN, "end"sv);
|
||||
|
||||
// 6. Let xp be ! ResolvePlural(pluralRules, x).
|
||||
auto start_plurality = MUST_OR_THROW_OOM(resolve_plural(vm, plural_rules, start));
|
||||
auto start_plurality = resolve_plural(plural_rules, start);
|
||||
|
||||
// 7. Let yp be ! ResolvePlural(pluralRules, y).
|
||||
auto end_plurality = MUST_OR_THROW_OOM(resolve_plural(vm, plural_rules, end));
|
||||
auto end_plurality = resolve_plural(plural_rules, end);
|
||||
|
||||
// 8. If xp.[[FormattedString]] is yp.[[FormattedString]], then
|
||||
if (start_plurality.formatted_string == end_plurality.formatted_string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue