Coverage Report

Created: 2026-11-13 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021-2022, Tim Flynn <trflynn89@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Optional.h>
10
#include <AK/String.h>
11
#include <AK/StringView.h>
12
#include <LibJS/Runtime/Object.h>
13
#include <LibLocale/Locale.h>
14
15
namespace JS::Intl {
16
17
class DisplayNames final : public Object {
18
    JS_OBJECT(DisplayNames, Object);
19
    JS_DECLARE_ALLOCATOR(DisplayNames);
20
21
    enum class Type {
22
        Invalid,
23
        Language,
24
        Region,
25
        Script,
26
        Currency,
27
        Calendar,
28
        DateTimeField,
29
    };
30
31
    enum class Fallback {
32
        Invalid,
33
        None,
34
        Code,
35
    };
36
37
    enum class LanguageDisplay {
38
        Dialect,
39
        Standard,
40
    };
41
42
public:
43
0
    virtual ~DisplayNames() override = default;
44
45
0
    String const& locale() const { return m_locale; }
46
0
    void set_locale(String locale) { m_locale = move(locale); }
47
48
0
    ::Locale::Style style() const { return m_style; }
49
0
    void set_style(StringView style) { m_style = ::Locale::style_from_string(style); }
50
0
    StringView style_string() const { return ::Locale::style_to_string(m_style); }
51
52
0
    Type type() const { return m_type; }
53
    void set_type(StringView type);
54
    StringView type_string() const;
55
56
0
    Fallback fallback() const { return m_fallback; }
57
    void set_fallback(StringView fallback);
58
    StringView fallback_string() const;
59
60
0
    bool has_language_display() const { return m_language_display.has_value(); }
61
0
    LanguageDisplay language_display() const { return *m_language_display; }
62
    void set_language_display(StringView language_display);
63
    StringView language_display_string() const;
64
65
private:
66
    DisplayNames(Object& prototype);
67
68
    String m_locale;                                   // [[Locale]]
69
    ::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]]
70
    Type m_type { Type::Invalid };                     // [[Type]]
71
    Fallback m_fallback { Fallback::Invalid };         // [[Fallback]]
72
    Optional<LanguageDisplay> m_language_display {};   // [[LanguageDisplay]]
73
};
74
75
ThrowCompletionOr<Value> canonical_code_for_display_names(VM&, DisplayNames::Type, StringView code);
76
bool is_valid_date_time_field_code(StringView field);
77
78
}