mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
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:
committed by
Andreas Kling
parent
a797a92990
commit
a20188cd91
Notes:
sideshowbarker
2024-07-17 21:11:12 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/a20188cd91 Pull-request: https://github.com/SerenityOS/serenity/pull/13673
@@ -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;
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user