summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Intl
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-11 11:15:42 -0400
committerLinus Groh <mail@linusgroh.de>2021-09-12 12:57:17 +0100
commit673fc02ac5ab92f8fe93b4cd831ec65c00a76654 (patch)
tree39bec63d0625b332c596a4a4850e99c900dc7ea7 /Userland/Libraries/LibJS/Runtime/Intl
parent7769cd2cabda8331e951aa77cdc9522a06cb3442 (diff)
downloadserenity-673fc02ac5ab92f8fe93b4cd831ec65c00a76654.zip
LibJS: Move locale_relevant_extension_keys to Intl.Locale
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Locale.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp14
3 files changed, 16 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
index 23c7be195d..130245699f 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp
@@ -15,6 +15,18 @@ Locale* Locale::create(GlobalObject& global_object, Unicode::LocaleID const& loc
return global_object.heap().allocate<Locale>(global_object, locale_id, *global_object.intl_locale_prototype());
}
+Vector<StringView> const& Locale::relevant_extension_keys()
+{
+ // 14.2.2 Internal slots, https://tc39.es/ecma402/#sec-intl.locale-internal-slots
+ // The value of the [[RelevantExtensionKeys]] internal slot is « "ca", "co", "hc", "kf", "kn", "nu" ».
+ // If %Collator%.[[RelevantExtensionKeys]] does not contain "kf", then remove "kf" from %Locale%.[[RelevantExtensionKeys]].
+ // If %Collator%.[[RelevantExtensionKeys]] does not contain "kn", then remove "kn" from %Locale%.[[RelevantExtensionKeys]].
+
+ // FIXME: We do not yet have an Intl.Collator object. For now, we behave as if "kf" and "kn" exist, as test262 depends on it.
+ static Vector<StringView> relevant_extension_keys { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
+ return relevant_extension_keys;
+}
+
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects
Locale::Locale(Object& prototype)
: Object(prototype)
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.h b/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
index 480a0ffc98..5d4213a8f3 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.h
@@ -8,6 +8,7 @@
#include <AK/Optional.h>
#include <AK/String.h>
+#include <AK/Vector.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Value.h>
#include <LibUnicode/Forward.h>
@@ -20,6 +21,8 @@ class Locale final : public Object {
public:
static Locale* create(GlobalObject&, Unicode::LocaleID const&);
+ static Vector<StringView> const& relevant_extension_keys(); // [[RelevantExtensionKeys]]
+
Locale(Object& prototype);
Locale(Unicode::LocaleID const&, Object& prototype);
virtual ~Locale() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
index 12a97b9be0..338c32cd81 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp
@@ -25,18 +25,6 @@ struct LocaleAndKeys {
Optional<String> nu;
};
-static Vector<StringView> const& locale_relevant_extension_keys()
-{
- // 14.2.2 Internal slots, https://tc39.es/ecma402/#sec-intl.locale-internal-slots
- // The value of the [[RelevantExtensionKeys]] internal slot is « "ca", "co", "hc", "kf", "kn", "nu" ».
- // If %Collator%.[[RelevantExtensionKeys]] does not contain "kf", then remove "kf" from %Locale%.[[RelevantExtensionKeys]].
- // If %Collator%.[[RelevantExtensionKeys]] does not contain "kn", then remove "kn" from %Locale%.[[RelevantExtensionKeys]].
-
- // FIXME: We do not yet have an Intl.Collator object. For now, we behave as if "kf" and "kn" exist, as test262 depends on it.
- static Vector<StringView> relevant_extension_keys { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
- return relevant_extension_keys;
-}
-
// Note: This is not an AO in the spec. This just serves to abstract very similar steps in ApplyOptionsToTag and the Intl.Locale constructor.
static Optional<String> get_string_option(GlobalObject& global_object, Object const& options, PropertyName const& property, Function<bool(StringView)> validator, Vector<StringView> const& values = {})
{
@@ -278,7 +266,7 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
auto options_value = vm.argument(1);
// 2. Let relevantExtensionKeys be %Locale%.[[RelevantExtensionKeys]].
- auto const& relevant_extension_keys = locale_relevant_extension_keys();
+ auto const& relevant_extension_keys = Locale::relevant_extension_keys();
// 3. Let internalSlotsList be « [[InitializedLocale]], [[Locale]], [[Calendar]], [[Collation]], [[HourCycle]], [[NumberingSystem]] ».
// 4. If relevantExtensionKeys contains "kf", then