LibWeb/IDL: Add support for returning nullable sequence types
This commit is contained in:
parent
633ac53c0c
commit
85c617fb1c
Notes:
sideshowbarker
2024-07-17 14:33:07 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/85c617fb1c Pull-request: https://github.com/SerenityOS/serenity/pull/14184 Reviewed-by: https://github.com/Quaker762 ✅ Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/sunverwerth
1 changed files with 16 additions and 0 deletions
|
@ -1319,6 +1319,12 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
|
|||
if (@value@.is_null()) {
|
||||
@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"~~~(
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue