Make DOMPoint and DOMPointReadOnly serializable (#35989)

* script: Make DOMPointReadOnly serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make DOMPoint serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Shrink worker script event.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Update components/script/dom/dompoint.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Josh Matthews 2025-03-26 21:35:02 -04:00 committed by GitHub
parent 1df1ba58d6
commit 53a2e61fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 224 additions and 45 deletions

View file

@ -16,7 +16,7 @@ pub(crate) enum WorkerScriptMsg {
/// Message sent through Worker.postMessage /// Message sent through Worker.postMessage
DOMMessage { DOMMessage {
origin: ImmutableOrigin, origin: ImmutableOrigin,
data: StructuredSerializedData, data: Box<StructuredSerializedData>,
}, },
} }

View file

@ -9,7 +9,7 @@ use std::num::NonZeroU32;
use std::os::raw; use std::os::raw;
use std::ptr; use std::ptr;
use base::id::{BlobId, MessagePortId, PipelineNamespaceId}; use base::id::{BlobId, DomPointId, MessagePortId, PipelineNamespaceId};
use js::glue::{ use js::glue::{
CopyJSStructuredCloneData, DeleteJSAutoStructuredCloneBuffer, GetLengthOfJSStructuredCloneData, CopyJSStructuredCloneData, DeleteJSAutoStructuredCloneBuffer, GetLengthOfJSStructuredCloneData,
NewJSAutoStructuredCloneBuffer, WriteBytesToJSStructuredCloneData, NewJSAutoStructuredCloneBuffer, WriteBytesToJSStructuredCloneData,
@ -24,7 +24,7 @@ use js::jsval::UndefinedValue;
use js::rust::wrappers::{JS_ReadStructuredClone, JS_WriteStructuredClone}; use js::rust::wrappers::{JS_ReadStructuredClone, JS_WriteStructuredClone};
use js::rust::{CustomAutoRooterGuard, HandleValue, MutableHandleValue}; use js::rust::{CustomAutoRooterGuard, HandleValue, MutableHandleValue};
use script_bindings::conversions::IDLInterface; use script_bindings::conversions::IDLInterface;
use script_traits::serializable::BlobImpl; use script_traits::serializable::{BlobImpl, DomPoint};
use script_traits::transferable::MessagePortImpl; use script_traits::transferable::MessagePortImpl;
use script_traits::{ use script_traits::{
Serializable as SerializableInterface, StructuredSerializedData, Serializable as SerializableInterface, StructuredSerializedData,
@ -38,6 +38,8 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::serializable::{IntoStorageKey, Serializable, StorageKey}; use crate::dom::bindings::serializable::{IntoStorageKey, Serializable, StorageKey};
use crate::dom::bindings::transferable::{ExtractComponents, IdFromComponents, Transferable}; use crate::dom::bindings::transferable::{ExtractComponents, IdFromComponents, Transferable};
use crate::dom::blob::Blob; use crate::dom::blob::Blob;
use crate::dom::dompoint::DOMPoint;
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::messageport::MessagePort; use crate::dom::messageport::MessagePort;
use crate::realms::{AlreadyInRealm, InRealm, enter_realm}; use crate::realms::{AlreadyInRealm, InRealm, enter_realm};
@ -54,6 +56,8 @@ pub(super) enum StructuredCloneTags {
DomBlob = 0xFFFF8001, DomBlob = 0xFFFF8001,
MessagePort = 0xFFFF8002, MessagePort = 0xFFFF8002,
Principals = 0xFFFF8003, Principals = 0xFFFF8003,
DomPointReadOnly = 0xFFFF8004,
DomPoint = 0xFFFF8005,
Max = 0xFFFFFFFF, Max = 0xFFFFFFFF,
} }
@ -61,6 +65,8 @@ impl From<SerializableInterface> for StructuredCloneTags {
fn from(v: SerializableInterface) -> Self { fn from(v: SerializableInterface) -> Self {
match v { match v {
SerializableInterface::Blob => StructuredCloneTags::DomBlob, SerializableInterface::Blob => StructuredCloneTags::DomBlob,
SerializableInterface::DomPointReadOnly => StructuredCloneTags::DomPointReadOnly,
SerializableInterface::DomPoint => StructuredCloneTags::DomPoint,
} }
} }
} }
@ -83,6 +89,8 @@ fn reader_for_type(
) -> *mut JSObject { ) -> *mut JSObject {
match val { match val {
SerializableInterface::Blob => read_object::<Blob>, SerializableInterface::Blob => read_object::<Blob>,
SerializableInterface::DomPointReadOnly => read_object::<DOMPointReadOnly>,
SerializableInterface::DomPoint => read_object::<DOMPoint>,
} }
} }
@ -214,6 +222,8 @@ type SerializeOperation = unsafe fn(
fn serialize_for_type(val: SerializableInterface) -> SerializeOperation { fn serialize_for_type(val: SerializableInterface) -> SerializeOperation {
match val { match val {
SerializableInterface::Blob => try_serialize::<Blob>, SerializableInterface::Blob => try_serialize::<Blob>,
SerializableInterface::DomPointReadOnly => try_serialize::<DOMPointReadOnly>,
SerializableInterface::DomPoint => try_serialize::<DOMPoint>,
} }
} }
@ -465,6 +475,9 @@ pub(crate) enum StructuredData<'a> {
pub(crate) struct StructuredDataReader { pub(crate) struct StructuredDataReader {
/// A map of deserialized blobs, stored temporarily here to keep them rooted. /// A map of deserialized blobs, stored temporarily here to keep them rooted.
pub(crate) blobs: Option<HashMap<StorageKey, DomRoot<Blob>>>, pub(crate) blobs: Option<HashMap<StorageKey, DomRoot<Blob>>>,
/// A map of deserialized points, stored temporarily here to keep them rooted.
pub(crate) points_read_only: Option<HashMap<StorageKey, DomRoot<DOMPointReadOnly>>>,
pub(crate) dom_points: Option<HashMap<StorageKey, DomRoot<DOMPoint>>>,
/// A vec of transfer-received DOM ports, /// A vec of transfer-received DOM ports,
/// to be made available to script through a message event. /// to be made available to script through a message event.
pub(crate) message_ports: Option<Vec<DomRoot<MessagePort>>>, pub(crate) message_ports: Option<Vec<DomRoot<MessagePort>>>,
@ -476,12 +489,17 @@ pub(crate) struct StructuredDataReader {
/// used as part of the "deserialize" steps of blobs, /// used as part of the "deserialize" steps of blobs,
/// to produce the DOM blobs stored in `blobs` above. /// to produce the DOM blobs stored in `blobs` above.
pub(crate) blob_impls: Option<HashMap<BlobId, BlobImpl>>, pub(crate) blob_impls: Option<HashMap<BlobId, BlobImpl>>,
/// A map of serialized points.
pub(crate) points: Option<HashMap<DomPointId, DomPoint>>,
} }
/// A data holder for transferred and serialized objects. /// A data holder for transferred and serialized objects.
#[derive(Default)]
pub(crate) struct StructuredDataWriter { pub(crate) struct StructuredDataWriter {
/// Transferred ports. /// Transferred ports.
pub(crate) ports: Option<HashMap<MessagePortId, MessagePortImpl>>, pub(crate) ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
/// Serialized points.
pub(crate) points: Option<HashMap<DomPointId, DomPoint>>,
/// Serialized blobs. /// Serialized blobs.
pub(crate) blobs: Option<HashMap<BlobId, BlobImpl>>, pub(crate) blobs: Option<HashMap<BlobId, BlobImpl>>,
} }
@ -497,10 +515,7 @@ pub(crate) fn write(
if let Some(transfer) = transfer { if let Some(transfer) = transfer {
transfer.to_jsval(*cx, val.handle_mut()); transfer.to_jsval(*cx, val.handle_mut());
} }
let mut sc_writer = StructuredDataWriter { let mut sc_writer = StructuredDataWriter::default();
ports: None,
blobs: None,
};
let sc_writer_ptr = &mut sc_writer as *mut _; let sc_writer_ptr = &mut sc_writer as *mut _;
let scbuf = NewJSAutoStructuredCloneBuffer( let scbuf = NewJSAutoStructuredCloneBuffer(
@ -537,6 +552,7 @@ pub(crate) fn write(
let data = StructuredSerializedData { let data = StructuredSerializedData {
serialized: data, serialized: data,
ports: sc_writer.ports.take(), ports: sc_writer.ports.take(),
points: sc_writer.points.take(),
blobs: sc_writer.blobs.take(), blobs: sc_writer.blobs.take(),
}; };
@ -556,8 +572,11 @@ pub(crate) fn read(
let mut sc_reader = StructuredDataReader { let mut sc_reader = StructuredDataReader {
blobs: None, blobs: None,
message_ports: None, message_ports: None,
points_read_only: None,
dom_points: None,
port_impls: data.ports.take(), port_impls: data.ports.take(),
blob_impls: data.blobs.take(), blob_impls: data.blobs.take(),
points: data.points.take(),
}; };
let sc_reader_ptr = &mut sc_reader as *mut _; let sc_reader_ptr = &mut sc_reader as *mut _;
unsafe { unsafe {

View file

@ -564,7 +564,8 @@ impl DedicatedWorkerGlobalScope {
let target = self.upcast(); let target = self.upcast();
let _ac = enter_realm(self); let _ac = enter_realm(self);
rooted!(in(*scope.get_cx()) let mut message = UndefinedValue()); rooted!(in(*scope.get_cx()) let mut message = UndefinedValue());
if let Ok(ports) = structuredclone::read(scope.upcast(), data, message.handle_mut()) if let Ok(ports) =
structuredclone::read(scope.upcast(), *data, message.handle_mut())
{ {
MessageEvent::dispatch_jsval( MessageEvent::dispatch_jsval(
target, target,

View file

@ -2,14 +2,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use base::id::DomPointId;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::rust::HandleObject; use js::rust::HandleObject;
use script_traits::serializable::DomPoint;
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointInit, DOMPointMethods}; use crate::dom::bindings::codegen::Bindings::DOMPointBinding::{DOMPointInit, DOMPointMethods};
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods; use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::serializable::{Serializable, StorageKey};
use crate::dom::bindings::structuredclone::{StructuredData, StructuredDataReader};
use crate::dom::dompointreadonly::{DOMPointReadOnly, DOMPointWriteMethods}; use crate::dom::dompointreadonly::{DOMPointReadOnly, DOMPointWriteMethods};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -124,3 +130,49 @@ impl DOMPointMethods<crate::DomTypeHolder> for DOMPoint {
self.point.SetW(value); self.point.SetW(value);
} }
} }
impl Serializable for DOMPoint {
type Id = DomPointId;
type Data = DomPoint;
fn serialize(&self) -> Result<(Self::Id, Self::Data), ()> {
let serialized = DomPoint {
x: self.X(),
y: self.Y(),
z: self.Z(),
w: self.W(),
};
Ok((DomPointId::new(), serialized))
}
fn deserialize(
owner: &GlobalScope,
serialized: Self::Data,
can_gc: CanGc,
) -> Result<DomRoot<Self>, ()>
where
Self: Sized,
{
Ok(Self::new(
owner,
serialized.x,
serialized.y,
serialized.z,
serialized.w,
can_gc,
))
}
fn serialized_storage(data: StructuredData<'_>) -> &mut Option<HashMap<Self::Id, Self::Data>> {
match data {
StructuredData::Reader(reader) => &mut reader.points,
StructuredData::Writer(writer) => &mut writer.points,
}
}
fn deserialized_storage(
reader: &mut StructuredDataReader,
) -> &mut Option<HashMap<StorageKey, DomRoot<Self>>> {
&mut reader.dom_points
}
}

View file

@ -3,15 +3,21 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::Cell; use std::cell::Cell;
use std::collections::HashMap;
use std::num::NonZeroU32;
use base::id::{DomPointId, DomPointIndex, PipelineNamespaceId};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::rust::HandleObject; use js::rust::HandleObject;
use script_traits::serializable::DomPoint;
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods; use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::serializable::{IntoStorageKey, Serializable, StorageKey};
use crate::dom::bindings::structuredclone::{StructuredData, StructuredDataReader};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::CanGc; use crate::script_runtime::CanGc;
@ -134,3 +140,70 @@ impl DOMPointWriteMethods for DOMPointReadOnly {
self.w.set(value); self.w.set(value);
} }
} }
impl Serializable for DOMPointReadOnly {
type Id = DomPointId;
type Data = DomPoint;
fn serialize(&self) -> Result<(Self::Id, Self::Data), ()> {
let serialized = DomPoint {
x: self.x.get(),
y: self.y.get(),
z: self.z.get(),
w: self.w.get(),
};
Ok((DomPointId::new(), serialized))
}
fn deserialize(
owner: &GlobalScope,
serialized: Self::Data,
can_gc: CanGc,
) -> Result<DomRoot<Self>, ()>
where
Self: Sized,
{
Ok(Self::new(
owner,
serialized.x,
serialized.y,
serialized.z,
serialized.w,
can_gc,
))
}
fn serialized_storage(data: StructuredData<'_>) -> &mut Option<HashMap<Self::Id, Self::Data>> {
match data {
StructuredData::Reader(r) => &mut r.points,
StructuredData::Writer(w) => &mut w.points,
}
}
fn deserialized_storage(
reader: &mut StructuredDataReader,
) -> &mut Option<HashMap<StorageKey, DomRoot<Self>>> {
&mut reader.points_read_only
}
}
impl From<StorageKey> for DomPointId {
fn from(storage_key: StorageKey) -> DomPointId {
let namespace_id = PipelineNamespaceId(storage_key.name_space);
let index = DomPointIndex(
NonZeroU32::new(storage_key.index).expect("Deserialized point index is zero"),
);
DomPointId {
namespace_id,
index,
}
}
}
impl IntoStorageKey for DomPointId {
fn into_storage_key(self) -> StorageKey {
let DomPointIndex(index) = self.index;
StorageKey::new(self.namespace_id, index)
}
}

View file

@ -123,8 +123,7 @@ impl History {
Some(data) => { Some(data) => {
let data = StructuredSerializedData { let data = StructuredSerializedData {
serialized: data, serialized: data,
ports: None, ..Default::default()
blobs: None,
}; };
rooted!(in(*GlobalScope::get_cx()) let mut state = UndefinedValue()); rooted!(in(*GlobalScope::get_cx()) let mut state = UndefinedValue());
if structuredclone::read(self.window.as_global_scope(), data, state.handle_mut()) if structuredclone::read(self.window.as_global_scope(), data, state.handle_mut())

View file

@ -443,7 +443,8 @@ impl ServiceWorkerGlobalScope {
let target = self.upcast(); let target = self.upcast();
let _ac = enter_realm(scope); let _ac = enter_realm(scope);
rooted!(in(*scope.get_cx()) let mut message = UndefinedValue()); rooted!(in(*scope.get_cx()) let mut message = UndefinedValue());
if let Ok(ports) = structuredclone::read(scope.upcast(), data, message.handle_mut()) if let Ok(ports) =
structuredclone::read(scope.upcast(), *data, message.handle_mut())
{ {
ExtendableMessageEvent::dispatch_jsval( ExtendableMessageEvent::dispatch_jsval(
target, target,

View file

@ -148,7 +148,7 @@ impl Worker {
address, address,
WorkerScriptMsg::DOMMessage { WorkerScriptMsg::DOMMessage {
origin: self.global().origin().immutable().clone(), origin: self.global().origin().immutable().clone(),
data, data: Box::new(data),
}, },
)); ));
Ok(()) Ok(())

View file

@ -64,7 +64,10 @@ impl ServiceWorker {
fn forward_dom_message(&self, msg: DOMMessage) { fn forward_dom_message(&self, msg: DOMMessage) {
let DOMMessage { origin, data } = msg; let DOMMessage { origin, data } = msg;
let _ = self.sender.send(ServiceWorkerScriptMsg::CommonWorker( let _ = self.sender.send(ServiceWorkerScriptMsg::CommonWorker(
WorkerScriptMsg::DOMMessage { origin, data }, WorkerScriptMsg::DOMMessage {
origin,
data: Box::new(data),
},
)); ));
} }

View file

@ -195,6 +195,7 @@ impl PipelineNamespace {
namespace_id_method! {next_service_worker_registration_id, ServiceWorkerRegistrationId, namespace_id_method! {next_service_worker_registration_id, ServiceWorkerRegistrationId,
self, ServiceWorkerRegistrationIndex} self, ServiceWorkerRegistrationIndex}
namespace_id_method! {next_blob_id, BlobId, self, BlobIndex} namespace_id_method! {next_blob_id, BlobId, self, BlobIndex}
namespace_id_method! {next_dom_point_id, DomPointId, self, DomPointIndex}
} }
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = const { Cell::new(None) }); thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = const { Cell::new(None) });
@ -411,6 +412,19 @@ impl BlobId {
} }
} }
namespace_id! {DomPointId, DomPointIndex, "DomPoint"}
impl DomPointId {
pub fn new() -> DomPointId {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let next_point_id = namespace.next_dom_point_id();
tls.set(Some(namespace));
next_point_id
})
}
}
namespace_id! {HistoryStateId, HistoryStateIndex, "HistoryState"} namespace_id! {HistoryStateId, HistoryStateIndex, "HistoryState"}
impl HistoryStateId { impl HistoryStateId {

View file

@ -21,8 +21,8 @@ use std::sync::Arc;
use background_hang_monitor_api::BackgroundHangMonitorRegister; use background_hang_monitor_api::BackgroundHangMonitorRegister;
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{ use base::id::{
BlobId, BrowsingContextId, HistoryStateId, MessagePortId, PipelineId, PipelineNamespaceId, BlobId, BrowsingContextId, DomPointId, HistoryStateId, MessagePortId, PipelineId,
WebViewId, PipelineNamespaceId, WebViewId,
}; };
#[cfg(feature = "bluetooth")] #[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
@ -64,7 +64,7 @@ pub use crate::script_msg::{
DOMMessage, IFrameSizeMsg, Job, JobError, JobResult, JobResultValue, JobType, SWManagerMsg, DOMMessage, IFrameSizeMsg, Job, JobError, JobResult, JobResultValue, JobType, SWManagerMsg,
SWManagerSenders, ScopeThings, ScriptMsg, ServiceWorkerMsg, TouchEventResult, SWManagerSenders, ScopeThings, ScriptMsg, ServiceWorkerMsg, TouchEventResult,
}; };
use crate::serializable::BlobImpl; use crate::serializable::{BlobImpl, DomPoint};
use crate::transferable::MessagePortImpl; use crate::transferable::MessagePortImpl;
/// The origin where a given load was initiated. /// The origin where a given load was initiated.
@ -648,12 +648,14 @@ impl ScriptToConstellationChan {
/// A data-holder for serialized data and transferred objects. /// A data-holder for serialized data and transferred objects.
/// <https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer> /// <https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer>
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)] #[derive(Debug, Default, Deserialize, MallocSizeOf, Serialize)]
pub struct StructuredSerializedData { pub struct StructuredSerializedData {
/// Data serialized by SpiderMonkey. /// Data serialized by SpiderMonkey.
pub serialized: Vec<u8>, pub serialized: Vec<u8>,
/// Serialized in a structured callback, /// Serialized in a structured callback,
pub blobs: Option<HashMap<BlobId, BlobImpl>>, pub blobs: Option<HashMap<BlobId, BlobImpl>>,
/// Serialized point objects.
pub points: Option<HashMap<DomPointId, DomPoint>>,
/// Transferred objects. /// Transferred objects.
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>, pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
} }
@ -678,12 +680,20 @@ where
pub enum Serializable { pub enum Serializable {
/// The `Blob` interface. /// The `Blob` interface.
Blob, Blob,
/// The `DOMPoint` interface.
DomPoint,
/// The `DOMPointReadOnly` interface.
DomPointReadOnly,
} }
impl Serializable { impl Serializable {
fn clone_values(&self) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) { fn clone_values(&self) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) {
match self { match self {
Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>, Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>,
Serializable::DomPointReadOnly => {
StructuredSerializedData::clone_all_of_type::<DomPoint>
},
Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
} }
} }
} }
@ -737,9 +747,7 @@ impl StructuredSerializedData {
let mut cloned = StructuredSerializedData { let mut cloned = StructuredSerializedData {
serialized, serialized,
blobs: None, ..Default::default()
// Ports cannot be broadcast.
ports: None,
}; };
for serializable in Serializable::iter() { for serializable in Serializable::iter() {

View file

@ -11,7 +11,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::path::PathBuf; use std::path::PathBuf;
use base::id::BlobId; use base::id::{BlobId, DomPointId};
use malloc_size_of_derive::MallocSizeOf; use malloc_size_of_derive::MallocSizeOf;
use net_traits::filemanager_thread::RelativePos; use net_traits::filemanager_thread::RelativePos;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -182,3 +182,36 @@ impl BlobImpl {
&mut self.blob_data &mut self.blob_data
} }
} }
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
/// A serializable version of the DOMPoint/DOMPointReadOnly interface.
pub struct DomPoint {
/// The x coordinate.
pub x: f64,
/// The y coordinate.
pub y: f64,
/// The z coordinate.
pub z: f64,
/// The w coordinate.
pub w: f64,
}
impl crate::BroadcastClone for DomPoint {
type Id = DomPointId;
fn source(
data: &crate::StructuredSerializedData,
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
&data.points
}
fn destination(
data: &mut crate::StructuredSerializedData,
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
&mut data.points
}
fn clone_for_broadcast(&self) -> Option<Self> {
Some(self.clone())
}
}

View file

@ -1,28 +1,4 @@
[structured-serialization.html] [structured-serialization.html]
[DOMPointReadOnly clone: basic]
expected: FAIL
[DOMPointReadOnly clone: custom property]
expected: FAIL
[DOMPointReadOnly clone: throwing getters]
expected: FAIL
[DOMPointReadOnly clone: non-initial values]
expected: FAIL
[DOMPoint clone: basic]
expected: FAIL
[DOMPoint clone: custom property]
expected: FAIL
[DOMPoint clone: throwing getters]
expected: FAIL
[DOMPoint clone: non-initial values]
expected: FAIL
[DOMRectReadOnly clone: basic] [DOMRectReadOnly clone: basic]
expected: FAIL expected: FAIL