script/dom/bindings/
transferable.rs1use std::hash::Hash;
9
10use base::id::NamespaceIndex;
11use rustc_hash::FxHashMap;
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(
33 &self,
34 cx: &mut js::context::JSContext,
35 ) -> Fallible<(NamespaceIndex<Self::Index>, Self::Data)>;
36
37 fn transfer_receive(
39 cx: &mut js::context::JSContext,
40 owner: &GlobalScope,
41 id: NamespaceIndex<Self::Index>,
42 serialized: Self::Data,
43 ) -> Result<DomRoot<Self>, ()>;
44
45 fn serialized_storage<'a>(
46 data: StructuredData<'a, '_>,
47 ) -> &'a mut Option<FxHashMap<NamespaceIndex<Self::Index>, Self::Data>>;
48}
49
50pub(crate) fn assert_transferable<T: Transferable>() {}