Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MessagePort and MessageChannel #16622

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement MessageChannel

  • Loading branch information
KiChjang committed Jun 9, 2019
commit 99842e446701f938fe09e0ee1f77d9db70b7ad0f
@@ -0,0 +1,60 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::codegen::Bindings::MessageChannelBinding::{MessageChannelMethods, Wrap};
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::messageport::MessagePort;
use dom_struct::dom_struct;

#[dom_struct]
pub struct MessageChannel {
reflector_: Reflector,
port1: Dom<MessagePort>,
port2: Dom<MessagePort>,
}

impl MessageChannel {
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel>
pub fn Constructor(global: &GlobalScope) -> Fallible<DomRoot<MessageChannel>> {
let incumbent = GlobalScope::incumbent().ok_or(Error::InvalidState)?;

// Step 1
let port1 = MessagePort::new(&incumbent);

// Step 2
let port2 = MessagePort::new(&incumbent);

// Step 3
port1.entangle(&port2);

// Steps 4-6
let channel = reflect_dom_object(Box::new(
MessageChannel {
reflector_: Reflector::new(),
port1: Dom::from_ref(&port1),
port2: Dom::from_ref(&port2),
}),
global,
Wrap
);

// Step 7
Ok(channel)
}
}

impl MessageChannelMethods for MessageChannel {
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel-port1>
fn Port1(&self) -> DomRoot<MessagePort> {
DomRoot::from_ref(&*self.port1)
}

/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel-port2>
fn Port2(&self) -> DomRoot<MessagePort> {
DomRoot::from_ref(&*self.port2)
}
}
@@ -401,6 +401,7 @@ pub mod mediaquerylist;
pub mod mediaquerylistevent;
pub mod mediastream;
pub mod mediastreamtrack;
pub mod messagechannel;
pub mod messageevent;
pub mod messageport;
pub mod mimetype;
@@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is:
* https://html.spec.whatwg.org/multipage/#messagechannel
*/

[Constructor, Exposed=(Window,Worker)]
interface MessageChannel {
readonly attribute MessagePort port1;
readonly attribute MessagePort port2;
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.