mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:07:35 +00:00
LibJS: Implement Intl.getCanonicalLocales
This commit is contained in:
parent
e8dd2eea74
commit
38d29a40dc
4 changed files with 103 additions and 0 deletions
|
@ -175,6 +175,7 @@ namespace JS {
|
|||
P(get) \
|
||||
P(getBigInt64) \
|
||||
P(getBigUint64) \
|
||||
P(getCanonicalLocales) \
|
||||
P(getDate) \
|
||||
P(getDay) \
|
||||
P(getFloat32) \
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Intl/DisplayNamesConstructor.h>
|
||||
#include <LibJS/Runtime/Intl/Intl.h>
|
||||
|
||||
|
@ -27,6 +29,27 @@ void Intl::initialize(GlobalObject& global_object)
|
|||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_direct_property(vm.names.DisplayNames, global_object.intl_display_names_constructor(), attr);
|
||||
|
||||
define_native_function(vm.names.getCanonicalLocales, get_canonical_locales, 1, attr);
|
||||
}
|
||||
|
||||
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
|
||||
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
|
||||
{
|
||||
auto locales = vm.argument(0);
|
||||
|
||||
// 1. Let ll be ? CanonicalizeLocaleList(locales).
|
||||
auto locale_list = canonicalize_locale_list(global_object, locales);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
MarkedValueList marked_locale_list { vm.heap() };
|
||||
marked_locale_list.ensure_capacity(locale_list.size());
|
||||
for (auto& locale : locale_list)
|
||||
marked_locale_list.append(js_string(vm, move(locale)));
|
||||
|
||||
// 2. Return CreateArrayFromList(ll).
|
||||
return Array::create_from(global_object, marked_locale_list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ public:
|
|||
explicit Intl(GlobalObject&);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~Intl() override = default;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_canonical_locales);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue