Truly independent web browser
Meta: Classify the members of an interface once for the Rust bindings
Aliaksandr Kalenik0942d831da0d
diff --git a/Meta/CMake/libweb_generators.cmake b/Meta/CMake/libweb_generators.cmakeindex 1da198c65d8..729ae45097f 100644--- a/Meta/CMake/libweb_generators.cmake+++ b/Meta/CMake/libweb_generators.cmake@@ -313,6 +313,7 @@ function (generate_js_bindings target)"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/overload_resolution.py""${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/realms.py""${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_bindings.py"+ "${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_members.py""${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_names.py""${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_overloads.py""${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_to_idl_value.py"diff --git a/Meta/Generators/generate_libweb_bindings.py b/Meta/Generators/generate_libweb_bindings.pyindex 600c6722abc..e06ff03ef2f 100644--- a/Meta/Generators/generate_libweb_bindings.py+++ b/Meta/Generators/generate_libweb_bindings.py@@ -269,10 +269,10 @@ def main() -> int:context = GenerationContext(modules)modules = context.modules- usage = DefinitionUsage(context)interface_sets = collect_interface_sets(modules)try:+ usage = DefinitionUsage(context)rust_bindings.check_rust_bindings(context, usage, interface_sets.intrinsics)except rust_bindings.UnsupportedByRustBindings as error:print(f"error: {error}", file=sys.stderr)diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.pyindex 768492a9be6..54c293416af 100644--- a/Meta/Generators/libweb_bindings/rust_bindings.py+++ b/Meta/Generators/libweb_bindings/rust_bindings.py@@ -14,8 +14,6 @@# A wrapper is a platform object whose host data holds a GC cell of the implementation. Its wrappable slot stays# empty, so the C++ bindings see a platform object without a C++ implementation object.-import re-from io import StringIOfrom typing import Dictfrom typing import List@@ -23,9 +21,9 @@ from typing import TextIOfrom Generators.libweb_bindings.context import GenerationContextfrom Generators.libweb_bindings.includes import GeneratedIncludes-from Generators.libweb_bindings.overload_resolution import operation_length-from Generators.libweb_bindings.overload_resolution import operation_overload_sets-from Generators.libweb_bindings.overload_resolution import parameter_list_length+from Generators.libweb_bindings.rust_members import RustConstructor+from Generators.libweb_bindings.rust_members import RustMembers+from Generators.libweb_bindings.rust_members import rust_membersfrom Generators.libweb_bindings.rust_names import rust_identifierfrom Generators.libweb_bindings.rust_names import rust_local_namefrom Generators.libweb_bindings.rust_overloads import write_constructor_overload_resolution@@ -44,16 +42,12 @@ from Generators.libweb_bindings.rust_usage import DefinitionUsagefrom Generators.libweb_bindings.rust_usage import is_implemented_in_rustfrom Generators.libweb_bindings.wrappers import wrapper_namefrom Utils.utils import title_case_to_snake_case-from Utils.webidl_parser import Constructorfrom Utils.webidl_parser import Interfacefrom Utils.webidl_parser import Modulefrom Utils.webidl_parser import OperationParameter-RUST_METHOD_NAME = re.compile(r"[a-z][a-z0-9_]*")--# The extended attributes of an interface and of its members that the Rust bindings handle.+# The extended attributes of an interface that the Rust bindings handle.SUPPORTED_INTERFACE_EXTENDED_ATTRIBUTES = {"Exposed", "ImplementedIn", "SecureContext", "Experimental"}-SUPPORTED_MEMBER_EXTENDED_ATTRIBUTES = {"NewObject", "SameObject"}def rust_module_name(interface: Interface) -> str:@@ -80,8 +74,8 @@ def interface_name_values(intrinsics: List[Interface]) -> Dict[str, int]:def check_interface_is_supported(interface: Interface, module: Module, context: GenerationContext) -> None:- """Raises an error that names what the Rust bindings do not handle yet, for everything that the functions that- write the bindings do not reject themselves."""+ """Raises an error that names what the Rust bindings do not handle yet about the interface as a whole. Its members+ are the business of rust_members(), and its types that of the functions that write the bindings."""def fail(message: str) -> None:raise UnsupportedByRustBindings(f"{interface.path}: {interface.name} is [ImplementedIn=Rust], but {message}")@@ -93,35 +87,6 @@ def check_interface_is_supported(interface: Interface, module: Module, context:fail("it is not a regular interface")if interface.parent_name:fail("it inherits from another interface")- special_operations = [- interface.named_property_getter,- interface.indexed_property_getter,- interface.named_property_setter,- interface.indexed_property_setter,- interface.named_property_deleter,- ]- if any(special_operations) or interface.stringifier is not None:- fail("it has special operations")- if interface.iterable or interface.async_iterable or interface.maplike or interface.setlike:- fail("it is iterable or a maplike or setlike")- if interface.static_attributes or interface.static_operations or interface.constants:- fail("it has static members or constants")- constructor_attributes = {"ImplementedAs"} if len(interface.constructors) > 1 else set()- for constructor in interface.constructors:- unsupported_attributes = set(constructor.extended_attributes) - constructor_attributes- if unsupported_attributes:- fail(- "the Rust bindings do not handle the extended attributes "- f"{sorted(unsupported_attributes)} of its constructor"- )- if len(interface.constructors) > 1:- # NB: Rust has no overloading, and a name made up from the position of a constructor in the IDL would swap- # two overloads silently when the IDL is reordered, so the IDL names the method of every overload.- methods = [constructor.extended_attributes.get("ImplementedAs") for constructor in interface.constructors]- if not all(method is not None and RUST_METHOD_NAME.fullmatch(method) for method in methods):- fail("its constructors are overloaded, and not all of them name their Rust method with [ImplementedAs]")- if len(set(methods)) != len(methods):- fail(f"its constructors name the same Rust method with [ImplementedAs] more than once: {methods}")if module.enumerations or module.callback_functions:fail("its module defines enumerations or callback functions")@@ -129,23 +94,7 @@ def check_interface_is_supported(interface: Interface, module: Module, context:if other.parent_name == interface.name:fail(f"{other.name} inherits from it")- def check_member_attributes(member_name: str, extended_attributes: dict) -> None:- unsupported = set(extended_attributes) - SUPPORTED_MEMBER_EXTENDED_ATTRIBUTES- if unsupported:- fail(f"the Rust bindings do not handle the extended attributes {sorted(unsupported)} of {member_name}")-- # NB: operation_overload_sets() leaves out the operations marked [FIXME], which C++ defines as unimplemented.- for operation in interface.regular_operations:- check_member_attributes(operation.name, operation.extended_attributes)-- for attribute in interface.regular_attributes:- check_member_attributes(attribute.name, attribute.extended_attributes)- if not attribute.readonly:- fail(f"its attribute {attribute.name} is not readonly")-- for name, operations in operation_overload_sets(interface).items():- if len(operations) > 1:- fail(f"its operation {name} is overloaded")+ rust_members(interface)def check_cpp_does_not_name_rust_interfaces(context: GenerationContext, usage: DefinitionUsage) -> None:@@ -297,22 +246,6 @@ def constructor_description(interface: Interface) -> str:return f"the constructor of {interface.name}"-def constructor_method_name(interface: Interface, constructor: Constructor) -> str:- """The method of the implementation that the steps of the constructor call. The constructors of an overloaded set- name theirs in the IDL."""- if len(interface.constructors) > 1:- return constructor.extended_attributes["ImplementedAs"]- return "construct"---def constructor_steps_function(interface: Interface, constructor: Constructor) -> str:- """The generated function of the steps of the constructor. The function `construct` is what the entry point of- a construction calls: the steps of the only constructor, or the choice between the overloads."""- if len(interface.constructors) > 1:- return f"{constructor_method_name(interface, constructor)}_steps"- return "construct"--def write_argument_count_check(out: TextIO, function_name: str, required_argument_count: int) -> None:"""Throws the errors of the C++ bindings for a call with too few arguments, which name the operation, or theinterface for a constructor."""@@ -373,7 +306,9 @@ def write_parameter_conversions(out.write(f" let {name} = {conversion}?;\n")-def implementation_method_signatures(context: GenerationContext, interface: Interface) -> List[str]:+def implementation_method_signatures(+ context: GenerationContext, interface: Interface, members: RustMembers+) -> List[str]:"""The methods the implementation of the interface defines, which the bindings call."""def parameter_list(what: str, parameters: List[OperationParameter]) -> str:@@ -383,24 +318,23 @@ def implementation_method_signatures(context: GenerationContext, interface: Inte)signatures = []- for constructor in interface.constructors:- parameters = parameter_list(constructor_description(interface), constructor.parameters)- method = constructor_method_name(interface, constructor)- signatures.append(f"fn {method}(cx: &mut CallContext{parameters}) -> WebIdlResult<Self>")- for attribute in interface.regular_attributes:- what = f"{interface.name}.{attribute.name}"- signatures.append(- f"fn {rust_identifier(attribute.name)}(&self, cx: &mut CallContext) -> "- f"WebIdlResult<{rust_type(attribute.type, context, what)}>"- )- for name, operations in operation_overload_sets(interface).items():- operation = operations[0]- what = f"{interface.name}.{name}()"- parameters = parameter_list(what, operation.parameters)+ for constructor in members.constructors:+ parameters = parameter_list(constructor_description(interface), constructor.constructor.parameters)+ signatures.append(f"fn {constructor.method}(cx: &mut CallContext{parameters}) -> WebIdlResult<Self>")+ for attribute in members.attributes:+ what = f"{interface.name}.{attribute.attribute.name}"signatures.append(- f"fn {rust_identifier(name)}(&self, cx: &mut CallContext{parameters}) -> "- f"WebIdlResult<{rust_type(operation.return_type, context, what)}>"+ f"fn {attribute.getter_method}(&self, cx: &mut CallContext) -> "+ f"WebIdlResult<{rust_type(attribute.attribute.type, context, what)}>")+ for operation_set in members.operation_sets:+ for overload in operation_set.overloads:+ what = f"{interface.name}.{operation_set.name}()"+ parameters = parameter_list(what, overload.operation.parameters)+ signatures.append(+ f"fn {overload.method}(&self, cx: &mut CallContext{parameters}) -> "+ f"WebIdlResult<{rust_type(overload.operation.return_type, context, what)}>"+ )return signatures@@ -408,8 +342,9 @@ def write_rust_interface(out: TextIO, context: GenerationContext, module: Module, interface: Interface, interface_name_value: int) -> None:implementation = implementation_path(interface)+ members = rust_members(interface)method_documentation = "".join(- f"/// - `{signature}`\n" for signature in implementation_method_signatures(context, interface)+ f"/// - `{signature}`\n" for signature in implementation_method_signatures(context, interface, members))out.write(f"""@@ -465,30 +400,33 @@ def write_rust_interface(""")- for attribute in interface.regular_attributes:- getter = f"{rust_identifier(attribute.name).removeprefix('r#')}_getter"- conversion = rust_to_js_value(attribute.type, "result", "&cx", context, f"{interface.name}.{attribute.name}")+ defined_property_names: List[str] = []++ for attribute in members.attributes:+ name = attribute.attribute.name+ conversion = rust_to_js_value(attribute.attribute.type, "result", "&cx", context, f"{interface.name}.{name}")out.write(f"""- fn {getter}(vm: &Vm) -> ThrowCompletionOr<Value> {{+ fn {attribute.getter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{let (implementation, mut cx) = this_implementation(vm)?;- let result = Implementation::{rust_identifier(attribute.name)}(&implementation, &mut cx)+ let result = Implementation::{attribute.getter_method}(&implementation, &mut cx).map_err(|exception| exception.throw(vm))?;{conversion}}}""")- for name, operations in operation_overload_sets(interface).items():- operation = operations[0]- function = rust_identifier(name)+ for operation_set in members.operation_sets:+ name = operation_set.name+ overload = operation_set.overloads[0]+ operation = overload.operationout.write(f"""- fn {function.removeprefix("r#")}_function(vm: &Vm) -> ThrowCompletionOr<Value> {{+ fn {operation_set.function}(vm: &Vm) -> ThrowCompletionOr<Value> {{let (implementation, mut cx) = this_implementation(vm)?;""")- write_argument_count_check(out, name, operation_length(operation))+ write_argument_count_check(out, name, overload.length)if operation.parameters:out.write(" let type_error_realm_scope = vm.type_error_realm_scope(cx.realm());\n")write_parameter_conversions(out, f"{interface.name}.{name}()", operation.parameters, context)@@ -496,7 +434,7 @@ def write_rust_interface(arguments = "".join(f", {rust_local_name(parameter.name)}" for parameter in operation.parameters)conversion = rust_to_js_value(operation.return_type, "result", "&cx", context, f"{interface.name}.{name}()")out.write(- f""" let result = Implementation::{function}(&implementation, &mut cx{arguments})+ f""" let result = Implementation::{overload.method}(&implementation, &mut cx{arguments}).map_err(|exception| exception.throw(vm))?;{conversion}}}@@ -521,13 +459,22 @@ def write_rust_interface(set_interface_prototype_object_prototype(vm, realm, prototype);""")- for attribute in interface.regular_attributes:- getter = f"{rust_identifier(attribute.name).removeprefix('r#')}_getter"- out.write(f' define_attribute(vm, realm, prototype, "{attribute.name}", raw_native!({getter}), None);\n')- for name, operations in operation_overload_sets(interface).items():- function = f"{rust_identifier(name).removeprefix('r#')}_function"- length = operation_length(operations[0])+ for attribute in members.attributes:+ name = attribute.attribute.name+ getter = attribute.getter_function+ out.write(f' define_attribute(vm, realm, prototype, "{name}", raw_native!({getter}), None);\n')+ defined_property_names.append(name)+ for operation_set in members.operation_sets:+ name = operation_set.name+ function = operation_set.function+ length = operation_set.lengthout.write(f' define_operation(vm, realm, prototype, "{name}", raw_native!({function}), {length});\n')+ defined_property_names.append(name)+ # NB: A member that rust_members() accepts and nothing above defines would be missing from the prototype without+ # any error, so the two are compared.+ assert defined_property_names == members.property_names(), (+ f"{interface.name}: the bindings define {defined_property_names}, its members are {members.property_names()}"+ )out.write(f""" define_to_string_tag(vm, prototype, "{interface.namespaced_name}");}}@@ -545,17 +492,17 @@ def write_rust_interface() {{// SAFETY: The caller passes live pointers.let (vm, realm, constructor) = unsafe {{ entry_point_arguments(vm, realm, constructor) }};- define_interface_object_properties(vm, realm, constructor, "{interface.name}", {constructor_length(interface)}, INTERFACE_NAME);+ define_interface_object_properties(vm, realm, constructor, "{interface.name}", {members.constructor_length}, INTERFACE_NAME);}}""")- for constructor in interface.constructors:+ for constructor in members.constructors:write_rust_constructor(out, context, interface, constructor)- if len(interface.constructors) > 1:- steps_functions = [constructor_steps_function(interface, constructor) for constructor in interface.constructors]+ if len(members.constructors) > 1:+ steps_functions = [constructor.steps_function for constructor in members.constructors]write_constructor_overload_resolution(out, context, interface, steps_functions)- if interface.constructors:+ if members.constructors:out.write(f"""/// {interface.constructor_class}::construct() of LibWeb's C++ bindings.@@ -579,27 +526,27 @@ def write_rust_interface(def write_rust_constructor(- out: TextIO, context: GenerationContext, interface: Interface, constructor: Constructor+ out: TextIO, context: GenerationContext, interface: Interface, constructor: RustConstructor) -> None:"""The steps of a constructor in the order of the C++ bindings: the prototype of the new object is read from thenew target before the arguments are counted and converted, and the conversions throw in the current realm."""- method = constructor_method_name(interface, constructor)+ parameters = constructor.constructor.parametersout.write(f"""/// The constructor steps of the interface, which internally create a new object implementing the interface,/// https://webidl.spec.whatwg.org/#internally-create-a-new-object-implementing-the-interface- fn {constructor_steps_function(interface, constructor)}(vm: &Vm, new_target: Gc<Object>) -> ThrowCompletionOr<Value> {{+ fn {constructor.steps_function}(vm: &Vm, new_target: Gc<Object>) -> ThrowCompletionOr<Value> {{let realm = vm.current_realm().expect("a construction runs in a realm");let prototype = prototype_from_new_target(vm, new_target, INTERFACE_NAME)?;""")- write_argument_count_check(out, interface.name, parameter_list_length(constructor.parameters))- write_parameter_conversions(out, constructor_description(interface), constructor.parameters, context)- arguments = "".join(f", {rust_local_name(parameter.name)}" for parameter in constructor.parameters)+ write_argument_count_check(out, interface.name, constructor.length)+ write_parameter_conversions(out, constructor_description(interface), parameters, context)+ arguments = "".join(f", {rust_local_name(parameter.name)}" for parameter in parameters)out.write(f""" let mut cx = CallContext::new(vm, realm);let implementation =- Implementation::{method}(&mut cx{arguments}).map_err(|exception| exception.throw(vm))?;+ Implementation::{constructor.method}(&mut cx{arguments}).map_err(|exception| exception.throw(vm))?;let implementation = CELL_CLASS.allocate(vm, implementation);Ok(Value::from_object(create_wrapper(vm, realm, wrapper_class(), prototype, implementation)))}}@@ -607,12 +554,6 @@ def write_rust_constructor()-def constructor_length(interface: Interface) -> int:- if not interface.constructors:- return 0- return min(parameter_list_length(constructor.parameters) for constructor in interface.constructors)--def write_rust_definitions(out: TextIO, context: GenerationContext, usage: DefinitionUsage) -> None:"""The conversions of the dictionaries and unions that the interfaces implemented in Rust name, each written once,whichever interfaces name it."""diff --git a/Meta/Generators/libweb_bindings/rust_members.py b/Meta/Generators/libweb_bindings/rust_members.pynew file mode 100644index 00000000000..d78b39069b4--- /dev/null+++ b/Meta/Generators/libweb_bindings/rust_members.py@@ -0,0 +1,177 @@+# Copyright (c) 2026-present, the Ladybird developers.+#+# SPDX-License-Identifier: BSD-2-Clause++# The members of an interface implemented in Rust, as the Rust bindings handle them: which attributes and operations+# the implementation has methods for and what those methods are called. Everything that asks about the members of such+# an interface asks here, so that what the checks accept, what the definitions are collected from and what the writer+# emits cannot differ. A member that the Rust bindings do not handle is an error that names it.++import re++from dataclasses import dataclass+from dataclasses import field+from typing import List++from Generators.libweb_bindings.overload_resolution import operation_length+from Generators.libweb_bindings.overload_resolution import operation_overload_sets+from Generators.libweb_bindings.overload_resolution import parameter_list_length+from Generators.libweb_bindings.rust_names import rust_identifier+from Generators.libweb_bindings.rust_types import UnsupportedByRustBindings+from Utils.webidl_parser import Attribute+from Utils.webidl_parser import Constructor+from Utils.webidl_parser import Interface+from Utils.webidl_parser import Operation++RUST_METHOD_NAME = re.compile(r"[a-z][a-z0-9_]*")++# The extended attributes of the members of an interface that the Rust bindings handle.+SUPPORTED_ATTRIBUTE_EXTENDED_ATTRIBUTES = {"NewObject", "SameObject"}+SUPPORTED_OPERATION_EXTENDED_ATTRIBUTES = {"NewObject", "SameObject"}+++@dataclass+class RustAttribute:+ attribute: Attribute+ # The method of the implementation that the getter calls.+ getter_method: str++ @property+ def getter_function(self) -> str:+ """The generated native function of the getter."""+ return f"{self.getter_method.removeprefix('r#')}_getter"+++@dataclass+class RustOperation:+ operation: Operation+ # The method of the implementation that the steps of the operation call.+ method: str++ @property+ def length(self) -> int:+ return operation_length(self.operation)+++@dataclass+class RustOperationSet:+ """The operations of an interface that share an identifier, which are one function of the prototype."""++ name: str+ overloads: List[RustOperation]++ @property+ def function(self) -> str:+ """The generated native function that the prototype holds."""+ return f"{rust_identifier(self.name).removeprefix('r#')}_function"++ @property+ def length(self) -> int:+ return min(overload.length for overload in self.overloads)+++@dataclass+class RustConstructor:+ constructor: Constructor+ # The method of the implementation that the steps of the constructor call. The constructors of an overloaded set+ # name theirs in the IDL.+ method: str+ # The generated function of the steps of the constructor. The function `construct` is what the entry point of a+ # construction calls: the steps of the only constructor, or the choice between the overloads.+ steps_function: str++ @property+ def length(self) -> int:+ return parameter_list_length(self.constructor.parameters)+++@dataclass+class RustMembers:+ attributes: List[RustAttribute] = field(default_factory=list)+ operation_sets: List[RustOperationSet] = field(default_factory=list)+ constructors: List[RustConstructor] = field(default_factory=list)++ @property+ def constructor_length(self) -> int:+ if not self.constructors:+ return 0+ return min(constructor.length for constructor in self.constructors)++ def property_names(self) -> List[str]:+ """The identifiers of the members that the interface prototype object has a property for."""+ names = [attribute.attribute.name for attribute in self.attributes]+ names.extend(operation_set.name for operation_set in self.operation_sets)+ return names+++def rust_members(interface: Interface) -> RustMembers:+ """Raises an error that names the member for every member that the Rust bindings do not handle yet."""++ def fail(message: str) -> None:+ raise UnsupportedByRustBindings(f"{interface.path}: {interface.name} is [ImplementedIn=Rust], but {message}")++ def check_extended_attributes(member_name: str, extended_attributes: dict, supported: set) -> None:+ unsupported = set(extended_attributes) - supported+ if unsupported:+ fail(f"the Rust bindings do not handle the extended attributes {sorted(unsupported)} of {member_name}")++ special_operations = [+ interface.named_property_getter,+ interface.indexed_property_getter,+ interface.named_property_setter,+ interface.indexed_property_setter,+ interface.named_property_deleter,+ ]+ if any(special_operations) or interface.stringifier is not None:+ fail("it has special operations")+ if interface.iterable or interface.async_iterable or interface.maplike or interface.setlike:+ fail("it is iterable or a maplike or setlike")+ if interface.static_attributes or interface.static_operations or interface.constants:+ fail("it has static members or constants")++ members = RustMembers()++ constructor_attributes = {"ImplementedAs"} if len(interface.constructors) > 1 else set()+ for constructor in interface.constructors:+ unsupported_attributes = set(constructor.extended_attributes) - constructor_attributes+ if unsupported_attributes:+ fail(+ "the Rust bindings do not handle the extended attributes "+ f"{sorted(unsupported_attributes)} of its constructor"+ )+ if len(interface.constructors) > 1:+ # NB: Rust has no overloading, and a name made up from the position of a constructor in the IDL would swap+ # two overloads silently when the IDL is reordered, so the IDL names the method of every overload.+ methods = [constructor.extended_attributes.get("ImplementedAs") for constructor in interface.constructors]+ if not all(method is not None and RUST_METHOD_NAME.fullmatch(method) for method in methods):+ fail("its constructors are overloaded, and not all of them name their Rust method with [ImplementedAs]")+ if len(set(methods)) != len(methods):+ fail(f"its constructors name the same Rust method with [ImplementedAs] more than once: {methods}")+ for constructor in interface.constructors:+ method = constructor.extended_attributes["ImplementedAs"]+ members.constructors.append(RustConstructor(constructor, method, f"{method}_steps"))+ else:+ for constructor in interface.constructors:+ members.constructors.append(RustConstructor(constructor, "construct", "construct"))++ # NB: operation_overload_sets() leaves out the operations marked [FIXME], which C++ defines as unimplemented.+ for operation in interface.regular_operations:+ check_extended_attributes(+ operation.name, operation.extended_attributes, SUPPORTED_OPERATION_EXTENDED_ATTRIBUTES+ )++ for attribute in interface.regular_attributes:+ check_extended_attributes(+ attribute.name, attribute.extended_attributes, SUPPORTED_ATTRIBUTE_EXTENDED_ATTRIBUTES+ )+ if not attribute.readonly:+ fail(f"its attribute {attribute.name} is not readonly")+ members.attributes.append(RustAttribute(attribute, rust_identifier(attribute.name)))++ for name, operations in operation_overload_sets(interface).items():+ if len(operations) > 1:+ fail(f"its operation {name} is overloaded")+ overloads = [RustOperation(operation, rust_identifier(name)) for operation in operations]+ members.operation_sets.append(RustOperationSet(name, overloads))++ return membersdiff --git a/Meta/Generators/libweb_bindings/rust_usage.py b/Meta/Generators/libweb_bindings/rust_usage.pyindex 6ae0cb1c98d..5b0c10981d5 100644--- a/Meta/Generators/libweb_bindings/rust_usage.py+++ b/Meta/Generators/libweb_bindings/rust_usage.py@@ -14,6 +14,7 @@ from typing import Optionalfrom typing import Setfrom Generators.libweb_bindings.context import GenerationContext+from Generators.libweb_bindings.rust_members import rust_membersfrom Generators.libweb_bindings.rust_types import is_named_unionfrom Generators.libweb_bindings.rust_types import runtime_union_typefrom Utils.webidl_parser import Dictionary@@ -70,6 +71,8 @@ class ConversionDirections:class DefinitionUsage:+ """Raises the errors of rust_members() for the interfaces implemented in Rust, whose members it reads."""+def __init__(self, context: GenerationContext) -> None:self.context = context# The dictionaries that the interfaces implemented in Rust name, in the order of their first use.@@ -90,14 +93,16 @@ class DefinitionUsage:interface = module.interfaceif interface is None or not is_implemented_in_rust(interface):continue- for attribute in interface.regular_attributes:- self._name_for_rust(attribute.type, from_js=not attribute.readonly, to_js=True)- for operation in interface.regular_operations:- self._name_for_rust(operation.return_type, from_js=False, to_js=True)- for parameter in operation.parameters:- self._name_for_rust(parameter.type, from_js=True, to_js=False)- for constructor in interface.constructors:- for parameter in constructor.parameters:+ members = rust_members(interface)+ for attribute in members.attributes:+ self._name_for_rust(attribute.attribute.type, from_js=False, to_js=True)+ for operation_set in members.operation_sets:+ for overload in operation_set.overloads:+ self._name_for_rust(overload.operation.return_type, from_js=False, to_js=True)+ for parameter in overload.operation.parameters:+ self._name_for_rust(parameter.type, from_js=True, to_js=False)+ for constructor in members.constructors:+ for parameter in constructor.constructor.parameters:self._name_for_rust(parameter.type, from_js=True, to_js=False)def _name_for_rust(self, idl_type: IDLType, from_js: bool, to_js: bool) -> None: