diff options
author | Josh Matthews <josh@joshmatthews.net> | 2025-03-15 09:58:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-15 13:58:56 +0000 |
commit | d8fc1d8bb88d291233022f52550628e6fc0376a4 (patch) | |
tree | 3c99cae670682dbf5d7cf8cbffa151c8c55aef65 /components/shared/script/serializable.rs | |
parent | 21ecfdd088faa68ba470b15fff6eee61c05e6bba (diff) | |
download | servo-d8fc1d8bb88d291233022f52550628e6fc0376a4.tar.gz servo-d8fc1d8bb88d291233022f52550628e6fc0376a4.zip |
Refactor common boilerplate out of serialize/transfer implementations (#35831)
* script: Create infrastructure for reducing hand-written serializable/transferrable implementations.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Clone all serializable DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Deserialize all serializable DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Serialize all serializable DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Transfer-receive all transferable DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Transfer all transferable DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Formatting.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Extract boilerplate from serialize/deserialize implementations.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Extract boilerplate from transfer-receive.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Extract boilerplate from transfer operation.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Tidy fixes.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Check transferability of all DOM interfaces.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Clippy fixes.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Clippy fixes.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Remove unnecessary duplicate crate.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Formatting.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/shared/script/serializable.rs')
-rw-r--r-- | components/shared/script/serializable.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/components/shared/script/serializable.rs b/components/shared/script/serializable.rs index d168736f961..8e9f9f5b3da 100644 --- a/components/shared/script/serializable.rs +++ b/components/shared/script/serializable.rs @@ -60,6 +60,39 @@ impl FileBlob { } } +impl crate::BroadcastClone for BlobImpl { + type Id = BlobId; + + fn source( + data: &crate::StructuredSerializedData, + ) -> &Option<std::collections::HashMap<Self::Id, Self>> { + &data.blobs + } + + fn destination( + data: &mut crate::StructuredSerializedData, + ) -> &mut Option<std::collections::HashMap<Self::Id, Self>> { + &mut data.blobs + } + + fn clone_for_broadcast(&self) -> Option<Self> { + let type_string = self.type_string(); + + if let BlobData::Memory(bytes) = self.blob_data() { + let blob_clone = BlobImpl::new_from_bytes(bytes.clone(), type_string); + + // Note: we insert the blob at the original id, + // otherwise this will not match the storage key as serialized by SM in `serialized`. + // The clone has it's own new Id however. + return Some(blob_clone); + } else { + // Not panicking only because this is called from the constellation. + log::warn!("Serialized blob not in memory format(should never happen)."); + } + None + } +} + /// The data backing a DOM Blob. #[derive(Debug, Deserialize, MallocSizeOf, Serialize)] pub struct BlobImpl { |