1use js::gc::RootedVec;
6use js::jsapi::{Heap, JSObject};
7use rustc_hash::FxHashMap;
8use servo_base::id::{
9 BlobId, CryptoKeyId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, FileId,
10 FileListId, ImageBitmapId, ImageDataId, MessagePortId, OffscreenCanvasId, QuotaExceededErrorId,
11};
12use servo_constellation_traits::{
13 BlobImpl, DomException, DomMatrix, DomPoint, DomQuad, DomRect, MessagePortImpl,
14 SerializableCryptoKey, SerializableFile, SerializableFileList, SerializableImageBitmap,
15 SerializableImageData, SerializableQuotaExceededError, TransferableOffscreenCanvas,
16 TransformStreamData,
17};
18
19use crate::error::Error;
20
21pub enum StructuredData<'a, 'b> {
22 Reader(&'a mut StructuredDataReader<'b>),
23 Writer(&'a mut StructuredDataWriter),
24}
25
26#[repr(C)]
29pub struct StructuredDataReader<'a> {
30 pub error: Option<Error>,
32 pub roots: RootedVec<'a, Box<Heap<*mut JSObject>>>,
34 pub port_impls: Option<FxHashMap<MessagePortId, MessagePortImpl>>,
38 pub transform_streams_port_impls: Option<FxHashMap<MessagePortId, TransformStreamData>>,
40 pub blob_impls: Option<FxHashMap<BlobId, BlobImpl>>,
44 pub files: Option<FxHashMap<FileId, SerializableFile>>,
46 pub file_lists: Option<FxHashMap<FileListId, SerializableFileList>>,
48 pub points: Option<FxHashMap<DomPointId, DomPoint>>,
50 pub rects: Option<FxHashMap<DomRectId, DomRect>>,
52 pub quads: Option<FxHashMap<DomQuadId, DomQuad>>,
54 pub matrices: Option<FxHashMap<DomMatrixId, DomMatrix>>,
56 pub exceptions: Option<FxHashMap<DomExceptionId, DomException>>,
58 pub quota_exceeded_errors:
60 Option<FxHashMap<QuotaExceededErrorId, SerializableQuotaExceededError>>,
61 pub image_bitmaps: Option<FxHashMap<ImageBitmapId, SerializableImageBitmap>>,
63 pub transferred_image_bitmaps: Option<FxHashMap<ImageBitmapId, SerializableImageBitmap>>,
65 pub offscreen_canvases: Option<FxHashMap<OffscreenCanvasId, TransferableOffscreenCanvas>>,
67 pub image_data: Option<FxHashMap<ImageDataId, SerializableImageData>>,
69 pub crypto_keys: Option<FxHashMap<CryptoKeyId, SerializableCryptoKey>>,
71}
72
73#[derive(Default)]
75#[repr(C)]
76pub struct StructuredDataWriter {
77 pub error: Option<Error>,
79 pub ports: Option<FxHashMap<MessagePortId, MessagePortImpl>>,
81 pub transform_streams_port: Option<FxHashMap<MessagePortId, TransformStreamData>>,
83 pub points: Option<FxHashMap<DomPointId, DomPoint>>,
85 pub rects: Option<FxHashMap<DomRectId, DomRect>>,
87 pub quads: Option<FxHashMap<DomQuadId, DomQuad>>,
89 pub matrices: Option<FxHashMap<DomMatrixId, DomMatrix>>,
91 pub exceptions: Option<FxHashMap<DomExceptionId, DomException>>,
93 pub quota_exceeded_errors:
95 Option<FxHashMap<QuotaExceededErrorId, SerializableQuotaExceededError>>,
96 pub blobs: Option<FxHashMap<BlobId, BlobImpl>>,
98 pub files: Option<FxHashMap<FileId, SerializableFile>>,
100 pub file_lists: Option<FxHashMap<FileListId, SerializableFileList>>,
102 pub image_bitmaps: Option<FxHashMap<ImageBitmapId, SerializableImageBitmap>>,
104 pub transferred_image_bitmaps: Option<FxHashMap<ImageBitmapId, SerializableImageBitmap>>,
106 pub offscreen_canvases: Option<FxHashMap<OffscreenCanvasId, TransferableOffscreenCanvas>>,
108 pub image_data: Option<FxHashMap<ImageDataId, SerializableImageData>>,
110 pub crypto_keys: Option<FxHashMap<CryptoKeyId, SerializableCryptoKey>>,
112}
113
114pub trait MarkedAsSerializableInIdl {
117 fn assert_serializable();
119}
120
121pub trait MarkedAsTransferableInIdl {
124 fn assert_transferable();
126}