mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibWeb: Ensure that CSS initial values are always valid :^)
First off, this verifies that an initial value is always provided in Properties.json for each property. Second, it verifies that parsing that initial value succeeds. This means that a call to `property_initial_value()` will always return a valid StyleValue. :^)
This commit is contained in:
parent
63aa399873
commit
4d42915485
1 changed files with 17 additions and 12 deletions
|
@ -182,19 +182,24 @@ RefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
// works for now! :^)
|
// works for now! :^)
|
||||||
|
|
||||||
auto output_initial_value_code = [&](auto& name, auto& object) {
|
auto output_initial_value_code = [&](auto& name, auto& object) {
|
||||||
if (object.has("initial")) {
|
if (!object.has("initial")) {
|
||||||
auto& initial_value = object.get("initial");
|
dbgln("No initial value specified for property '{}'", name);
|
||||||
VERIFY(initial_value.is_string());
|
VERIFY_NOT_REACHED();
|
||||||
auto initial_value_string = initial_value.as_string();
|
|
||||||
|
|
||||||
auto member_generator = generator.fork();
|
|
||||||
member_generator.set("name:titlecase", title_casify(name));
|
|
||||||
member_generator.set("initial_value_string", initial_value_string);
|
|
||||||
member_generator.append(R"~~~(
|
|
||||||
if (auto parsed_value = Parser(parsing_context, "@initial_value_string@").parse_as_css_value(PropertyID::@name:titlecase@))
|
|
||||||
initial_values.set(PropertyID::@name:titlecase@, parsed_value.release_nonnull());
|
|
||||||
)~~~");
|
|
||||||
}
|
}
|
||||||
|
auto& initial_value = object.get("initial");
|
||||||
|
VERIFY(initial_value.is_string());
|
||||||
|
auto initial_value_string = initial_value.as_string();
|
||||||
|
|
||||||
|
auto member_generator = generator.fork();
|
||||||
|
member_generator.set("name:titlecase", title_casify(name));
|
||||||
|
member_generator.set("initial_value_string", initial_value_string);
|
||||||
|
member_generator.append(R"~~~(
|
||||||
|
{
|
||||||
|
auto parsed_value = Parser(parsing_context, "@initial_value_string@").parse_as_css_value(PropertyID::@name:titlecase@);
|
||||||
|
VERIFY(!parsed_value.is_null());
|
||||||
|
initial_values.set(PropertyID::@name:titlecase@, parsed_value.release_nonnull());
|
||||||
|
}
|
||||||
|
)~~~");
|
||||||
};
|
};
|
||||||
|
|
||||||
properties.for_each_member([&](auto& name, auto& value) {
|
properties.for_each_member([&](auto& name, auto& value) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue