From 939779cad39c4e9c0846a5dc4276057c3fa10a4d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 18 Feb 2024 15:06:12 -0500 Subject: [PATCH] LibWeb: Support nullable integral IDL types We currently support optional integral types, but not nullable types. So if an IDL contains e.g. "long?", passing null will be coerced to 0. This will be used by the Inspector, but will also eventually be used by real IDL interfaces (e.g. HTMLInputElement's selectionStart). --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index aa7b7717be..a47a20d178 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -396,7 +396,7 @@ static void generate_to_integral(SourceGenerator& scoped_generator, ParameterTyp VERIFY(it != idl_type_map.end()); scoped_generator.set("cpp_type"sv, it->cpp_type); - if (!optional || optional_default_value.has_value()) { + if ((!optional && !parameter.type->is_nullable()) || optional_default_value.has_value()) { scoped_generator.append(R"~~~( @cpp_type@ @cpp_name@; )~~~"); @@ -406,7 +406,11 @@ static void generate_to_integral(SourceGenerator& scoped_generator, ParameterTyp )~~~"); } - if (optional) { + if (parameter.type->is_nullable()) { + scoped_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_null() && !@js_name@@js_suffix@.is_undefined()) +)~~~"); + } else if (optional) { scoped_generator.append(R"~~~( if (!@js_name@@js_suffix@.is_undefined()) )~~~");