diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp index fa82a5841d..0d9de229f0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp @@ -53,6 +53,7 @@ void LocalePrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.hourCycle, hour_cycle, {}, Attribute::Configurable); define_native_accessor(vm.names.numberingSystem, numbering_system, {}, Attribute::Configurable); define_native_accessor(vm.names.numeric, numeric, {}, Attribute::Configurable); + define_native_accessor(vm.names.language, language, {}, Attribute::Configurable); } // 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString @@ -123,4 +124,23 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::numeric) return Value(locale_object->numeric()); } +// 14.3.13 get Intl.Locale.prototype.language, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.language +JS_DEFINE_NATIVE_GETTER(LocalePrototype::language) +{ + // 1. Let loc be the this value. + // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). + auto* locale_object = typed_this(global_object); + if (!locale_object) + return {}; + + // 3. Let locale be loc.[[Locale]]. + auto locale = Unicode::parse_unicode_locale_id(locale_object->locale()); + + // 4. Assert: locale matches the unicode_locale_id production. + VERIFY(locale.has_value()); + + // 5. Return the substring of locale corresponding to the unicode_language_subtag production of the unicode_language_id. + return js_string(vm, *locale->language_id.language); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.h b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.h index bdd557c569..8827c8cda9 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.h @@ -28,6 +28,7 @@ private: JS_DECLARE_NATIVE_GETTER(hour_cycle); JS_DECLARE_NATIVE_GETTER(numbering_system); JS_DECLARE_NATIVE_GETTER(numeric); + JS_DECLARE_NATIVE_GETTER(language); }; } |