Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/CSSNamespaceRule.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibJS/Heap/Heap.h>
8
#include <LibJS/Runtime/Realm.h>
9
#include <LibWeb/Bindings/CSSNamespaceRulePrototype.h>
10
#include <LibWeb/Bindings/Intrinsics.h>
11
#include <LibWeb/CSS/CSSNamespaceRule.h>
12
#include <LibWeb/CSS/Serialize.h>
13
#include <LibWeb/WebIDL/ExceptionOr.h>
14
15
namespace Web::CSS {
16
17
JS_DEFINE_ALLOCATOR(CSSNamespaceRule);
18
19
CSSNamespaceRule::CSSNamespaceRule(JS::Realm& realm, Optional<FlyString> prefix, FlyString namespace_uri)
20
0
    : CSSRule(realm, Type::Namespace)
21
0
    , m_namespace_uri(move(namespace_uri))
22
0
    , m_prefix(prefix.value_or(""_fly_string))
23
0
{
24
0
}
25
26
JS::NonnullGCPtr<CSSNamespaceRule> CSSNamespaceRule::create(JS::Realm& realm, Optional<FlyString> prefix, FlyString namespace_uri)
27
0
{
28
0
    return realm.heap().allocate<CSSNamespaceRule>(realm, realm, move(prefix), move(namespace_uri));
29
0
}
30
31
void CSSNamespaceRule::initialize(JS::Realm& realm)
32
0
{
33
0
    Base::initialize(realm);
34
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSNamespaceRule);
35
0
}
36
37
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
38
String CSSNamespaceRule::serialized() const
39
0
{
40
0
    StringBuilder builder;
41
    // The literal string "@namespace", followed by a single SPACE (U+0020),
42
0
    builder.append("@namespace "sv);
43
44
    // followed by the serialization as an identifier of the prefix attribute (if any),
45
0
    if (!m_prefix.is_empty()) {
46
0
        serialize_an_identifier(builder, m_prefix);
47
        // followed by a single SPACE (U+0020) if there is a prefix,
48
0
        builder.append(" "sv);
49
0
    }
50
51
    //  followed by the serialization as URL of the namespaceURI attribute,
52
0
    serialize_a_url(builder, m_namespace_uri);
53
54
    // followed the character ";" (U+003B).
55
0
    builder.append(";"sv);
56
57
0
    return MUST(builder.to_string());
58
0
}
59
60
}