continue messageport, transferable, postmessage options

This commit is contained in:
Gregory Terzian 2019-06-26 00:25:48 +08:00
parent c3b17c1201
commit 2f8932a6a1
100 changed files with 2456 additions and 1171 deletions

View file

@ -19,6 +19,7 @@ malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
parking_lot = "0.9"
serde = "1.0.60"
servo_url = {path = "../url"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
[dev-dependencies]

View file

@ -156,6 +156,20 @@ impl PipelineNamespace {
index: HistoryStateIndex(self.next_index()),
}
}
fn next_message_port_id(&mut self) -> MessagePortId {
MessagePortId {
namespace_id: self.id,
index: MessagePortIndex(self.next_index()),
}
}
fn next_message_port_router_id(&mut self) -> MessagePortRouterId {
MessagePortRouterId {
namespace_id: self.id,
index: MessagePortRouterIndex(self.next_index()),
}
}
}
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
@ -297,6 +311,68 @@ impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct MessagePortIndex(pub NonZeroU32);
malloc_size_of_is_0!(MessagePortIndex);
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct MessagePortId {
pub namespace_id: PipelineNamespaceId,
pub index: MessagePortIndex,
}
impl MessagePortId {
pub fn new() -> MessagePortId {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let next_message_port_id = namespace.next_message_port_id();
tls.set(Some(namespace));
next_message_port_id
})
}
}
impl fmt::Display for MessagePortId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let MessagePortIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index.get())
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct MessagePortRouterIndex(pub NonZeroU32);
malloc_size_of_is_0!(MessagePortRouterIndex);
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct MessagePortRouterId {
pub namespace_id: PipelineNamespaceId,
pub index: MessagePortRouterIndex,
}
impl MessagePortRouterId {
pub fn new() -> MessagePortRouterId {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let next_message_port_router_id = namespace.next_message_port_router_id();
tls.set(Some(namespace));
next_message_port_router_id
})
}
}
impl fmt::Display for MessagePortRouterId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let MessagePortRouterIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index.get())
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct HistoryStateIndex(pub NonZeroU32);
malloc_size_of_is_0!(HistoryStateIndex);