mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:37:34 +00:00
LibWeb/IDL: Add support for returning nullable sequence types
This commit is contained in:
parent
633ac53c0c
commit
85c617fb1c
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()) {
|
if (@value@.is_null()) {
|
||||||
@result_expression@ JS::js_null();
|
@result_expression@ JS::js_null();
|
||||||
} else {
|
} else {
|
||||||
|
)~~~");
|
||||||
|
} else if (type.name == "sequence") {
|
||||||
|
scoped_generator.append(R"~~~(
|
||||||
|
if (!@value@.has_value()) {
|
||||||
|
@result_expression@ JS::js_null();
|
||||||
|
} else {
|
||||||
)~~~");
|
)~~~");
|
||||||
} else {
|
} else {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
|
@ -1339,10 +1345,20 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
|
||||||
|
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
auto* new_array@recursion_depth@ = MUST(JS::Array::create(global_object, 0));
|
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@) {
|
for (size_t i@recursion_depth@ = 0; i@recursion_depth@ < @value@.size(); ++i@recursion_depth@) {
|
||||||
auto& element@recursion_depth@ = @value@.at(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);
|
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
Add a link
Reference in a new issue