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 MessageEvent.InitMessageEvent #25276

Merged
merged 3 commits into from Dec 18, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::codegen::Bindings::MessageEventBinding;
use crate::dom::bindings::codegen::Bindings::MessageEventBinding::MessageEventMethods;
@@ -56,10 +57,10 @@ pub struct MessageEvent {
event: Event,
#[ignore_malloc_size_of = "mozjs"]
data: Heap<JSVal>,
origin: DOMString,
source: Option<SrcObject>,
lastEventId: DOMString,
ports: Vec<DomRoot<MessagePort>>,
origin: DomRefCell<DOMString>,
source: DomRefCell<Option<SrcObject>>,
lastEventId: DomRefCell<DOMString>,
ports: DomRefCell<Vec<DomRoot<MessagePort>>>,
}

impl MessageEvent {
@@ -85,10 +86,10 @@ impl MessageEvent {
let ev = Box::new(MessageEvent {
event: Event::new_inherited(),
data: Heap::default(),
source: source.map(|source| source.into()),
origin,
lastEventId,
ports,
source: DomRefCell::new(source.map(|source| source.into())),
origin: DomRefCell::new(origin),
lastEventId: DomRefCell::new(lastEventId),
ports: DomRefCell::new(ports),
});
let ev = reflect_dom_object(ev, global, MessageEventBinding::Wrap);
ev.data.set(data.get());
@@ -187,12 +188,12 @@ impl MessageEventMethods for MessageEvent {

/// <https://html.spec.whatwg.org/multipage/#dom-messageevent-origin>
fn Origin(&self) -> DOMString {
self.origin.clone()
self.origin.borrow().clone()
}

// https://html.spec.whatwg.org/multipage/#dom-messageevent-source
fn GetSource(&self) -> Option<WindowProxyOrMessagePortOrServiceWorker> {
match &self.source {
match &*self.source.borrow() {
Some(SrcObject::WindowProxy(i)) => Some(
WindowProxyOrMessagePortOrServiceWorker::WindowProxy(DomRoot::from_ref(&*i)),
),
@@ -208,7 +209,7 @@ impl MessageEventMethods for MessageEvent {

/// <https://html.spec.whatwg.org/multipage/#dom-messageevent-lasteventid>
fn LastEventId(&self) -> DOMString {
self.lastEventId.clone()
self.lastEventId.borrow().clone()
}

/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
@@ -218,6 +219,28 @@ impl MessageEventMethods for MessageEvent {

/// <https://html.spec.whatwg.org/multipage/#dom-messageevent-ports>
fn Ports(&self, cx: JSContext) -> JSVal {
message_ports_to_frozen_array(self.ports.as_slice(), cx)
message_ports_to_frozen_array(self.ports.borrow().as_slice(), cx)
}

/// <https://html.spec.whatwg.org/multipage/#dom-messageevent-initmessageevent>
fn InitMessageEvent(
&self,
_cx: JSContext,
type_: DOMString,
bubbles: bool,
cancelable: bool,
data: HandleValue,
origin: DOMString,
lastEventId: DOMString,
source: Option<WindowProxyOrMessagePortOrServiceWorker>,
ports: Vec<DomRoot<MessagePort>>,
) {
self.data.set(data.get());
*self.origin.borrow_mut() = origin.clone();
*self.source.borrow_mut() = source.as_ref().map(|source| source.into());
*self.lastEventId.borrow_mut() = lastEventId.clone();
*self.ports.borrow_mut() = ports;
self.event
.init_event(Atom::from(type_), bubbles, cancelable);
}
}
@@ -11,6 +11,17 @@ interface MessageEvent : Event {
readonly attribute DOMString lastEventId;
readonly attribute MessageEventSource? source;
readonly attribute /*FrozenArray<MessagePort>*/any ports;

void initMessageEvent(
DOMString type,
optional boolean bubbles = false,
optional boolean cancelable = false,
optional any data = null,
optional DOMString origin = "",
optional DOMString lastEventId = "",
optional MessageEventSource? source = null,
optional sequence<MessagePort> ports = []
);
};

dictionary MessageEventInit : EventInit {
@@ -245,9 +245,6 @@
[SVGElement interface: attribute onchange]
expected: FAIL
[MessageEvent interface: calling initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\]) on new MessageEvent("message", { data: 5 }) with too few arguments must throw TypeError]
expected: FAIL
[OffscreenCanvasRenderingContext2D interface: operation bezierCurveTo(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
@@ -431,9 +428,6 @@
[BarProp interface: attribute visible]
expected: FAIL

[MessageEvent interface: operation initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\])]
expected: FAIL

[DragEvent interface object name]
expected: FAIL

@@ -551,9 +545,6 @@
[SVGElement interface: attribute onsuspend]
expected: FAIL

[MessageEvent interface: new MessageEvent("message", { data: 5 }) must inherit property "initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\])" with the proper type]
expected: FAIL

[DragEvent interface: existence and properties of interface prototype object]
expected: FAIL

@@ -92,9 +92,6 @@
[OffscreenCanvasRenderingContext2D interface: operation beginPath()]
expected: FAIL
[MessageEvent interface: calling initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\]) on new MessageEvent("message", { data: 5 }) with too few arguments must throw TypeError]
expected: FAIL
[OffscreenCanvasRenderingContext2D interface: attribute lineWidth]
expected: FAIL
@@ -152,9 +149,6 @@
[Path2D interface object name]
expected: FAIL

[MessageEvent interface: operation initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\])]
expected: FAIL

[OffscreenCanvasRenderingContext2D interface: operation quadraticCurveTo(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL

@@ -209,9 +203,6 @@
[Path2D interface: operation quadraticCurveTo(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL

[MessageEvent interface: new MessageEvent("message", { data: 5 }) must inherit property "initMessageEvent(DOMString, boolean, boolean, any, USVString, DOMString, MessageEventSource, [object Object\])" with the proper type]
expected: FAIL

[OffscreenCanvasRenderingContext2D interface: attribute lineCap]
expected: FAIL

@@ -1,23 +1,14 @@
[messageevent-constructor.https.html]
type: testharness
[Default event values]
expected: FAIL

[ports attribute should be a FrozenArray]
expected: FAIL

[initMessageEvent operation]
expected: FAIL

[All parameters to initMessageEvent should be mandatory]
expected: FAIL

[Passing ServiceWorker for source member]
expected: FAIL

[initMessageEvent operation default parameter values]
expected: FAIL

[MessageEvent constructor]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.