From 4a62268d7350f7b7f0df82ad7932ef1d5a661237 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 21 Apr 2024 12:57:00 +1200 Subject: [PATCH] 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. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 671dfa9822a..d6051224c69 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2622,19 +2622,21 @@ enum class @enum.type.name@ { )~~~"); enum_generator.append(R"~~~( -inline String idl_enum_to_string(@enum.type.name@ value) { - switch(value) { +inline String idl_enum_to_string(@enum.type.name@ value) +{ + switch (value) { )~~~"); for (auto& entry : it.value.translated_cpp_names) { enum_generator.set("enum.entry", entry.value); enum_generator.set("enum.string", entry.key); 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"~~~( - default: return ""_string; - }; + } + VERIFY_NOT_REACHED(); } )~~~"); }