LibIDL: Allow iterable<T> to be defined before property getter

Previously, an error would occur if an `iterable<T>` was defined before
the required value iterator. An is now also reported if an`iterable<T>`
is defined before a pair iterator, previously this error would only be
reported if the iterable was defined after the pair iterator.
This commit is contained in:
Tim Ledbetter 2025-09-02 07:23:26 +01:00 committed by Sam Atkins
commit fdbd25967b
Notes: github-actions[bot] 2025-09-02 09:42:49 +00:00
2 changed files with 14 additions and 6 deletions

View file

@ -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);

View file

@ -287,7 +287,9 @@ public:
bool has_unscopable_member { false };
Optional<NonnullRefPtr<Type const>> value_iterator_type;
Optional<size_t> value_iterator_offset;
Optional<Tuple<NonnullRefPtr<Type const>, NonnullRefPtr<Type const>>> pair_iterator_types;
Optional<size_t> pair_iterator_offset;
Optional<NonnullRefPtr<Type const>> async_value_iterator_type;
Vector<Parameter> async_value_iterator_parameters;