LibWeb/Bindings: Invert logic for nullability check in wrap statements

This is less code, and also makes a future bugfix much simpler to
implement :^)
This commit is contained in:
Shannon Booth 2025-03-23 20:19:10 +13:00 committed by Tim Flynn
parent dcb7842f59
commit b1b73f32a7
Notes: github-actions[bot] 2025-04-06 12:26:37 +00:00

View file

@ -1796,27 +1796,19 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const
if ((is_optional || type.is_nullable()) && !is<UnionType>(type)) {
if (type.is_string()) {
scoped_generator.append(R"~~~(
if (!@value@.has_value()) {
@result_expression@ JS::js_null();
} else {
if (@value@.has_value()) {
)~~~");
} else if (type.name() == "sequence") {
scoped_generator.append(R"~~~(
if (!@value@.has_value()) {
@result_expression@ JS::js_null();
} else {
if (@value@.has_value()) {
)~~~");
} else if (type.is_primitive() || interface.enumerations.contains(type.name()) || interface.dictionaries.contains(type.name())) {
scoped_generator.append(R"~~~(
if (!@value@.has_value()) {
@result_expression@ JS::js_null();
} else {
if (@value@.has_value()) {
)~~~");
} else {
scoped_generator.append(R"~~~(
if (!@value@) {
@result_expression@ JS::js_null();
} else {
if (@value@) {
)~~~");
}
}
@ -2071,6 +2063,8 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const
if ((type.is_nullable() || is_optional) && !is<UnionType>(type)) {
scoped_generator.append(R"~~~(
} else {
@result_expression@ JS::js_null();
}
)~~~");
}