Skip to content

Commit

Permalink
IDLGenerators: Allow methods with multiple sequence arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tcl3 authored and awesomekling committed Jan 3, 2025
1 parent aa82ff8 commit 10c5b9c
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,12 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@[email protected]_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@[email protected]_string_without_side_effects());
auto iterator_method@recursion_depth@ = TRY(@js_name@@[email protected]_method(vm, vm.well_known_symbol_iterator()));
if (!iterator_method@recursion_depth@)
auto @js_name@@js_suffix@_iterator_method@recursion_depth@ = TRY(@js_name@@[email protected]_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@@[email protected]_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"~~~(
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 10c5b9c

Please sign in to comment.