mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Reduce indexing boilerplate for serializable/transferrable objects. (#36624)
Rather than creating unique types for each pipeline-namespaced index type (eg. MessagePortId, DomExceptionId, etc.), we can create a generic common type that uses a marker to prevent type confusion. This change allows us to reduce the boilerplate code required when implementing serializable/transferable interfaces, since the structured clone implementation can rely on the common type. Testing: Existing WPT tests for serialization and transferring provide coverage. --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
0b8645d422
commit
7b16ae26b4
13 changed files with 170 additions and 337 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::DomPointId;
|
||||
use base::id::{DomPointId, DomPointIndex};
|
||||
use constellation_traits::DomPoint;
|
||||
use dom_struct::dom_struct;
|
||||
use js::rust::HandleObject;
|
||||
|
@ -132,10 +132,10 @@ impl DOMPointMethods<crate::DomTypeHolder> for DOMPoint {
|
|||
}
|
||||
|
||||
impl Serializable for DOMPoint {
|
||||
type Id = DomPointId;
|
||||
type Index = DomPointIndex;
|
||||
type Data = DomPoint;
|
||||
|
||||
fn serialize(&self) -> Result<(Self::Id, Self::Data), ()> {
|
||||
fn serialize(&self) -> Result<(DomPointId, Self::Data), ()> {
|
||||
let serialized = DomPoint {
|
||||
x: self.X(),
|
||||
y: self.Y(),
|
||||
|
@ -163,7 +163,9 @@ impl Serializable for DOMPoint {
|
|||
))
|
||||
}
|
||||
|
||||
fn serialized_storage(data: StructuredData<'_>) -> &mut Option<HashMap<Self::Id, Self::Data>> {
|
||||
fn serialized_storage(
|
||||
data: StructuredData<'_>,
|
||||
) -> &mut Option<HashMap<DomPointId, Self::Data>> {
|
||||
match data {
|
||||
StructuredData::Reader(reader) => &mut reader.points,
|
||||
StructuredData::Writer(writer) => &mut writer.points,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue