From 7f2b4318100c3875410b571cf91109bcb1de74b7 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Thu, 31 Jul 2025 11:44:04 +0200 Subject: [PATCH] Meta/IDL: Ensure unique variable name when iterating dictionary members --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index ed52e11d5d2..531dd107a47 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1841,7 +1841,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge )~~~"); } -static void generate_wrap_statement(SourceGenerator& generator, ByteString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, size_t recursion_depth = 0, bool is_optional = false) +static void generate_wrap_statement(SourceGenerator& generator, ByteString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, size_t recursion_depth = 0, bool is_optional = false, size_t iteration_index = 0) { auto scoped_generator = generator.fork(); scoped_generator.set("value", value); @@ -1861,6 +1861,7 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const } scoped_generator.set("result_expression", result_expression); scoped_generator.set("recursion_depth", ByteString::number(recursion_depth)); + scoped_generator.set("iteration_index", ByteString::number(iteration_index)); if (type.name() == "undefined") { scoped_generator.append(R"~~~( @@ -1912,7 +1913,7 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const auto& sequence_generic_type = as(type); scoped_generator.append(R"~~~( - auto new_array@recursion_depth@ = MUST(JS::Array::create(realm, 0)); + auto new_array@recursion_depth@_@iteration_index@ = MUST(JS::Array::create(realm, 0)); )~~~"); if (type.is_nullable() || is_optional) { @@ -1942,18 +1943,18 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const scoped_generator.append(R"~~~( auto property_index@recursion_depth@ = JS::PropertyKey { i@recursion_depth@ }; - MUST(new_array@recursion_depth@->create_data_property(property_index@recursion_depth@, wrapped_element@recursion_depth@)); + MUST(new_array@recursion_depth@_@iteration_index@->create_data_property(property_index@recursion_depth@, wrapped_element@recursion_depth@)); } )~~~"); if (type.name() == "FrozenArray"sv) { scoped_generator.append(R"~~~( - TRY(new_array@recursion_depth@->set_integrity_level(IntegrityLevel::Frozen)); + TRY(new_array@recursion_depth@_@iteration_index@->set_integrity_level(IntegrityLevel::Frozen)); )~~~"); } scoped_generator.append(R"~~~( - @result_expression@ new_array@recursion_depth@; + @result_expression@ new_array@recursion_depth@_@iteration_index@; )~~~"); } else if (type.name() == "record") { // https://webidl.spec.whatwg.org/#es-record @@ -2096,6 +2097,7 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const auto dictionary_object@recursion_depth@ = JS::Object::create(realm, realm.intrinsics().object_prototype()); )~~~"); + auto next_iteration_index = iteration_index + 1; auto* current_dictionary = &interface.dictionaries.find(type.name())->value; while (true) { for (auto& member : current_dictionary->members) { @@ -2124,7 +2126,9 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const JS::Value @wrapped_value_name@; )~~~"); } - generate_wrap_statement(dictionary_generator, ByteString::formatted("{}{}{}", value, type.is_nullable() ? "->" : ".", member.name.to_snakecase()), member.type, interface, ByteString::formatted("{} =", wrapped_value_name), recursion_depth + 1, is_optional); + + next_iteration_index++; + generate_wrap_statement(dictionary_generator, ByteString::formatted("{}{}{}", value, type.is_nullable() ? "->" : ".", member.name.to_snakecase()), member.type, interface, ByteString::formatted("{} =", wrapped_value_name), recursion_depth + 1, is_optional, next_iteration_index); if (is_optional) { dictionary_generator.append(R"~~~(