diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-06-04 03:57:54 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-13 21:45:27 +0100 |
commit | 633ac53c0c61056c526333183b17efb9641eb7f0 (patch) | |
tree | 7f52a449883a1abc5ac90e1abc4cfe81902a5bfd /Meta/Lagom | |
parent | 2a27f2293af58ecbad81164c31a41e590a63aa6c (diff) | |
download | serenity-633ac53c0c61056c526333183b17efb9641eb7f0.zip |
LibWeb/IDL: Add support for optional enums
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 184fa68156..50a71a736d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -577,6 +577,15 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter 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@ }; +)~~~"); + + if (optional) { + enum_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_undefined()) { +)~~~"); + } + + enum_generator.append(R"~~~( auto @js_name.as_string@ = TRY(@js_name@@js_suffix@.to_string(global_object)); )~~~"); auto first = true; @@ -596,6 +605,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter @else@ return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidEnumerationValue, @js_name.as_string@, "@parameter.type.name@"); )~~~"); + + if (optional) { + enum_generator.append(R"~~~( + } +)~~~"); } } else if (interface.dictionaries.contains(parameter.type->name)) { if (optional_default_value.has_value() && optional_default_value != "{}") |