From fdbd25967ba934b951511e377fed6aa06bcbeb30 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 2 Sep 2025 07:23:26 +0100 Subject: [PATCH] LibIDL: Allow `iterable` to be defined before property getter Previously, an error would occur if an `iterable` was defined before the required value iterator. An is now also reported if an`iterable` is defined before a pair iterator, previously this error would only be reported if the iterable was defined after the pair iterator. --- Libraries/LibIDL/IDLParser.cpp | 18 ++++++++++++------ Libraries/LibIDL/Types.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Libraries/LibIDL/IDLParser.cpp b/Libraries/LibIDL/IDLParser.cpp index 0b8af808210..4e854a9e131 100644 --- a/Libraries/LibIDL/IDLParser.cpp +++ b/Libraries/LibIDL/IDLParser.cpp @@ -518,18 +518,14 @@ void Parser::parse_iterable(Interface& interface) assert_specific('<'); auto first_type = parse_type(); if (lexer.next_is(',')) { - if (interface.supports_indexed_properties()) - report_parsing_error("Interfaces with a pair iterator must not support indexed properties."sv, filename, input, lexer.tell()); - assert_specific(','); consume_whitespace(); auto second_type = parse_type(); interface.pair_iterator_types = Tuple { move(first_type), move(second_type) }; + interface.pair_iterator_offset = lexer.tell(); } else { - if (!interface.supports_indexed_properties()) - report_parsing_error("Interfaces with a value iterator must support indexed properties."sv, filename, input, lexer.tell()); - interface.value_iterator_type = move(first_type); + interface.value_iterator_offset = lexer.tell(); } if (interface.async_value_iterator_type.has_value()) @@ -806,6 +802,16 @@ void Parser::parse_interface(Interface& interface) else interface.implemented_name = interface.name; + if (interface.pair_iterator_types.has_value() && interface.indexed_property_getter.has_value()) { + VERIFY(interface.pair_iterator_offset.has_value()); + report_parsing_error("Interfaces with a pair iterator must not support indexed properties."sv, filename, input, *interface.pair_iterator_offset); + } + + if (interface.value_iterator_type.has_value() && !interface.supports_indexed_properties()) { + VERIFY(interface.value_iterator_offset.has_value()); + report_parsing_error("Interfaces with a value iterator must support indexed properties."sv, filename, input, *interface.value_iterator_offset); + } + interface.constructor_class = ByteString::formatted("{}Constructor", interface.implemented_name); interface.prototype_class = ByteString::formatted("{}Prototype", interface.implemented_name); interface.prototype_base_class = ByteString::formatted("{}Prototype", interface.parent_name.is_empty() ? "Object" : interface.parent_name); diff --git a/Libraries/LibIDL/Types.h b/Libraries/LibIDL/Types.h index 20dbf71c626..bd3ca7304cf 100644 --- a/Libraries/LibIDL/Types.h +++ b/Libraries/LibIDL/Types.h @@ -287,7 +287,9 @@ public: bool has_unscopable_member { false }; Optional> value_iterator_type; + Optional value_iterator_offset; Optional, NonnullRefPtr>> pair_iterator_types; + Optional pair_iterator_offset; Optional> async_value_iterator_type; Vector async_value_iterator_parameters;