Skip to content

Truly independent web browser

LibWeb: Keep serializable interface metadata in Rust

Shannon Boothc5fb6549f236
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
index 4729b1b1bc6..db7205102be 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
@@ -6,8 +6,8 @@
//! What structured serialization asks of LibWeb's C++ code, which implements it in
//! Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp: the C++ records that the serializations hand their
-//! bytes over to and the deserializations read the bytes of, the registry of serializable interfaces, the platform
-//! objects, and the side tables that SharedArrayBuffers are shared through.
+//! bytes over to and the deserializations read the bytes of, C++ platform objects, and the side tables that
+//! SharedArrayBuffers are shared through.
use core::ffi::{c_int, c_void};
use core::marker::PhantomData;
@@ -28,15 +28,6 @@ unsafe extern "C" {
count: usize,
);
fn web_structured_serialize_set_storage_record(record: *mut c_void, data: ak::Span<'_, u8>);
- fn web_structured_serialize_is_ipc_interface(interface_name: u16) -> bool;
- fn web_structured_serialize_interface_storage_identifier(
- interface_name: u16,
- identifier: &mut ak::Span<'static, u8>,
- ) -> bool;
- fn web_structured_serialize_interface_name_from_storage_identifier(
- identifier: ak::Span<'_, u8>,
- interface_name: &mut u16,
- ) -> bool;
fn web_structured_serialize_ipc_record_data(record: *const c_void, data: &mut ak::Span<'static, u8>);
fn web_structured_serialize_ipc_record_shared_array_buffer(
@@ -48,8 +39,6 @@ unsafe extern "C" {
message: ak::Span<'_, u8>,
) -> RawNativeFunctionResult;
- fn web_structured_serialize_serializable_payload_version() -> u64;
-
fn web_structured_serialize_current_settings_object_agent_cluster(agent_cluster: &mut u64) -> bool;
fn web_structured_serialize_current_settings_object_cross_origin_isolated_capability() -> bool;
fn web_structured_serialize_realm_agent_cluster(realm: *mut c_void, agent_cluster: &mut u64) -> bool;
@@ -57,7 +46,6 @@ unsafe extern "C" {
fn web_structured_serialize_cpp_interface_name(object: *mut c_void, interface_name: &mut u16) -> bool;
fn web_structured_serialize_is_exposed(interface_name: u16, realm: *mut c_void) -> bool;
- fn web_structured_serialize_serializable_steps(interface_name: u16) -> u8;
fn web_structured_serialize_gather_image_bitmap_pixels(
transfer_list: *const *mut c_void,
@@ -163,31 +151,6 @@ impl StorageSerializationRecord {
}
}
-/// Whether IPC records can contain this interface, including interfaces that cannot be stored.
-pub(crate) fn is_ipc_interface(interface_name: u16) -> bool {
- // SAFETY: The call takes an interface identifier by value.
- unsafe { web_structured_serialize_is_ipc_interface(interface_name) }
-}
-
-/// The identifier of the serializable interface that a storage record holds, from LibWeb's registry of them, if the
-/// Bindings::InterfaceName names one.
-pub(crate) fn serializable_interface_storage_identifier(interface_name: u16) -> Option<&'static [u8]> {
- let mut identifier = ak::Span::default();
- // SAFETY: The call writes a span of static storage to the local.
- unsafe { web_structured_serialize_interface_storage_identifier(interface_name, &mut identifier) }
- .then(|| identifier.as_slice())
-}
-
-/// The Bindings::InterfaceName of the serializable interface with the identifier, if LibWeb's registry has one.
-pub(crate) fn serializable_interface_name_from_storage_identifier(identifier: &[u8]) -> Option<u16> {
- let mut interface_name = 0;
- // SAFETY: The call borrows the identifier, and writes to the local.
- unsafe {
- web_structured_serialize_interface_name_from_storage_identifier(ak::Span::new(identifier), &mut interface_name)
- }
- .then_some(interface_name)
-}
-
/// An HTML::IPCSerializationRecord that C++ lends for a deserialization to read.
#[derive(Clone, Copy)]
pub(crate) struct ReceivedIPCSerializationRecord<'a> {
@@ -276,13 +239,6 @@ pub(crate) fn data_clone_error_from_serialization_error(realm: Gc<Realm>, messag
}
}
-/// HTML::serializable_payload_version: the per-interface payload version that a storage record holds after the
-/// interface name of every serializable object.
-pub(crate) fn serializable_payload_version() -> u64 {
- // SAFETY: The call has no arguments.
- unsafe { web_structured_serialize_serializable_payload_version() }
-}
-
/// The agent cluster of the current settings object, if it has one.
pub(crate) fn current_settings_object_agent_cluster() -> Option<u64> {
let mut agent_cluster = 0;
@@ -319,33 +275,6 @@ pub(crate) fn is_exposed(interface_name: u16, realm: Gc<Realm>) -> bool {
unsafe { web_structured_serialize_is_exposed(interface_name, realm.as_ptr().cast()) }
}
-/// Whose steps serialize and deserialize the objects of a serializable interface.
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub(crate) enum SerializableSteps {
- /// The steps of an interface implemented in Rust, which its bindings run.
- Rust,
- /// The steps of DOMException, which run in crate::webidl::dom_exception.
- DOMException,
- /// The steps of QuotaExceededError, which run in crate::webidl::quota_exceeded_error.
- QuotaExceededError,
- /// The steps of CryptoKey, which run in crate::crypto::crypto_key.
- CryptoKey,
- /// The steps of RTCEncodedAudioFrame, which run in crate::webrtc::rtc_encoded_audio_frame.
- RTCEncodedAudioFrame,
-}
-
-pub(crate) fn serializable_steps(interface_name: u16) -> SerializableSteps {
- // SAFETY: The call takes a value.
- match unsafe { web_structured_serialize_serializable_steps(interface_name) } {
- 0 => SerializableSteps::Rust,
- 1 => SerializableSteps::DOMException,
- 2 => SerializableSteps::QuotaExceededError,
- 3 => SerializableSteps::CryptoKey,
- 4 => SerializableSteps::RTCEncodedAudioFrame,
- steps => unreachable!("LibWeb names no serializable steps {steps}"),
- }
-}
-
/// HTML::ImageBitmapSharedPixels that this owns: the shared memory that a transfer gathers the pixels of its
/// ImageBitmaps in, if it has some.
pub(crate) struct ImageBitmapSharedPixels(Option<NonNull<c_void>>);
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/exports.rs
index b602ea967b9..e5b20cc0d2b 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/exports.rs
@@ -234,3 +234,17 @@ pub unsafe extern "C" fn web_rust_structured_deserialize_with_transfer(
}),
)
}
+
+/// # Safety
+///
+/// The callback must accept the context and an identifier of static storage.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_rust_serializable_storage_registry(
+ context: *mut c_void,
+ append: unsafe extern "C" fn(*mut c_void, u16, ak::Span<'static, u8>),
+) {
+ for entry in super::serializable::STORAGE_INTERFACES {
+ // SAFETY: The caller lends its context to its callback.
+ unsafe { append(context, entry.interface_name, ak::Span::new(entry.identifier)) };
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
index dbf4590800f..c63db75a81c 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
@@ -42,15 +42,17 @@ use crate::html::image_bitmap::ImageBitmap;
use crate::html::message_port::MessagePort;
use crate::html::offscreen_canvas;
use crate::html::structured_serialize::cpp::{
- OwnedSerializedTransferRecord, SerializableSteps, SerializedTransferRecord, current_settings_object_agent_cluster,
+ OwnedSerializedTransferRecord, SerializedTransferRecord, current_settings_object_agent_cluster,
current_settings_object_cross_origin_isolated_capability, data_clone_error_from_serialization_error,
- gather_image_bitmap_pixels, is_exposed, realm_agent_cluster, serializable_interface_storage_identifier,
- serializable_payload_version, serializable_steps,
+ gather_image_bitmap_pixels, is_exposed, realm_agent_cluster,
};
use crate::html::structured_serialize::memory::{DeserializationMemory, SerializationMemory};
use crate::html::structured_serialize::message_record::MessageRecord;
use crate::html::structured_serialize::reader::StructuredSerializeReader;
-use crate::html::structured_serialize::serializable::serializable_interface_name;
+use crate::html::structured_serialize::serializable::{
+ SERIALIZABLE_PAYLOAD_VERSION, SerializableSteps, serializable_interface_name,
+ serializable_interface_storage_identifier, serializable_steps,
+};
use crate::html::structured_serialize::transfer_data_holder::TransferDataHolder;
use crate::html::structured_serialize::writer::StructuredSerializeWriter;
use crate::streams::readable_stream::ReadableStream;
@@ -1067,7 +1069,7 @@ pub(crate) fn encode_serializable_object_header(
serialized.encode_u8(ValueTag::SerializableObject as u8);
serialized.encode_interface_name(interface_name);
if serialized.serialization_type() == SerializationType::Storage {
- serialized.encode_u64(serializable_payload_version());
+ serialized.encode_u64(SERIALIZABLE_PAYLOAD_VERSION);
}
Ok(())
}
@@ -1082,7 +1084,7 @@ pub(crate) fn decode_serializable_object_header(
return Err(data_clone_error("Unexpected serializable object"));
}
if serialized.serialization_type() == SerializationType::Storage
- && serialized.decode_u64()? != serializable_payload_version()
+ && serialized.decode_u64()? != SERIALIZABLE_PAYLOAD_VERSION
{
return Err(data_clone_error("Unsupported serializable payload version"));
}
@@ -1563,7 +1565,7 @@ impl Deserializer<'_, '_, '_> {
return Err(data_clone_error("Unsupported type"));
}
- if version.is_some_and(|version| version != serializable_payload_version()) {
+ if version.is_some_and(|version| version != SERIALIZABLE_PAYLOAD_VERSION) {
return Err(data_clone_error_from_serialization_error(
realm,
"Unsupported serializable payload version",
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
index d0ba0bed2cd..623173fe788 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
@@ -25,10 +25,12 @@ use libwebcommon_rust::html::serialization_records::{DecodeError, DecodedString,
use crate::bindings::WebIdlResult;
use crate::html::structured_serialize::cpp::{
- ReceivedIPCSerializationRecord, data_clone_error_from_serialization_error, is_ipc_interface,
- serializable_interface_name_from_storage_identifier,
+ ReceivedIPCSerializationRecord, data_clone_error_from_serialization_error,
};
use crate::html::structured_serialize::message_record::{MessageRecord, SharedMemory};
+use crate::html::structured_serialize::serializable::{
+ is_ipc_interface, serializable_interface_name_from_storage_identifier,
+};
/// Where the record keeps the SharedArrayBuffers that it shares.
#[derive(Clone, Copy)]
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs
index ceb7d64b16a..5a634622914 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/serializable.rs
@@ -7,19 +7,58 @@
//! Dispatch to the steps of serializable interfaces. The generated Rust bindings classify their wrappers exactly,
//! and C++ reports the primary interface of objects that it implements.
-use libjs_rust::api::{Gc, Object, Value, Vm};
+use libjs_rust::api::{Gc, Object};
-use crate::bindings::structured_data::{SerializationReader, SerializationWriter};
-use crate::bindings::{CallContext, WebIdlResult};
use crate::html::structured_serialize::cpp::cpp_serializable_interface_name;
+/// The identifier stored for the primary interface of a serializable object.
+pub(crate) struct SerializableRegistryEntry {
+ pub(crate) interface_name: u16,
+ pub(crate) identifier: &'static [u8],
+}
+
+/// Whose Rust steps serialize and deserialize an interface's objects.
+pub(crate) enum SerializableSteps {
+ Rust,
+ DOMException,
+ QuotaExceededError,
+ CryptoKey,
+ RTCEncodedAudioFrame,
+}
+
+// The version after every serializable object's interface identifier in a storage record. Changing it requires
+// migration.
+pub(crate) const SERIALIZABLE_PAYLOAD_VERSION: u64 = 1;
+
#[cfg(web_idl_bindings)]
use crate::bindings::generated::serializable_objects as generated;
// A standalone cargo build has no wrapper classes or interface identifiers to dispatch on.
#[cfg(not(web_idl_bindings))]
mod generated {
- use super::*;
+ use libjs_rust::api::{Gc, Object, Value, Vm};
+
+ use super::{SerializableRegistryEntry, SerializableSteps};
+ use crate::bindings::structured_data::{SerializationReader, SerializationWriter};
+ use crate::bindings::{CallContext, WebIdlResult};
+
+ pub(crate) const STORAGE_INTERFACES: &[SerializableRegistryEntry] = &[];
+
+ pub(crate) fn serializable_interface_storage_identifier(_: u16) -> Option<&'static [u8]> {
+ unreachable!("serialization requires the generated bindings")
+ }
+
+ pub(crate) fn serializable_interface_name_from_storage_identifier(_: &[u8]) -> Option<u16> {
+ unreachable!("serialization requires the generated bindings")
+ }
+
+ pub(crate) fn is_ipc_interface(_: u16) -> bool {
+ unreachable!("serialization requires the generated bindings")
+ }
+
+ pub(crate) fn serializable_steps(_: u16) -> SerializableSteps {
+ unreachable!("serialization requires the generated bindings")
+ }
pub(crate) fn rust_interface_name(_: Gc<Object>) -> Option<u16> {
unreachable!("serialization requires the generated bindings")
@@ -44,7 +83,10 @@ mod generated {
}
}
-pub(crate) use generated::{deserialization_steps, serialization_steps};
+pub(crate) use generated::{
+ STORAGE_INTERFACES, deserialization_steps, is_ipc_interface, serializable_interface_name_from_storage_identifier,
+ serializable_interface_storage_identifier, serializable_steps, serialization_steps,
+};
pub(crate) fn serializable_interface_name(object: Gc<Object>) -> Option<u16> {
generated::rust_interface_name(object).or_else(|| {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
index e1f817bc86a..e0c1d192dd5 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
@@ -19,10 +19,9 @@ use ak::{Utf16String, Utf16StringUnits};
use libjs_rust::api::{ArrayBuffer, BigInt, DataBlockStorage, DeferGc, Gc, MarkedVec, Vm};
use libwebcommon_rust::html::serialization_records::{RecordEncoder, SerializationType};
-use crate::html::structured_serialize::cpp::{
- IPCSerializationRecord, StorageSerializationRecord, serializable_interface_storage_identifier,
-};
+use crate::html::structured_serialize::cpp::{IPCSerializationRecord, StorageSerializationRecord};
use crate::html::structured_serialize::message_record::{MessageRecord, SharedMemory};
+use crate::html::structured_serialize::serializable::serializable_interface_storage_identifier;
/// The record of a structured serialization, which the serialization writes its values to.
pub(crate) struct StructuredSerializeWriter<'vm> {
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
index 845802d3d50..b71d08b4936 100644
--- a/Libraries/LibWeb/HTML/StructuredSerialize.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
@@ -7,7 +7,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Array.h>
#include <AK/Debug.h>
#include <LibJS/HostClassBuilder.h>
#include <LibJS/Runtime/ArrayBuffer.h>
@@ -18,31 +17,6 @@
namespace Web::HTML {
-// The identifier that a storage record holds for the primary interface of each serializable object.
-static constexpr auto s_serializable_storage_registry = to_array<SerializableRegistryEntry>({
- { Bindings::InterfaceName::Blob, "Blob"sv },
- { Bindings::InterfaceName::CryptoKey, "CryptoKey"sv },
- { Bindings::InterfaceName::DOMException, "DOMException"sv },
- { Bindings::InterfaceName::DOMMatrix, "DOMMatrix"sv },
- { Bindings::InterfaceName::DOMMatrixReadOnly, "DOMMatrixReadOnly"sv },
- { Bindings::InterfaceName::DOMPoint, "DOMPoint"sv },
- { Bindings::InterfaceName::DOMPointReadOnly, "DOMPointReadOnly"sv },
- { Bindings::InterfaceName::DOMQuad, "DOMQuad"sv },
- { Bindings::InterfaceName::DOMRect, "DOMRect"sv },
- { Bindings::InterfaceName::DOMRectReadOnly, "DOMRectReadOnly"sv },
- { Bindings::InterfaceName::File, "File"sv },
- { Bindings::InterfaceName::FileList, "FileList"sv },
- { Bindings::InterfaceName::ImageBitmap, "ImageBitmap"sv },
- { Bindings::InterfaceName::ImageData, "ImageData"sv },
- { Bindings::InterfaceName::Module, "Module"sv },
- { Bindings::InterfaceName::QuotaExceededError, "QuotaExceededError"sv },
-});
-
-ReadonlySpan<SerializableRegistryEntry> serializable_storage_registry()
-{
- return s_serializable_storage_registry.span();
-}
-
// The same-process SharedArrayBuffer aliases of an IPCSerializationRecord. Only this file creates side tables, so a
// record's side table is one of these.
class SharedArrayBufferSideTable final : public SameProcessSerializationSideTable {
@@ -88,6 +62,7 @@ JSCompletion web_rust_structured_deserialize(JSVM*, void* target_realm, IPCSeria
JSCompletion web_rust_structured_deserialize_for_storage(JSVM*, void* target_realm, ReadonlyBytes);
JSCompletion web_rust_structured_serialize_with_transfer(JSVM*, void* realm, JSValue, JSObject* const* transfer_list, size_t count, SerializedTransferRecord** out_record);
JSCompletion web_rust_structured_deserialize_with_transfer(JSVM*, void* target_realm, SerializedTransferRecord*, Vector<GC::Root<JS::Object>>* transferred_values);
+void web_rust_serializable_storage_registry(void* context, void (*append)(void*, u16 interface_name, ReadonlyBytes identifier));
}
// https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer
@@ -167,4 +142,13 @@ TransferDataDecoder::TransferDataDecoder(TransferDataEncoder&& data_holder)
m_attachments.enqueue(move(attachment));
}
+Vector<SerializableRegistryEntry> serializable_storage_registry()
+{
+ Vector<SerializableRegistryEntry> entries;
+ web_rust_serializable_storage_registry(&entries, [](void* context, u16 interface_name, ReadonlyBytes identifier) {
+ static_cast<Vector<SerializableRegistryEntry>*>(context)->append({ static_cast<Bindings::InterfaceName>(interface_name), StringView { identifier } });
+ });
+ return entries;
+}
+
}
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.h b/Libraries/LibWeb/HTML/StructuredSerialize.h
index 11acbeb481f..32548fb441c 100644
--- a/Libraries/LibWeb/HTML/StructuredSerialize.h
+++ b/Libraries/LibWeb/HTML/StructuredSerialize.h
@@ -109,7 +109,7 @@ struct SerializableRegistryEntry {
StringView identifier;
};
-WEB_API ReadonlySpan<SerializableRegistryEntry> serializable_storage_registry();
+WEB_API Vector<SerializableRegistryEntry> serializable_storage_registry();
template<typename T>
WebIDL::ExceptionOr<void> encode_or_throw_data_clone_error(JS::Realm& realm, TransferDataEncoder& encoder, T const& value)
@@ -124,9 +124,3 @@ WEB_API WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_
WEB_API WebIDL::ExceptionOr<DeserializedTransferRecord> structured_deserialize_with_transfer(SerializedTransferRecord&, JS::Realm&);
}
-
-namespace Web::Bindings {
-
-WEB_API bool serializable_interface_is_implemented_in_rust(InterfaceName);
-
-}
diff --git a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
index 683531a8223..94f632e66ee 100644
--- a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
@@ -25,42 +25,27 @@
// What the Rust implementation of structured serialization asks of LibWeb's C++ code, declared on the Rust side in
// Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs. C++ keeps the records that the serializations
-// hand their bytes over to and the deserializations read the bytes of, the registry of serializable interfaces, the
-// platform objects, and the side tables that SharedArrayBuffers are shared through.
+// hand their bytes over to and the deserializations read the bytes of, C++ platform objects, and the side tables
+// that SharedArrayBuffers are shared through.
using namespace Web;
using namespace Web::HTML;
-// Whose steps serialize and deserialize the objects of a serializable interface.
-enum class SerializableSteps : u8 {
- Rust,
- DOMException,
- QuotaExceededError,
- CryptoKey,
- RTCEncodedAudioFrame,
-};
-
extern "C" {
void web_structured_serialize_set_ipc_record(IPCSerializationRecord*, ReadonlyBytes data, JSObject* const* shared_array_buffers, size_t count);
void web_structured_serialize_set_storage_record(StorageSerializationRecord*, ReadonlyBytes data);
-bool web_structured_serialize_interface_storage_identifier(u16 interface_name, ReadonlyBytes* identifier);
-bool web_structured_serialize_is_ipc_interface(u16 interface_name);
-bool web_structured_serialize_interface_name_from_storage_identifier(ReadonlyBytes identifier, u16* interface_name);
void web_structured_serialize_ipc_record_data(IPCSerializationRecord const*, ReadonlyBytes* data);
JSObject* web_structured_serialize_ipc_record_shared_array_buffer(IPCSerializationRecord const*, u32 side_table_index);
JSCompletion web_structured_serialize_data_clone_error_from_serialization_error(void* realm, ReadonlyBytes message);
-u64 web_structured_serialize_serializable_payload_version();
-
bool web_structured_serialize_current_settings_object_agent_cluster(u64* agent_cluster);
bool web_structured_serialize_current_settings_object_cross_origin_isolated_capability();
bool web_structured_serialize_realm_agent_cluster(void* realm, u64* agent_cluster);
bool web_structured_serialize_cpp_interface_name(JSObject*, u16* interface_name);
bool web_structured_serialize_is_exposed(u16 interface_name, void* realm);
-u8 web_structured_serialize_serializable_steps(u16 interface_name);
ImageBitmapSharedPixels* web_structured_serialize_gather_image_bitmap_pixels(JSObject* const* transfer_list, size_t count, u32 buffer_index, int* shared_memory, size_t* size);
void web_structured_serialize_image_bitmap_pixels_destroy(ImageBitmapSharedPixels*);
@@ -112,37 +97,6 @@ void web_structured_serialize_set_storage_record(StorageSerializationRecord* rec
record->data = MUST(ByteBuffer::copy(data));
}
-bool web_structured_serialize_interface_storage_identifier(u16 interface_name, ReadonlyBytes* identifier)
-{
- for (auto const& entry : serializable_storage_registry()) {
- if (entry.interface_name == static_cast<Bindings::InterfaceName>(interface_name)) {
- *identifier = entry.identifier.bytes();
- return true;
- }
- }
- return false;
-}
-
-bool web_structured_serialize_is_ipc_interface(u16 interface_name)
-{
- // Encoded audio frames can be cloned between agents, but cannot be stored.
- if (static_cast<Bindings::InterfaceName>(interface_name) == Bindings::InterfaceName::RTCEncodedAudioFrame)
- return true;
- ReadonlyBytes identifier;
- return web_structured_serialize_interface_storage_identifier(interface_name, &identifier);
-}
-
-bool web_structured_serialize_interface_name_from_storage_identifier(ReadonlyBytes identifier, u16* interface_name)
-{
- for (auto const& entry : serializable_storage_registry()) {
- if (entry.identifier.bytes() == identifier) {
- *interface_name = to_underlying(entry.interface_name);
- return true;
- }
- }
- return false;
-}
-
void web_structured_serialize_ipc_record_data(IPCSerializationRecord const* record, ReadonlyBytes* data)
{
*data = record->data.span();
@@ -163,11 +117,6 @@ JSCompletion web_structured_serialize_data_clone_error_from_serialization_error(
return Bindings::completion_to_abi(js_realm, WebIDL::ExceptionOr<JS::Value> { data_clone_error_from_serialization_error(js_realm, error) });
}
-u64 web_structured_serialize_serializable_payload_version()
-{
- return serializable_payload_version;
-}
-
bool web_structured_serialize_current_settings_object_agent_cluster(u64* agent_cluster)
{
auto id = current_settings_object().agent_cluster_id();
@@ -205,23 +154,6 @@ bool web_structured_serialize_is_exposed(u16 interface_name, void* realm)
return Bindings::is_exposed(static_cast<Bindings::InterfaceName>(interface_name), realm_from_abi(realm));
}
-u8 web_structured_serialize_serializable_steps(u16 interface_name)
-{
- switch (static_cast<Bindings::InterfaceName>(interface_name)) {
- case Bindings::InterfaceName::DOMException:
- return to_underlying(SerializableSteps::DOMException);
- case Bindings::InterfaceName::QuotaExceededError:
- return to_underlying(SerializableSteps::QuotaExceededError);
- case Bindings::InterfaceName::CryptoKey:
- return to_underlying(SerializableSteps::CryptoKey);
- case Bindings::InterfaceName::RTCEncodedAudioFrame:
- return to_underlying(SerializableSteps::RTCEncodedAudioFrame);
- default:
- VERIFY(Bindings::serializable_interface_is_implemented_in_rust(static_cast<Bindings::InterfaceName>(interface_name)));
- return to_underlying(SerializableSteps::Rust);
- }
-}
-
// AD-HOC: Gather the pixels of the transferred ImageBitmaps in one buffer of shared memory. Without it, as when there
// is not enough memory for it, the pixels travel inline.
ImageBitmapSharedPixels* web_structured_serialize_gather_image_bitmap_pixels(JSObject* const* transfer_list, size_t count, u32 buffer_index, int* shared_memory, size_t* size)
diff --git a/Libraries/LibWeb/HTML/StructuredSerializeTypes.h b/Libraries/LibWeb/HTML/StructuredSerializeTypes.h
index 0547b3af754..7b019316fed 100644
--- a/Libraries/LibWeb/HTML/StructuredSerializeTypes.h
+++ b/Libraries/LibWeb/HTML/StructuredSerializeTypes.h
@@ -16,11 +16,6 @@
namespace Web::HTML {
-// The per-interface payload version encoded after every SerializableObject's interface name in
-// storage records. The decoder requires an exact match, so a bump orphans stored records of every
-// type unless migration support is added alongside it.
-static constexpr u64 serializable_payload_version = 1;
-
// A storage-golden expectation, not a deserializer rule.
enum class Expectation : u8 {
PositiveGolden,
diff --git a/Meta/CMake/libweb_generators.cmake b/Meta/CMake/libweb_generators.cmake
index cb4a29d5e27..11a0ff84472 100644
--- a/Meta/CMake/libweb_generators.cmake
+++ b/Meta/CMake/libweb_generators.cmake
@@ -316,7 +316,6 @@ function (generate_js_bindings target)
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_types.py"
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/rust_usage.py"
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/security_checks.py"
- "${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/structured_serialize.py"
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/to_idl_value.py"
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/to_js_value.py"
"${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_bindings/wrappers.py"
@@ -359,10 +358,6 @@ function (generate_js_bindings target)
list(APPEND LIBWEB_ALL_GENERATED_HEADERS ${GLOBAL_MIXIN_HEADERS})
list(APPEND LIBWEB_ALL_BINDINGS_SOURCES ${GLOBAL_MIXIN_HEADERS})
- set(STRUCTURED_SERIALIZE_BINDINGS_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/Bindings/StructuredSerializeBindings.cpp")
- target_sources(${target} PRIVATE ${STRUCTURED_SERIALIZE_BINDINGS_SOURCE})
- list(APPEND LIBWEB_ALL_BINDINGS_SOURCES ${STRUCTURED_SERIALIZE_BINDINGS_SOURCE})
-
set(LIBWEB_ALL_IDL_FILES_ARGUMENT ${LIBWEB_ALL_IDL_FILES})
set(LIBWEB_ALL_PARSED_IDL_FILES_ARGUMENT ${LIBWEB_ALL_PARSED_IDL_FILES})
set(LIBWEB_BINDINGS_DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/Bindings/LibWebBindings.d")
diff --git a/Meta/Generators/generate_libweb_bindings.py b/Meta/Generators/generate_libweb_bindings.py
index 7b0cf47718d..06909099ff8 100644
--- a/Meta/Generators/generate_libweb_bindings.py
+++ b/Meta/Generators/generate_libweb_bindings.py
@@ -30,7 +30,6 @@ from Generators.libweb_bindings.intrinsics import write_wrapper_factory_implemen
from Generators.libweb_bindings.json_conversions import write_dictionary_json_conversions
from Generators.libweb_bindings.json_conversions import write_dictionary_json_declarations
from Generators.libweb_bindings.rust_usage import DefinitionUsage
-from Generators.libweb_bindings.structured_serialize import write_structured_serialize_bindings_implementation
from Generators.libweb_bindings.to_idl_value import dictionaries_in_dependency_order
from Generators.libweb_bindings.to_idl_value import write_dictionary_conversion
from Generators.libweb_bindings.to_idl_value import write_dictionary_declaration
@@ -362,14 +361,6 @@ def main() -> int:
)
output_files.append(rust_bindings_path)
- structured_serialize_bindings_implementation_path = output_directory / "StructuredSerializeBindings.cpp"
- write_generated_file(
- structured_serialize_bindings_implementation_path,
- write_structured_serialize_bindings_implementation,
- interface_sets.intrinsics,
- )
- output_files.append(structured_serialize_bindings_implementation_path)
-
if arguments.depfile is not None:
generate_depfile(arguments.depfile, dependency_paths, output_files)
diff --git a/Meta/Generators/libweb_bindings/rust_structured_serialize.py b/Meta/Generators/libweb_bindings/rust_structured_serialize.py
index c00d1a25ef5..96c69f7f99c 100644
--- a/Meta/Generators/libweb_bindings/rust_structured_serialize.py
+++ b/Meta/Generators/libweb_bindings/rust_structured_serialize.py
@@ -10,6 +10,29 @@ from Generators.libweb_bindings.rust_types import is_implemented_in_rust
from Generators.libweb_bindings.rust_types import rust_interface_path
from Utils.webidl_parser import Interface
+# These strings are persisted in storage records. IDL decoration alone does not mean the wire format supports an interface.
+STORAGE_IDENTIFIERS = (
+ "Blob",
+ "CryptoKey",
+ "DOMException",
+ "DOMMatrix",
+ "DOMMatrixReadOnly",
+ "DOMPoint",
+ "DOMPointReadOnly",
+ "DOMQuad",
+ "DOMRect",
+ "DOMRectReadOnly",
+ "File",
+ "FileList",
+ "ImageBitmap",
+ "ImageData",
+ "Module",
+ "QuotaExceededError",
+)
+
+# The serializable interfaces implemented in C++ whose steps run in Rust.
+CPP_INTERFACES_WITH_RUST_STEPS = ("CryptoKey", "DOMException", "QuotaExceededError", "RTCEncodedAudioFrame")
+
def write_rust_serializable_dispatch(out: TextIO, interfaces: List[Interface], values: Dict[str, int]) -> None:
serializable = sorted(
@@ -17,7 +40,6 @@ def write_rust_serializable_dispatch(out: TextIO, interfaces: List[Interface], v
key=lambda interface: interface.name,
)
rust_interfaces = [interface for interface in serializable if is_implemented_in_rust(interface)]
- cpp_interfaces = [interface for interface in serializable if not is_implemented_in_rust(interface)]
out.write(
"""
pub(crate) mod serializable_objects {
@@ -25,9 +47,10 @@ pub(crate) mod serializable_objects {
use crate::bindings::{CallContext, WebIdlResult};
use crate::bindings::interface::is_exact_wrapper;
use crate::bindings::structured_data::{self, SerializationReader, SerializationWriter};
+ use crate::html::structured_serialize::serializable::{SerializableRegistryEntry, SerializableSteps};
const CPP_INTERFACES: &[u16] = &["""
- + ", ".join(str(values[interface.name]) for interface in cpp_interfaces)
+ + ", ".join(str(values[name]) for name in CPP_INTERFACES_WITH_RUST_STEPS)
+ """];
pub(crate) fn rust_interface_name(object: Gc<Object>) -> Option<u16> {
@@ -83,6 +106,39 @@ pub(crate) mod serializable_objects {
""" _ => unreachable!("the interface is a Rust serializable interface"),
}
}
+
+ pub(crate) const STORAGE_INTERFACES: &[SerializableRegistryEntry] = &[
+"""
+ )
+ for name in STORAGE_IDENTIFIERS:
+ out.write(f' SerializableRegistryEntry {{ interface_name: {values[name]}, identifier: b"{name}" }},\n')
+ out.write(
+ f""" ];
+
+ pub(crate) fn serializable_interface_storage_identifier(interface_name: u16) -> Option<&'static [u8]> {{
+ STORAGE_INTERFACES.iter().find(|entry| entry.interface_name == interface_name).map(|entry| entry.identifier)
+ }}
+
+ pub(crate) fn serializable_interface_name_from_storage_identifier(identifier: &[u8]) -> Option<u16> {{
+ STORAGE_INTERFACES.iter().find(|entry| entry.identifier == identifier).map(|entry| entry.interface_name)
+ }}
+
+ pub(crate) fn is_ipc_interface(interface_name: u16) -> bool {{
+ interface_name == {values["RTCEncodedAudioFrame"]} || serializable_interface_storage_identifier(interface_name).is_some()
+ }}
+
+ pub(crate) fn serializable_steps(interface_name: u16) -> SerializableSteps {{
+ match interface_name {{
+"""
+ )
+ for name in CPP_INTERFACES_WITH_RUST_STEPS:
+ out.write(f" {values[name]} => SerializableSteps::{name},\n")
+ for interface in rust_interfaces:
+ out.write(f" {values[interface.name]} => SerializableSteps::Rust,\n")
+ out.write(
+ """ _ => unreachable!("the interface has serialization steps"),
+ }
+ }
}
"""
)
diff --git a/Meta/Generators/libweb_bindings/structured_serialize.py b/Meta/Generators/libweb_bindings/structured_serialize.py
deleted file mode 100644
index 8d4937b0eb5..00000000000
--- a/Meta/Generators/libweb_bindings/structured_serialize.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (c) 2026-present, the Ladybird developers.
-#
-# SPDX-License-Identifier: BSD-2-Clause
-
-from typing import List
-from typing import TextIO
-
-from Generators.libweb_bindings.rust_types import is_implemented_in_rust
-from Utils.webidl_parser import Interface
-
-
-def write_structured_serialize_bindings_implementation(out: TextIO, interfaces: List[Interface]) -> None:
- out.write("#include <LibWeb/HTML/StructuredSerialize.h>\n\nnamespace Web::Bindings {\n")
- out.write(
- "bool serializable_interface_is_implemented_in_rust(InterfaceName interface_name)\n{\n switch (interface_name) {\n"
- )
- for interface in interfaces:
- if "Serializable" in interface.extended_attributes and is_implemented_in_rust(interface):
- out.write(f" case InterfaceName::{interface.name}:\n")
- out.write(" return true;\n default:\n return false;\n }\n}\n}\n")