mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
111e0159ff
commit
e03e710d1b
Notes:
sideshowbarker
2024-07-17 03:25:24 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/e03e710d1b Pull-request: https://github.com/SerenityOS/serenity/pull/21831
1 changed files with 5 additions and 1 deletions
|
@ -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@));
|
||||
|
|
Loading…
Reference in a new issue