From 110d73d78604b375c81e2c11e3ce03f020e15c81 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Fri, 1 Apr 2022 23:31:46 +0300 Subject: LibWeb: Strip double quotes from IDL enum default values --- .../CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Meta/Lagom') diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 850ee15e35..8d05d704c1 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -560,7 +560,16 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } else if (interface.enumerations.contains(parameter.type->name)) { auto enum_generator = scoped_generator.fork(); auto& enumeration = interface.enumerations.find(parameter.type->name)->value; - enum_generator.set("enum.default.cpp_value", *enumeration.translated_cpp_names.get(optional_default_value.value_or(enumeration.first_member))); + StringView enum_member_name; + if (optional_default_value.has_value()) { + VERIFY(optional_default_value->length() >= 2 && (*optional_default_value)[0] == '"' && (*optional_default_value)[optional_default_value->length() - 1] == '"'); + enum_member_name = optional_default_value->substring_view(1, optional_default_value->length() - 2); + } else { + enum_member_name = enumeration.first_member; + } + auto default_value_cpp_name = enumeration.translated_cpp_names.get(enum_member_name); + VERIFY(default_value_cpp_name.has_value()); + enum_generator.set("enum.default.cpp_value", *default_value_cpp_name); enum_generator.set("js_name.as_string", String::formatted("{}{}_string", enum_generator.get("js_name"), enum_generator.get("js_suffix"))); enum_generator.append(R"~~~( @parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ }; -- cgit v1.2.3