summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-06-04 03:58:30 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-13 21:45:27 +0100
commit85c617fb1c101f457c7f64014b33edd22cd131a1 (patch)
tree2b48d6a16db4c28dcfed804c98a4c03e870dd39a
parent633ac53c0c61056c526333183b17efb9641eb7f0 (diff)
downloadserenity-85c617fb1c101f457c7f64014b33edd22cd131a1.zip
LibWeb/IDL: Add support for returning nullable sequence types
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
index 50a71a736d..28a839fd66 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
@@ -1320,6 +1320,12 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
@result_expression@ JS::js_null();
} else {
)~~~");
+ } else if (type.name == "sequence") {
+ scoped_generator.append(R"~~~(
+ if (!@value@.has_value()) {
+ @result_expression@ JS::js_null();
+ } else {
+)~~~");
} else {
scoped_generator.append(R"~~~(
if (!@value@) {
@@ -1339,10 +1345,20 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
scoped_generator.append(R"~~~(
auto* new_array@recursion_depth@ = MUST(JS::Array::create(global_object, 0));
+)~~~");
+ if (!type.nullable) {
+ scoped_generator.append(R"~~~(
for (size_t i@recursion_depth@ = 0; i@recursion_depth@ < @value@.size(); ++i@recursion_depth@) {
auto& element@recursion_depth@ = @value@.at(i@recursion_depth@);
)~~~");
+ } else {
+ scoped_generator.append(R"~~~(
+ auto& @value@_non_optional = @value@.value();
+ for (size_t i@recursion_depth@ = 0; i@recursion_depth@ < @value@_non_optional.size(); ++i@recursion_depth@) {
+ auto& element@recursion_depth@ = @value@_non_optional.at(i@recursion_depth@);
+)~~~");
+ }
generate_wrap_statement(scoped_generator, String::formatted("element{}", recursion_depth), sequence_generic_type.parameters.first(), interface, String::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);