mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Auto merge of #25821 - gterzian:fix_messagechannel_constructor_idiom, r=Manishearth
Use new and new_inherited in messagechannel <!-- Please describe your changes on the following line: --> Use common DOM constructor idioms in `MessageChannel`. Also, remove the falliable from the result, since that seems to match the spec better https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messagechannel --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
ada95b9878
2 changed files with 17 additions and 14 deletions
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* 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::codegen::Bindings::MessageChannelBinding::{MessageChannelMethods, Wrap};
|
||||||
use crate::dom::bindings::error::{Error, Fallible};
|
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
@ -20,9 +19,12 @@ pub struct MessageChannel {
|
||||||
impl MessageChannel {
|
impl MessageChannel {
|
||||||
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel>
|
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel>
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn Constructor(global: &GlobalScope) -> Fallible<DomRoot<MessageChannel>> {
|
pub fn Constructor(global: &GlobalScope) -> DomRoot<MessageChannel> {
|
||||||
let incumbent = GlobalScope::incumbent().ok_or(Error::InvalidState)?;
|
MessageChannel::new(global)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel>
|
||||||
|
pub fn new(incumbent: &GlobalScope) -> DomRoot<MessageChannel> {
|
||||||
// Step 1
|
// Step 1
|
||||||
let port1 = MessagePort::new(&incumbent);
|
let port1 = MessagePort::new(&incumbent);
|
||||||
|
|
||||||
|
@ -39,18 +41,19 @@ impl MessageChannel {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Steps 4-6
|
// Steps 4-6
|
||||||
let channel = reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(MessageChannel {
|
Box::new(MessageChannel::new_inherited(&*port1, &*port2)),
|
||||||
reflector_: Reflector::new(),
|
incumbent,
|
||||||
port1: Dom::from_ref(&port1),
|
|
||||||
port2: Dom::from_ref(&port2),
|
|
||||||
}),
|
|
||||||
global,
|
|
||||||
Wrap,
|
Wrap,
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Step 7
|
pub fn new_inherited(port1: &MessagePort, port2: &MessagePort) -> MessageChannel {
|
||||||
Ok(channel)
|
MessageChannel {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
port1: Dom::from_ref(port1),
|
||||||
|
port2: Dom::from_ref(port2),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
[Exposed=(Window,Worker)]
|
[Exposed=(Window,Worker)]
|
||||||
interface MessageChannel {
|
interface MessageChannel {
|
||||||
[Throws] constructor();
|
constructor();
|
||||||
readonly attribute MessagePort port1;
|
readonly attribute MessagePort port1;
|
||||||
readonly attribute MessagePort port2;
|
readonly attribute MessagePort port2;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue