IDLGenerators: Support nullable dictionary members with default values

When wrapping dictionary members, generate_wrap_statement was called
with the pattern "auto {} = ...", where "..." was determined based on
the variable's type. However, in generate_wrap_statement, if a type is
nullable it generates an if statement, so this would end up generating
something along the lines of

    if (!retval.member.has_value()) {
    	auto wrapped_member0_value = JS::js_null();
    } else {
    	auto wrapped_member0_value = JS::Value(...);
    }

...which makes the declaration inaccessible. It now generates the same
code, but the "auto" declaration (now an explicit JS::Value declaration)
is outside of the if-statement.
This commit is contained in:
Matthew Olsson 2023-11-06 15:17:10 +00:00 committed by Andreas Kling
parent 111e0159ff
commit e03e710d1b
Notes: sideshowbarker 2024-07-17 03:25:24 +09:00

View file

@ -1770,7 +1770,11 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
auto wrapped_value_name = DeprecatedString::formatted("wrapped_{}", member_value_js_name);
dictionary_generator.set("wrapped_value_name", wrapped_value_name);
generate_wrap_statement(dictionary_generator, DeprecatedString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, DeprecatedString::formatted("auto {} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
dictionary_generator.append(R"~~~(
JS::Value @wrapped_value_name@;
)~~~");
generate_wrap_statement(dictionary_generator, DeprecatedString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, DeprecatedString::formatted("{} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
dictionary_generator.append(R"~~~(
MUST(dictionary_object@recursion_depth@->create_data_property("@member_key@", @wrapped_value_name@));