From 6a9cd0e8e066f85a2f7ba67ef25f29215591c19d Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 18 Jul 2025 16:14:26 +1200 Subject: [PATCH] LibWeb: Use interface_name instead of serialize_type virtual `interface_name` is implemented for every platform object, so we no longer need this boilerplate for every serializable platform object. --- Libraries/LibWeb/Bindings/Serializable.h | 2 -- Libraries/LibWeb/Crypto/CryptoKey.h | 1 - Libraries/LibWeb/FileAPI/Blob.h | 2 -- Libraries/LibWeb/FileAPI/File.h | 2 -- Libraries/LibWeb/FileAPI/FileList.h | 1 - Libraries/LibWeb/Geometry/DOMMatrix.h | 2 -- Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h | 1 - Libraries/LibWeb/Geometry/DOMPoint.h | 2 -- Libraries/LibWeb/Geometry/DOMPointReadOnly.h | 1 - Libraries/LibWeb/Geometry/DOMQuad.h | 1 - Libraries/LibWeb/Geometry/DOMRect.h | 2 -- Libraries/LibWeb/Geometry/DOMRectReadOnly.h | 1 - Libraries/LibWeb/HTML/ImageBitmap.h | 1 - Libraries/LibWeb/HTML/ImageData.h | 1 - Libraries/LibWeb/HTML/StructuredSerialize.cpp | 2 +- Libraries/LibWeb/WebIDL/DOMException.h | 2 -- Libraries/LibWeb/WebIDL/QuotaExceededError.h | 1 - 17 files changed, 1 insertion(+), 24 deletions(-) diff --git a/Libraries/LibWeb/Bindings/Serializable.h b/Libraries/LibWeb/Bindings/Serializable.h index f7cf2080b8..310b7c9432 100644 --- a/Libraries/LibWeb/Bindings/Serializable.h +++ b/Libraries/LibWeb/Bindings/Serializable.h @@ -17,8 +17,6 @@ class Serializable { public: virtual ~Serializable() = default; - virtual InterfaceName serialize_type() const = 0; - // https://html.spec.whatwg.org/multipage/structured-data.html#serialization-steps virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) = 0; diff --git a/Libraries/LibWeb/Crypto/CryptoKey.h b/Libraries/LibWeb/Crypto/CryptoKey.h index 0cf3402b4a..25158414ac 100644 --- a/Libraries/LibWeb/Crypto/CryptoKey.h +++ b/Libraries/LibWeb/Crypto/CryptoKey.h @@ -49,7 +49,6 @@ public: InternalKeyData const& handle() const { return m_key_data; } String algorithm_name() const; - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::CryptoKey; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/FileAPI/Blob.h b/Libraries/LibWeb/FileAPI/Blob.h index f676075a75..59fe5783c4 100644 --- a/Libraries/LibWeb/FileAPI/Blob.h +++ b/Libraries/LibWeb/FileAPI/Blob.h @@ -59,8 +59,6 @@ public: GC::Ref get_stream(); - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::Blob; } - virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/FileAPI/File.h b/Libraries/LibWeb/FileAPI/File.h index 057f60c9a2..835629cd21 100644 --- a/Libraries/LibWeb/FileAPI/File.h +++ b/Libraries/LibWeb/FileAPI/File.h @@ -30,8 +30,6 @@ public: // https://w3c.github.io/FileAPI/#dfn-lastModified i64 last_modified() const { return m_last_modified; } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::File; } - virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/FileAPI/FileList.h b/Libraries/LibWeb/FileAPI/FileList.h index 8f017fefd5..b60f91e90f 100644 --- a/Libraries/LibWeb/FileAPI/FileList.h +++ b/Libraries/LibWeb/FileAPI/FileList.h @@ -46,7 +46,6 @@ public: virtual Optional item_value(size_t index) const override; - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::FileList; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/Geometry/DOMMatrix.h b/Libraries/LibWeb/Geometry/DOMMatrix.h index 89e7cd1c75..410bd03cdb 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrix.h +++ b/Libraries/LibWeb/Geometry/DOMMatrix.h @@ -70,8 +70,6 @@ public: WebIDL::ExceptionOr> set_matrix_value(String const& transform_list); - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMMatrix; } - private: DOMMatrix(JS::Realm&, double m11, double m12, double m21, double m22, double m41, double m42); DOMMatrix(JS::Realm&, double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44); diff --git a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h index 5c1cf63397..fc54e040a2 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h +++ b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h @@ -115,7 +115,6 @@ public: WebIDL::ExceptionOr to_string() const; - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMMatrixReadOnly; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/Geometry/DOMPoint.h b/Libraries/LibWeb/Geometry/DOMPoint.h index 37f166e424..6f66971d65 100644 --- a/Libraries/LibWeb/Geometry/DOMPoint.h +++ b/Libraries/LibWeb/Geometry/DOMPoint.h @@ -35,8 +35,6 @@ public: void set_z(double z) { m_z = z; } void set_w(double w) { m_w = w; } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMPoint; } - private: DOMPoint(JS::Realm&, double x, double y, double z, double w); DOMPoint(JS::Realm&); diff --git a/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Libraries/LibWeb/Geometry/DOMPointReadOnly.h index 99242b9654..751449443d 100644 --- a/Libraries/LibWeb/Geometry/DOMPointReadOnly.h +++ b/Libraries/LibWeb/Geometry/DOMPointReadOnly.h @@ -44,7 +44,6 @@ public: WebIDL::ExceptionOr> matrix_transform(DOMMatrixInit&) const; - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMPointReadOnly; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/Geometry/DOMQuad.h b/Libraries/LibWeb/Geometry/DOMQuad.h index 44f6fee5af..af916babad 100644 --- a/Libraries/LibWeb/Geometry/DOMQuad.h +++ b/Libraries/LibWeb/Geometry/DOMQuad.h @@ -44,7 +44,6 @@ public: GC::Ref get_bounds() const; - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMQuad; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/Geometry/DOMRect.h b/Libraries/LibWeb/Geometry/DOMRect.h index 0e4d09a713..7e97a1aa27 100644 --- a/Libraries/LibWeb/Geometry/DOMRect.h +++ b/Libraries/LibWeb/Geometry/DOMRect.h @@ -33,8 +33,6 @@ public: void set_width(double width) { m_rect.set_width(width); } void set_height(double height) { m_rect.set_height(height); } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMRect; } - private: DOMRect(JS::Realm&, double x, double y, double width, double height); explicit DOMRect(JS::Realm&); diff --git a/Libraries/LibWeb/Geometry/DOMRectReadOnly.h b/Libraries/LibWeb/Geometry/DOMRectReadOnly.h index ba70ca9714..5e93f055a3 100644 --- a/Libraries/LibWeb/Geometry/DOMRectReadOnly.h +++ b/Libraries/LibWeb/Geometry/DOMRectReadOnly.h @@ -69,7 +69,6 @@ public: return min(x(), x() + width()); } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMRectReadOnly; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/HTML/ImageBitmap.h b/Libraries/LibWeb/HTML/ImageBitmap.h index 464c91fe9b..f4f9f785cf 100644 --- a/Libraries/LibWeb/HTML/ImageBitmap.h +++ b/Libraries/LibWeb/HTML/ImageBitmap.h @@ -38,7 +38,6 @@ public: virtual ~ImageBitmap() override; // ^Web::Bindings::Serializable - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::ImageBitmap; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/HTML/ImageData.h b/Libraries/LibWeb/HTML/ImageData.h index f4ed6692a1..1dc7f6db16 100644 --- a/Libraries/LibWeb/HTML/ImageData.h +++ b/Libraries/LibWeb/HTML/ImageData.h @@ -46,7 +46,6 @@ public: Bindings::PredefinedColorSpace color_space() const { return m_color_space; } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::ImageData; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Libraries/LibWeb/HTML/StructuredSerialize.cpp index 36f8951bcb..afc1339ad7 100644 --- a/Libraries/LibWeb/HTML/StructuredSerialize.cpp +++ b/Libraries/LibWeb/HTML/StructuredSerialize.cpp @@ -444,7 +444,7 @@ public: // 2. Let typeString be the identifier of the primary interface of value. // 3. Set serialized to { [[Type]]: typeString }. serialized.encode(ValueTag::SerializableObject); - serialized.encode(serializable->serialize_type()); + serialized.encode(as(serializable)->interface_name()); // 4. Set deep to true deep = true; diff --git a/Libraries/LibWeb/WebIDL/DOMException.h b/Libraries/LibWeb/WebIDL/DOMException.h index 69b1a917fd..1ab45d5e94 100644 --- a/Libraries/LibWeb/WebIDL/DOMException.h +++ b/Libraries/LibWeb/WebIDL/DOMException.h @@ -112,8 +112,6 @@ public: Utf16FlyString const& message() const { return m_message; } u16 code() const { return get_legacy_code_for_name(m_name); } - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::DOMException; } - virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override; diff --git a/Libraries/LibWeb/WebIDL/QuotaExceededError.h b/Libraries/LibWeb/WebIDL/QuotaExceededError.h index c9ecb50b9f..c41e9975a8 100644 --- a/Libraries/LibWeb/WebIDL/QuotaExceededError.h +++ b/Libraries/LibWeb/WebIDL/QuotaExceededError.h @@ -27,7 +27,6 @@ public: static ExceptionOr> construct_impl(JS::Realm&, Utf16String const& message = {}, QuotaExceededErrorOptions const& options = {}); - virtual Bindings::InterfaceName serialize_type() const override { return Bindings::InterfaceName::QuotaExceededError; } virtual WebIDL::ExceptionOr serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override; virtual WebIDL::ExceptionOr deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override;