From e03e710d1b4be8511636e93538b6f82cd58db017 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Mon, 6 Nov 2023 15:17:10 +0000 Subject: [PATCH] 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. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index e9cc19ace5..cf21f3187d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -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@));