LibWeb: Do not handle an invalid enum in idl_enum_to_string

We should never hit this case - so don't generate code for it, and
instead put in a VERIFY_NOT_REACHED.

Also improve the formatting of the generated code to closer match the
serenity code style.
This commit is contained in:
Shannon Booth 2024-04-21 12:57:00 +12:00 committed by Andreas Kling
commit 4a62268d73
Notes: sideshowbarker 2024-07-17 03:03:15 +09:00

View file

@ -2622,19 +2622,21 @@ enum class @enum.type.name@ {
)~~~"); )~~~");
enum_generator.append(R"~~~( enum_generator.append(R"~~~(
inline String idl_enum_to_string(@enum.type.name@ value) { inline String idl_enum_to_string(@enum.type.name@ value)
switch(value) { {
switch (value) {
)~~~"); )~~~");
for (auto& entry : it.value.translated_cpp_names) { for (auto& entry : it.value.translated_cpp_names) {
enum_generator.set("enum.entry", entry.value); enum_generator.set("enum.entry", entry.value);
enum_generator.set("enum.string", entry.key); enum_generator.set("enum.string", entry.key);
enum_generator.append(R"~~~( enum_generator.append(R"~~~(
case @enum.type.name@::@enum.entry@: return "@enum.string@"_string; case @enum.type.name@::@enum.entry@:
return "@enum.string@"_string;
)~~~"); )~~~");
} }
enum_generator.append(R"~~~( enum_generator.append(R"~~~(
default: return "<unknown>"_string; }
}; VERIFY_NOT_REACHED();
} }
)~~~"); )~~~");
} }