mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibJS+LibLocale: Port Intl.NumberFormat to String
This commit is contained in:
parent
76fd5f2756
commit
0c2efa285a
13 changed files with 169 additions and 149 deletions
|
@ -92,13 +92,13 @@ PluralRules::PluralRules(Object& prototype)
|
|||
}
|
||||
|
||||
// 16.5.3 ResolvePlural ( pluralRules, n ), https://tc39.es/ecma402/#sec-resolveplural
|
||||
::Locale::PluralCategory resolve_plural(PluralRules const& plural_rules, Value number)
|
||||
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural(VM& vm, PluralRules const& plural_rules, Value number)
|
||||
{
|
||||
return resolve_plural(plural_rules, plural_rules.type(), number);
|
||||
return resolve_plural(vm, plural_rules, plural_rules.type(), number);
|
||||
}
|
||||
|
||||
// Non-standard overload of ResolvePlural to allow using the AO without an Intl.PluralRules object.
|
||||
::Locale::PluralCategory resolve_plural(NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number)
|
||||
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural(VM& vm, NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number)
|
||||
{
|
||||
// 1. Assert: Type(pluralRules) is Object.
|
||||
// 2. Assert: pluralRules has an [[InitializedPluralRules]] internal slot.
|
||||
|
@ -116,7 +116,7 @@ PluralRules::PluralRules(Object& prototype)
|
|||
// 6. Let type be pluralRules.[[Type]].
|
||||
|
||||
// 7. Let res be ! FormatNumericToString(pluralRules, n).
|
||||
auto result = format_numeric_to_string(number_format, number);
|
||||
auto result = MUST_OR_THROW_OOM(format_numeric_to_string(vm, number_format, number));
|
||||
|
||||
// 8. Let s be res.[[FormattedString]].
|
||||
auto const& string = result.formatted_string;
|
||||
|
@ -149,10 +149,10 @@ ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM& vm, PluralR
|
|||
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaN, "end"sv);
|
||||
|
||||
// 6. Let xp be ! ResolvePlural(pluralRules, x).
|
||||
auto start_plurality = resolve_plural(plural_rules, start);
|
||||
auto start_plurality = MUST_OR_THROW_OOM(resolve_plural(vm, plural_rules, start));
|
||||
|
||||
// 7. Let yp be ! ResolvePlural(pluralRules, y).
|
||||
auto end_plurality = resolve_plural(plural_rules, end);
|
||||
auto end_plurality = MUST_OR_THROW_OOM(resolve_plural(vm, plural_rules, end));
|
||||
|
||||
// 8. Let locale be pluralRules.[[Locale]].
|
||||
auto const& locale = plural_rules.locale();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue