Coverage Report

Created: 2026-07-25 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/CSS.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
3
 * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#include <LibJS/Runtime/VM.h>
9
#include <LibWeb/CSS/CSS.h>
10
#include <LibWeb/CSS/Parser/Parser.h>
11
#include <LibWeb/CSS/PropertyID.h>
12
#include <LibWeb/CSS/PropertyName.h>
13
#include <LibWeb/CSS/Serialize.h>
14
15
namespace Web::CSS {
16
17
// https://www.w3.org/TR/cssom-1/#dom-css-escape
18
WebIDL::ExceptionOr<String> escape(JS::VM&, StringView identifier)
19
0
{
20
    // The escape(ident) operation must return the result of invoking serialize an identifier of ident.
21
0
    return serialize_an_identifier(identifier);
22
0
}
23
24
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
25
bool supports(JS::VM& vm, StringView property, StringView value)
26
0
{
27
0
    auto& realm = *vm.current_realm();
28
29
    // 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
30
    //    and value successfully parses according to that property’s grammar, return true.
31
0
    if (auto property_id = property_id_from_string(property); property_id.has_value()) {
32
0
        if (parse_css_value(Parser::ParsingContext { realm }, value, property_id.value()))
33
0
            return true;
34
0
    }
35
36
    // 2. Otherwise, if property is a custom property name string, return true.
37
0
    else if (is_a_custom_property_name_string(property)) {
38
0
        return true;
39
0
    }
40
41
    // 3. Otherwise, return false.
42
0
    return false;
43
0
}
44
45
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
46
WebIDL::ExceptionOr<bool> supports(JS::VM& vm, StringView condition_text)
47
0
{
48
0
    auto& realm = *vm.current_realm();
49
50
    // 1. If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
51
0
    if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, condition_text); supports && supports->matches())
52
0
        return true;
53
54
    // 2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
55
0
    auto wrapped_condition_text = TRY_OR_THROW_OOM(vm, String::formatted("({})", condition_text));
56
57
0
    if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, wrapped_condition_text); supports && supports->matches())
58
0
        return true;
59
60
    // 3. Otherwise, return false.
61
0
    return false;
62
0
}
63
64
}