LibWeb: Add method for whether tree-counting function is allowed

Some contexts (e.g. descriptors, media conditions) don't allow tree
counting functions, this commit adds an easy way to check if the current
value context is one of those.
This commit is contained in:
Callum Law 2025-09-30 15:12:52 +13:00 committed by Tim Ledbetter
commit fd31fbd84b
Notes: github-actions[bot] 2025-10-20 15:13:55 +00:00
5 changed files with 27 additions and 1 deletions

View file

@ -1694,6 +1694,21 @@ bool Parser::context_allows_quirky_length() const
return unitless_length_allowed;
}
bool Parser::context_allows_tree_counting_functions() const
{
for (auto context : m_value_context) {
if (context.has<DescriptorContext>())
return false;
if (auto const* special_context = context.get_pointer<SpecialContext>(); special_context && first_is_one_of(*special_context, SpecialContext::DOMMatrixInitString, SpecialContext::MediaCondition))
return false;
// TODO: Handle other contexts where tree counting functions are not allowed
}
return true;
}
Vector<ComponentValue> Parser::parse_as_list_of_component_values()
{
return parse_a_list_of_component_values(m_token_stream);