aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/messageevent.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-12-18 17:01:36 -0500
committerGitHub <noreply@github.com>2019-12-18 17:01:36 -0500
commitf183d66217a3647a9a69d8004ab806193c7b021f (patch)
treee6ece7d3695136c915e85a63d80a937d5ff05603 /components/script/dom/messageevent.rs
parentb49e74b1f277587b4899fb8feea6bb50d3a41312 (diff)
parentb4090cce6ef80c4fe0374ffa908b6dc9b3fb2d10 (diff)
downloadservo-f183d66217a3647a9a69d8004ab806193c7b021f.tar.gz
servo-f183d66217a3647a9a69d8004ab806193c7b021f.zip
Auto merge of #25276 - kunalmohan:25192-initMessageEvent, r=jdm
Implement MessageEvent.InitMessageEvent <!-- Please describe your changes on the following line: --> InitMessageEvent had to be implemented as required by wpt. For this few keys of struct `MessageEvent` are now wrapped inside DomRefCell wrapper. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [x] These changes fix #25192 (GitHub issue number if applicable) <!-- Either: --> - [X] There are tests for these changes <!-- 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. -->
Diffstat (limited to 'components/script/dom/messageevent.rs')
-rw-r--r--components/script/dom/messageevent.rs47
1 files changed, 35 insertions, 12 deletions
diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs
index 9d9e5f88e35..cc5725ffb6c 100644
--- a/components/script/dom/messageevent.rs
+++ b/components/script/dom/messageevent.rs
@@ -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);
}
}