LibWeb: Use generated enum code for property value validation

This has the nice benefit of removing a lot of duplicated lists of
values from Properties.json. :^)
This commit is contained in:
Sam Atkins
2022-04-14 11:23:23 +01:00
committed by Andreas Kling
parent a797a92990
commit a20188cd91
Notes: sideshowbarker 2024-07-17 21:11:12 +09:00
2 changed files with 78 additions and 261 deletions

View File

@@ -150,6 +150,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::Stream:
generator.append(R"~~~(
#include <AK/Assertions.h>
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleValue.h>
@@ -512,8 +513,13 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
} else if (type_name == "url") {
// FIXME: Handle urls!
} else {
warnln("Unrecognized valid-type name: '{}'", type_name);
VERIFY_NOT_REACHED();
// Assume that any other type names are defined in Enums.json.
// If they're not, the output won't compile, but that's fine since it's invalid.
property_generator.set("type_name:snakecase", snake_casify(type_name));
property_generator.append(R"~~~(
if (auto converted_identifier = value_id_to_@type_name:snakecase@(style_value.to_identifier()); converted_identifier.has_value())
return true;
)~~~");
}
}
}