mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
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:
parent
dcb7842f59
commit
b1b73f32a7
Notes:
github-actions[bot]
2025-04-06 12:26:37 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/b1b73f32a73 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3847 Reviewed-by: https://github.com/trflynn89
1 changed files with 6 additions and 12 deletions
|
@ -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();
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue