script/dom/bindings/
transferable.rs1use std::collections::HashMap;
9use std::hash::Hash;
10
11use base::id::NamespaceIndex;
12use script_bindings::structuredclone::MarkedAsTransferableInIdl;
13
14use crate::dom::bindings::error::Fallible;
15use crate::dom::bindings::reflector::DomObject;
16use crate::dom::bindings::root::DomRoot;
17use crate::dom::bindings::structuredclone::StructuredData;
18use crate::dom::globalscope::GlobalScope;
19
20pub(crate) trait Transferable: DomObject + MarkedAsTransferableInIdl
21where
22 Self: Sized,
23{
24 type Index: Copy + Eq + Hash;
25 type Data;
26
27 fn can_transfer(&self) -> bool {
28 true
29 }
30
31 fn transfer(&self) -> Fallible<(NamespaceIndex<Self::Index>, Self::Data)>;
33
34 fn transfer_receive(
36 owner: &GlobalScope,
37 id: NamespaceIndex<Self::Index>,
38 serialized: Self::Data,
39 ) -> Result<DomRoot<Self>, ()>;
40
41 fn serialized_storage<'a>(
42 data: StructuredData<'a, '_>,
43 ) -> &'a mut Option<HashMap<NamespaceIndex<Self::Index>, Self::Data>>;
44}
45
46pub(crate) fn assert_transferable<T: Transferable>() {}