mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibJS: Implement a nearly empty Intl.DisplayNames object
This adds plumbing for the Intl.DisplayNames object, constructor, and prototype.
This commit is contained in:
committed by
Linus Groh
parent
137e98cb6f
commit
0fb4e8b749
Notes:
sideshowbarker
2024-07-18 05:15:39 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0fb4e8b749d Pull-request: https://github.com/SerenityOS/serenity/pull/9599 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg ✅
99
Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
Normal file
99
Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/DisplayNames.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
// 12 DisplayNames Objects, https://tc39.es/ecma402/#intl-displaynames-objects
|
||||
DisplayNames::DisplayNames(Object& prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayNames::set_style(StringView style)
|
||||
{
|
||||
if (style == "narrow"sv) {
|
||||
m_style = Style::Narrow;
|
||||
} else if (style == "short"sv) {
|
||||
m_style = Style::Short;
|
||||
} else if (style == "long"sv) {
|
||||
m_style = Style::Long;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
StringView DisplayNames::style_string() const
|
||||
{
|
||||
switch (m_style) {
|
||||
case Style::Narrow:
|
||||
return "narrow"sv;
|
||||
case Style::Short:
|
||||
return "short"sv;
|
||||
case Style::Long:
|
||||
return "long"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayNames::set_type(StringView type)
|
||||
{
|
||||
if (type == "language"sv) {
|
||||
m_type = Type::Language;
|
||||
} else if (type == "region"sv) {
|
||||
m_type = Type::Region;
|
||||
} else if (type == "script"sv) {
|
||||
m_type = Type::Script;
|
||||
} else if (type == "currency"sv) {
|
||||
m_type = Type::Currency;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
StringView DisplayNames::type_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Language:
|
||||
return "language"sv;
|
||||
case Type::Region:
|
||||
return "region"sv;
|
||||
case Type::Script:
|
||||
return "script"sv;
|
||||
case Type::Currency:
|
||||
return "currency"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayNames::set_fallback(StringView fallback)
|
||||
{
|
||||
if (fallback == "none"sv) {
|
||||
m_fallback = Fallback::None;
|
||||
} else if (fallback == "code"sv) {
|
||||
m_fallback = Fallback::Code;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
StringView DisplayNames::fallback_string() const
|
||||
{
|
||||
switch (m_fallback) {
|
||||
case Fallback::None:
|
||||
return "none"sv;
|
||||
case Fallback::Code:
|
||||
return "code"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user