LibWeb: Generate property_maximum_value_count()

This will allow the CSS Parser to check if a property has been give too
many arguments, and if so, reject it as invalid.
This commit is contained in:
Sam Atkins 2021-09-22 12:24:33 +01:00 committed by Andreas Kling
parent e40ea819d9
commit a1bc89b814
Notes: sideshowbarker 2024-07-18 03:32:59 +09:00
2 changed files with 28 additions and 0 deletions

View file

@ -252,6 +252,32 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk)
}
}
size_t property_maximum_value_count(PropertyID property_id)
{
switch (property_id) {
)~~~");
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
if (value.as_object().has("max-values")) {
auto max_values = value.as_object().get("max-values");
VERIFY(max_values.is_number() && !max_values.is_double());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", title_casify(name));
property_generator.set("max_values", max_values.to_string());
property_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
return @max_values@;
)~~~");
}
});
generator.append(R"~~~(
default:
return 1;
}
}
} // namespace Web::CSS
)~~~");

View file

@ -106,6 +106,8 @@ bool is_inherited_property(PropertyID);
bool is_pseudo_property(PropertyID);
RefPtr<StyleValue> property_initial_value(PropertyID);
size_t property_maximum_value_count(PropertyID);
constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;