LibWeb/CSS: Include guaranteed-invalid value in ComponentValue

Treating these like any other ComponentValue means not having to convert
between different types of Vector, and that we will be able to use
TokenStream to parse the "argument grammars" of arbitrary substitution
functions.
This commit is contained in:
Sam Atkins 2025-06-18 17:24:19 +01:00 committed by Tim Ledbetter
parent b5ed910f1f
commit 9079be850b
Notes: github-actions[bot] 2025-07-09 15:46:20 +00:00
4 changed files with 44 additions and 4 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,7 +10,7 @@
namespace Web::CSS::Parser {
ComponentValue::ComponentValue(Token token)
: m_value(token)
: m_value(move(token))
{
}
ComponentValue::ComponentValue(Function&& function)
@ -21,6 +21,10 @@ ComponentValue::ComponentValue(SimpleBlock&& block)
: m_value(move(block))
{
}
ComponentValue::ComponentValue(GuaranteedInvalidValue&& invalid)
: m_value(move(invalid))
{
}
ComponentValue::~ComponentValue() = default;
@ -50,6 +54,9 @@ String ComponentValue::to_debug_string() const
},
[](Function const& function) {
return MUST(String::formatted("Function: {}", function.to_string()));
},
[](GuaranteedInvalidValue const&) {
return "Guaranteed-invalid value"_string;
});
}
@ -58,4 +65,25 @@ String ComponentValue::original_source_text() const
return m_value.visit([](auto const& it) { return it.original_source_text(); });
}
bool ComponentValue::contains_guaranteed_invalid_value() const
{
return m_value.visit(
[](Token const&) {
return false;
},
[](SimpleBlock const& block) {
return block.value
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
.has_value();
},
[](Function const& function) {
return function.value
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
.has_value();
},
[](GuaranteedInvalidValue const&) {
return true;
});
}
}