diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-01 23:31:46 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-02 13:13:37 +0300 |
commit | 110d73d78604b375c81e2c11e3ce03f020e15c81 (patch) | |
tree | e7ced0747528ddc8a59b21dcb56e9c64d54df579 /Meta/Lagom | |
parent | f744c31a6f9aaa1e961e287599c05ea55af19065 (diff) | |
download | serenity-110d73d78604b375c81e2c11e3ce03f020e15c81.zip |
LibWeb: Strip double quotes from IDL enum default values
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
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@ }; |