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).
This commit is contained in:
Timothy Flynn 2024-02-18 15:06:12 -05:00 committed by Andreas Kling
parent 1cb450e9a3
commit 939779cad3
Notes: sideshowbarker 2024-07-17 06:46:15 +09:00

View File

@ -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())
)~~~");