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.
This commit is contained in:
Timothy Flynn 2022-03-21 19:59:03 -04:00 committed by Andreas Kling
parent dc94879b83
commit 324f709d29
Notes: sideshowbarker 2024-07-17 16:58:06 +09:00

View file

@ -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@));
)~~~");
} else {
if (!optional_default_value.has_value()) {
if (!optional_default_value.has_value() || optional_default_value == "null"sv) {
union_generator.append(R"~~~(
Optional<@union_type@> @cpp_name@;
if (!@js_name@@js_suffix@.is_undefined())