diff options
Diffstat (limited to 'components/script/dom/customevent.rs')
-rw-r--r-- | components/script/dom/customevent.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 6c1e71b3b08..ac7017e1817 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -13,6 +13,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::event::Event; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; +use string_cache::Atom; use util::str::DOMString; // https://dom.spec.whatwg.org/#interface-customevent @@ -37,13 +38,13 @@ impl CustomEvent { CustomEventBinding::Wrap) } pub fn new(global: GlobalRef, - type_: DOMString, + type_: Atom, bubbles: bool, cancelable: bool, detail: HandleValue) -> Root<CustomEvent> { let ev = CustomEvent::new_uninitialized(global); - ev.InitCustomEvent(global.get_cx(), type_, bubbles, cancelable, detail); + ev.init_custom_event(global.get_cx(), type_, bubbles, cancelable, detail); ev } #[allow(unsafe_code)] @@ -52,11 +53,26 @@ impl CustomEvent { init: &CustomEventBinding::CustomEventInit) -> Fallible<Root<CustomEvent>> { Ok(CustomEvent::new(global, - type_, + Atom::from(&*type_), init.parent.bubbles, init.parent.cancelable, unsafe { HandleValue::from_marked_location(&init.detail) })) } + + fn init_custom_event(&self, + _cx: *mut JSContext, + type_: Atom, + can_bubble: bool, + cancelable: bool, + detail: HandleValue) { + let event = self.upcast::<Event>(); + if event.dispatching() { + return; + } + + self.detail.set(detail.get()); + event.init_event(type_, can_bubble, cancelable); + } } impl CustomEventMethods for CustomEvent { @@ -72,12 +88,6 @@ impl CustomEventMethods for CustomEvent { can_bubble: bool, cancelable: bool, detail: HandleValue) { - let event = self.upcast::<Event>(); - if event.dispatching() { - return; - } - - self.detail.set(detail.get()); - event.InitEvent(type_, can_bubble, cancelable); + self.init_custom_event(_cx, Atom::from(&*type_), can_bubble, cancelable, detail) } } |