mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
LibJS: Parse new Intl.DisplayNames "type" and "languageDisplay" options
Intl.DisplayNames v2 adds "calendar" and "dateTimeField" types, as well as a "languageDisplay" option for the "language" type. This just adds these options to the constructor.
This commit is contained in:
parent
853ccab9af
commit
71f7e67a20
6 changed files with 102 additions and 14 deletions
|
@ -53,6 +53,10 @@ void DisplayNames::set_type(StringView type)
|
|||
m_type = Type::Script;
|
||||
else if (type == "currency"sv)
|
||||
m_type = Type::Currency;
|
||||
else if (type == "calendar"sv)
|
||||
m_type = Type::Calendar;
|
||||
else if (type == "dateTimeField"sv)
|
||||
m_type = Type::DateTimeField;
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -68,6 +72,10 @@ StringView DisplayNames::type_string() const
|
|||
return "script"sv;
|
||||
case Type::Currency:
|
||||
return "currency"sv;
|
||||
case Type::Calendar:
|
||||
return "calendar"sv;
|
||||
case Type::DateTimeField:
|
||||
return "dateTimeField"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -95,6 +103,30 @@ StringView DisplayNames::fallback_string() const
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayNames::set_language_display(StringView language_display)
|
||||
{
|
||||
if (language_display == "dialect"sv)
|
||||
m_language_display = LanguageDisplay::Dialect;
|
||||
else if (language_display == "standard"sv)
|
||||
m_language_display = LanguageDisplay::Standard;
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
StringView DisplayNames::language_display_string() const
|
||||
{
|
||||
VERIFY(m_language_display.has_value());
|
||||
|
||||
switch (*m_language_display) {
|
||||
case LanguageDisplay::Dialect:
|
||||
return "dialect"sv;
|
||||
case LanguageDisplay::Standard:
|
||||
return "standard"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
// 12.1.1 CanonicalCodeForDisplayNames ( type, code ), https://tc39.es/ecma402/#sec-canonicalcodefordisplaynames
|
||||
ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_object, DisplayNames::Type type, StringView code)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue