Truly independent web browser
Meta: Let Rust descriptor interfaces inherit CSSStyleDeclaration
Andreas Kling8ec70afefa16
diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.pyindex d6653a51068..1d4be482075 100644--- a/Meta/Generators/libweb_bindings/rust_bindings.py+++ b/Meta/Generators/libweb_bindings/rust_bindings.py@@ -20,6 +20,7 @@ from io import StringIOfrom typing import Callablefrom typing import Dictfrom typing import List+from typing import Optionalfrom typing import TextIOfrom typing import Tuple@@ -298,8 +299,10 @@ void {initialize_constructor}(JSVM*, void* realm, JSObject* constructor);f"{interface.path}: {interface.name} supports indexed properties and inherits from an interface ""implemented in C++, which the Rust bindings do not handle yet")- out.write(- f"""+ indexed_ancestor = cpp_ancestor_with_indexed_properties(interface, context)+ if indexed_ancestor is None:+ out.write(+ f"""}}// The wrappers hold the cell of their object as host data and, for an interface that inherits from one implemented in@@ -307,7 +310,25 @@ void {initialize_constructor}(JSVM*, void* realm, JSObject* constructor);constexpr JSHostClass {wrapper_host_class_symbol(interface)} = JS::make_host_class(JS_HOST_CLASS_OBJECT, "{interface.name}"sv,&{parent_host_class}, &platform_object_hooks, nullptr, platform_object_host_class_flags);"""- )+ )+ else:+ legacy_info = f"{wrapper_name(interface)}_legacy_platform_object_info"+ out.write(+ f"""+}}++static constexpr LegacyPlatformObjectInfo {legacy_info} {{+ .supports_indexed_properties = true,+ .item_value = {wrapper_name(indexed_ancestor)}_item_value,+}};++// The wrappers hold the cell of their object as host data and the C++ object it owns as their wrappable, whose indexed+// properties the C++ bindings of the ancestor read.+constexpr JSHostClass {wrapper_host_class_symbol(interface)} = JS::make_host_class(JS_HOST_CLASS_OBJECT, "{interface.name}"sv,+ &{parent_host_class}, &indexed_legacy_platform_object_hooks, &{legacy_info},+ platform_object_host_class_flags | JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE);+"""+ )elif not supports_indexed_properties:out.write(f"""@@ -1352,6 +1373,16 @@ def write_default_to_json(out: TextIO, context: GenerationContext, interface: In)+def cpp_ancestor_with_indexed_properties(interface: Interface, context: GenerationContext) -> Optional[Interface]:+ """The nearest ancestor implemented in C++ that declares an indexed property getter."""+ ancestor = cpp_ancestor(interface, context)+ while ancestor is not None:+ if ancestor.indexed_property_getter is not None:+ return ancestor+ ancestor = context.interfaces.get(ancestor.parent_name)+ return None++def item_value_entry_point(interface: Interface) -> str:return rust_entry_point_name(interface, "item_value")diff --git a/Meta/Generators/libweb_bindings/rust_members.py b/Meta/Generators/libweb_bindings/rust_members.pyindex a2df37ea028..5f5d99fc98a 100644--- a/Meta/Generators/libweb_bindings/rust_members.py+++ b/Meta/Generators/libweb_bindings/rust_members.py@@ -35,9 +35,11 @@ RUST_METHOD_NAME = re.compile(r"[a-z][a-z0-9_]*")# NB: The context of an attribute or an operation that is [NeedsCallerRealm] has the current realm, not the realm of# the object.SUPPORTED_ATTRIBUTE_EXTENDED_ATTRIBUTES = {+ "AttributeCallbackName","CachedAccessor","FIXME","ImplementedAs",+ "LegacyNullToEmptyString","NeedsCallerRealm","NewObject","PutForwards",@@ -90,15 +92,22 @@ class RustAttribute:the object: [CachedAccessor]."""return "CachedAccessor" in self.attribute.extended_attributes+ @property+ def function_stem(self) -> str:+ """What the generated native functions are named after. [AttributeCallbackName] tells apart the attributes that+ name the same methods."""+ callback_name = self.attribute.extended_attributes.get("AttributeCallbackName")+ return callback_name or generated_function_stem(self.getter_method)+@propertydef getter_function(self) -> str:"""The generated native function of the getter."""- return f"{generated_function_stem(self.getter_method)}_getter"+ return f"{self.function_stem}_getter"@propertydef setter_function(self) -> str:"""The generated native function of the setter."""- return f"{generated_function_stem(self.getter_method)}_setter"+ return f"{self.function_stem}_setter"@dataclass@@ -492,8 +501,12 @@ def rust_members(interface: Interface) -> RustMembers:else:members.constants.append(RustConstant(constant.name, value))- methods = [attribute.getter_method for attribute in members.attributes if attribute.event_type is None]- methods.extend(attribute.setter_method for attribute in members.attributes if attribute.setter_method is not None)+ # NB: The spellings of a CSS descriptor or property are attributes with the same steps, which name the same methods.+ attribute_methods = {attribute.getter_method for attribute in members.attributes if attribute.event_type is None}+ attribute_methods.update(+ attribute.setter_method for attribute in members.attributes if attribute.setter_method is not None+ )+ methods = sorted(attribute_methods)methods.extend(overload.methodfor operation_set in members.operation_sets + members.static_operation_setsdiff --git a/Meta/Generators/libweb_bindings/rust_types.py b/Meta/Generators/libweb_bindings/rust_types.pyindex c712aab13af..e7354219ee7 100644--- a/Meta/Generators/libweb_bindings/rust_types.py+++ b/Meta/Generators/libweb_bindings/rust_types.py@@ -127,7 +127,7 @@ def is_implemented_in_rust(interface: Optional[Interface]) -> bool:# The interfaces implemented in C++ that an interface implemented in Rust can inherit from# (Libraries/LibWeb/Bindings/RustEventTarget.h).-CPP_PARENT_INTERFACES = ("EventTarget", "Event")+CPP_PARENT_INTERFACES = ("CSSStyleDeclaration", "EventTarget", "Event")def cpp_ancestor(interface: Interface, context: GenerationContext) -> Optional[Interface]: