mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
Meta/IDL: Ensure unique variable name when iterating dictionary members
This commit is contained in:
parent
69c6b6df91
commit
7f2b431810
Notes:
github-actions[bot]
2025-08-27 08:00:04 +00:00
Author: https://github.com/stelar7
Commit: 7f2b431810
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5665
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/trflynn89
1 changed files with 10 additions and 6 deletions
|
@ -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<IDL::ParameterizedType>(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"~~~(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue