mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
LibJS: Implement Intl.PluralRules.supportedLocalesOf
This commit is contained in:
parent
624fad3821
commit
8b3f49ff84
3 changed files with 65 additions and 0 deletions
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Intl/PluralRules.h>
|
||||
#include <LibJS/Runtime/Intl/PluralRulesConstructor.h>
|
||||
|
||||
|
@ -26,6 +28,9 @@ void PluralRulesConstructor::initialize(GlobalObject& global_object)
|
|||
// 16.3.1 Intl.PluralRules.prototype, https://tc39.es/ecma402/#sec-intl.pluralrules.prototype
|
||||
define_direct_property(vm.names.prototype, global_object.intl_plural_rules_prototype(), 0);
|
||||
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
|
||||
}
|
||||
|
||||
// 16.2.1 Intl.PluralRules ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-intl.pluralrules
|
||||
|
@ -51,4 +56,19 @@ ThrowCompletionOr<Object*> PluralRulesConstructor::construct(FunctionObject& new
|
|||
return TRY(initialize_plural_rules(global_object, *plural_rules, locales, options));
|
||||
}
|
||||
|
||||
// 16.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] ), https://tc39.es/ecma402/#sec-intl.pluralrules.supportedlocalesof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PluralRulesConstructor::supported_locales_of)
|
||||
{
|
||||
auto locales = vm.argument(0);
|
||||
auto options = vm.argument(1);
|
||||
|
||||
// 1. Let availableLocales be %PluralRules%.[[AvailableLocales]].
|
||||
|
||||
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
auto requested_locales = TRY(canonicalize_locale_list(global_object, locales));
|
||||
|
||||
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
|
||||
return TRY(supported_locales(global_object, requested_locales, options));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue