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