mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
script: Add generic root storage to StructuredCloneReader. (#36640)
This reduces the boilerplate necessary for adding new serializable/transferable interfaces to the structured cloning code. We always need to root the deserialized objects when performing a read operation, but we don't actually need the concrete object types in the majority of cases. By storing a list of rooted JS object values, we can push generic reflector objects into it, and extract the types we need (MessagePort) at the very end. Testing: Existing WPT structured cloning tests will provide coverage. Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
7c1e5918a8
commit
5d3cbc67ee
10 changed files with 73 additions and 126 deletions
|
@ -17,9 +17,9 @@ use crate::dom::bindings::reflector::{
|
|||
Reflector, reflect_dom_object, reflect_dom_object_with_proto,
|
||||
};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::serializable::{Serializable, StorageKey};
|
||||
use crate::dom::bindings::serializable::Serializable;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::structuredclone::{StructuredData, StructuredDataReader};
|
||||
use crate::dom::bindings::structuredclone::StructuredData;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
|
@ -252,18 +252,12 @@ impl Serializable for DOMException {
|
|||
))
|
||||
}
|
||||
|
||||
fn serialized_storage(
|
||||
data: StructuredData<'_>,
|
||||
) -> &mut Option<HashMap<DomExceptionId, Self::Data>> {
|
||||
fn serialized_storage<'a>(
|
||||
data: StructuredData<'a, '_>,
|
||||
) -> &'a mut Option<HashMap<DomExceptionId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.exceptions,
|
||||
StructuredData::Writer(writer) => &mut writer.exceptions,
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialized_storage(
|
||||
reader: &mut StructuredDataReader,
|
||||
) -> &mut Option<HashMap<StorageKey, DomRoot<Self>>> {
|
||||
&mut reader.dom_exceptions
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue