2021-08-08 18:27:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2021-08-25 09:41:25 -04:00
|
|
|
#include <LibJS/Runtime/Array.h>
|
2021-08-08 18:27:28 +01:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2021-08-25 09:41:25 -04:00
|
|
|
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
2021-09-06 22:18:48 -04:00
|
|
|
#include <LibJS/Runtime/Intl/CollatorConstructor.h>
|
2021-11-18 10:30:31 -05:00
|
|
|
#include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h>
|
2021-08-24 22:27:05 -04:00
|
|
|
#include <LibJS/Runtime/Intl/DisplayNamesConstructor.h>
|
2021-08-08 18:27:28 +01:00
|
|
|
#include <LibJS/Runtime/Intl/Intl.h>
|
2021-09-05 23:05:16 -04:00
|
|
|
#include <LibJS/Runtime/Intl/ListFormatConstructor.h>
|
2021-09-02 08:32:43 -04:00
|
|
|
#include <LibJS/Runtime/Intl/LocaleConstructor.h>
|
2021-09-08 21:34:27 -04:00
|
|
|
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
|
2022-01-28 12:56:04 -05:00
|
|
|
#include <LibJS/Runtime/Intl/PluralRulesConstructor.h>
|
2022-01-25 10:41:57 -05:00
|
|
|
#include <LibJS/Runtime/Intl/RelativeTimeFormatConstructor.h>
|
2021-08-08 18:27:28 +01:00
|
|
|
|
|
|
|
namespace JS::Intl {
|
|
|
|
|
|
|
|
// 8 The Intl Object, https://tc39.es/ecma402/#intl-object
|
|
|
|
Intl::Intl(GlobalObject& global_object)
|
|
|
|
: Object(*global_object.object_prototype())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Intl::initialize(GlobalObject& global_object)
|
|
|
|
{
|
|
|
|
Object::initialize(global_object);
|
2021-08-08 18:39:20 +01:00
|
|
|
|
|
|
|
auto& vm = this->vm();
|
|
|
|
|
|
|
|
// 8.1.1 Intl[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl-toStringTag
|
|
|
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl"), Attribute::Configurable);
|
2021-08-24 22:27:05 -04:00
|
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
2021-09-06 22:18:48 -04:00
|
|
|
define_direct_property(vm.names.Collator, global_object.intl_collator_constructor(), attr);
|
2021-11-18 10:30:31 -05:00
|
|
|
define_direct_property(vm.names.DateTimeFormat, global_object.intl_date_time_format_constructor(), attr);
|
2021-08-24 22:27:05 -04:00
|
|
|
define_direct_property(vm.names.DisplayNames, global_object.intl_display_names_constructor(), attr);
|
2021-09-05 23:05:16 -04:00
|
|
|
define_direct_property(vm.names.ListFormat, global_object.intl_list_format_constructor(), attr);
|
2021-09-02 08:32:43 -04:00
|
|
|
define_direct_property(vm.names.Locale, global_object.intl_locale_constructor(), attr);
|
2021-09-08 21:34:27 -04:00
|
|
|
define_direct_property(vm.names.NumberFormat, global_object.intl_number_format_constructor(), attr);
|
2022-01-28 12:56:04 -05:00
|
|
|
define_direct_property(vm.names.PluralRules, global_object.intl_plural_rules_constructor(), attr);
|
2022-01-25 10:41:57 -05:00
|
|
|
define_direct_property(vm.names.RelativeTimeFormat, global_object.intl_relative_time_format_constructor(), attr);
|
2021-08-25 09:41:25 -04:00
|
|
|
|
2021-10-22 22:45:54 +01:00
|
|
|
define_native_function(vm.names.getCanonicalLocales, get_canonical_locales, 1, attr);
|
2021-08-25 09:41:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
|
2021-10-22 22:45:54 +01:00
|
|
|
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
|
2021-08-25 09:41:25 -04:00
|
|
|
{
|
|
|
|
auto locales = vm.argument(0);
|
|
|
|
|
|
|
|
// 1. Let ll be ? CanonicalizeLocaleList(locales).
|
2021-10-22 22:45:54 +01:00
|
|
|
auto locale_list = TRY(canonicalize_locale_list(global_object, locales));
|
2021-08-25 09:41:25 -04:00
|
|
|
|
|
|
|
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);
|
2021-08-08 18:27:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|