Browse Source

LibWeb: Support IDL default values of "null" for optional arguments

This is a bit strange in the IDL syntax, but e.g., in HTMLSelectElement,
we have (simplified):

    undefined add(optional (HTMLElement or long)? before = null)

This could instead become:

    undefined add(optional (HTMLElement or long) before)

This change generates code for the former as if it were the latter.
Timothy Flynn 3 years ago
parent
commit
324f709d29

+ 1 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp

@@ -1050,7 +1050,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
     @union_type@ @cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
     @union_type@ @cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
 )~~~");
 )~~~");
             } else {
             } else {
-                if (!optional_default_value.has_value()) {
+                if (!optional_default_value.has_value() || optional_default_value == "null"sv) {
                     union_generator.append(R"~~~(
                     union_generator.append(R"~~~(
     Optional<@union_type@> @cpp_name@;
     Optional<@union_type@> @cpp_name@;
     if (!@js_name@@js_suffix@.is_undefined())
     if (!@js_name@@js_suffix@.is_undefined())