From 8f3fe0c39ec4c378d8594f1f7e04901883398cec Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Thu, 19 Jun 2025 13:44:49 +0200 Subject: [PATCH] LibWeb: Support nullable attributes in generated `toJSON()` Any optional or nullable attribute will end up in an `if/else` branch when we collect the attribute values, and this is inherently incompatibly with an `auto {attr}_wrapped = ...` expression. Define the variable as an `JS::Value` before generating the wrap statement so we can properly support `toJSON()` for an attribute like: readonly attribute double? altitude; --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 2d47ae30a7a..51c0be7fe49 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3161,7 +3161,10 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu )~~~"); } - generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, ByteString::formatted("auto {}_wrapped =", return_value_name)); + attribute_generator.append(R"~~~( + JS::Value @attribute.return_value_name@_wrapped; +)~~~"); + generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, ByteString::formatted("{}_wrapped =", return_value_name)); attribute_generator.append(R"~~~( MUST(result->create_data_property("@attribute.name@"_fly_string, @attribute.return_value_name@_wrapped));