IDLGenerators: Allow methods with multiple sequence arguments

Previously, a method with multiple sequence arguments would cause a
compile error, as the same variable name was redeclared when iterating
the sequence for each argument. This change disambiguates these
variable names.
This commit is contained in:
Tim Ledbetter 2025-01-02 12:38:54 +00:00 committed by Andreas Kling
parent aa82ff8044
commit 10c5b9c07b
Notes: github-actions[bot] 2025-01-03 13:55:26 +00:00

View file

@ -1030,12 +1030,12 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
auto iterator_method@recursion_depth@ = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
if (!iterator_method@recursion_depth@)
auto @js_name@@js_suffix@_iterator_method@recursion_depth@ = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
if (!@js_name@@js_suffix@_iterator_method@recursion_depth@)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, @js_name@@js_suffix@.to_string_without_side_effects());
)~~~");
parameterized_type.generate_sequence_from_iterable(sequence_generator, ByteString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), ByteString::formatted("{}{}", js_name, js_suffix), ByteString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
parameterized_type.generate_sequence_from_iterable(sequence_generator, ByteString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), ByteString::formatted("{}{}", js_name, js_suffix), ByteString::formatted("{}{}_iterator_method{}", js_name, js_suffix, recursion_depth), interface, recursion_depth + 1);
if (optional) {
sequence_generator.append(R"~~~(
@ -1699,7 +1699,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
// FIXME: The WebIDL spec is out of date - it should be using GetIteratorFromMethod.
sequence_generator.append(R"~~~(
auto iterator@recursion_depth@ = TRY(JS::get_iterator_from_method(vm, @iterable_cpp_name@, *@iterator_method_cpp_name@));
auto @iterable_cpp_name@_iterator@recursion_depth@ = TRY(JS::get_iterator_from_method(vm, @iterable_cpp_name@, *@iterator_method_cpp_name@));
)~~~");
if (sequence_cpp_type.sequence_storage_type == SequenceStorageType::Vector) {
@ -1714,7 +1714,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
sequence_generator.append(R"~~~(
for (;;) {
auto next@recursion_depth@ = TRY(JS::iterator_step(vm, iterator@recursion_depth@));
auto next@recursion_depth@ = TRY(JS::iterator_step(vm, @iterable_cpp_name@_iterator@recursion_depth@));
if (!next@recursion_depth@)
break;