Match forwarded events as atoms, fixes #7495

This commit is contained in:
Aidan Hobson Sayers 2015-09-14 14:16:33 +01:00
parent 97710f0739
commit d1fcbca3b1

View file

@ -140,21 +140,19 @@ impl VirtualMethods for HTMLBodyElement {
}); });
}, },
(name, AttributeMutation::Set(_)) if name.starts_with("on") => { (name, AttributeMutation::Set(_)) if name.starts_with("on") => {
static FORWARDED_EVENTS: &'static [&'static str] =
&["onfocus", "onload", "onscroll", "onafterprint", "onbeforeprint",
"onbeforeunload", "onhashchange", "onlanguagechange", "onmessage",
"onoffline", "ononline", "onpagehide", "onpageshow", "onpopstate",
"onstorage", "onresize", "onunload", "onerror"];
let window = window_from_node(self); let window = window_from_node(self);
let (cx, url, reflector) = (window.get_cx(), let (cx, url, reflector) = (window.get_cx(),
window.get_url(), window.get_url(),
window.reflector().get_jsobject()); window.reflector().get_jsobject());
let evtarget = let evtarget = match name {
if FORWARDED_EVENTS.iter().any(|&event| &**name == event) { &atom!(onfocus) | &atom!(onload) | &atom!(onscroll) | &atom!(onafterprint) |
EventTargetCast::from_ref(window.r()) &atom!(onbeforeprint) | &atom!(onbeforeunload) | &atom!(onhashchange) |
} else { &atom!(onlanguagechange) | &atom!(onmessage) | &atom!(onoffline) | &atom!(ononline) |
EventTargetCast::from_ref(self) &atom!(onpagehide) | &atom!(onpageshow) | &atom!(onpopstate) | &atom!(onstorage) |
}; &atom!(onresize) | &atom!(onunload) | &atom!(onerror)
=> EventTargetCast::from_ref(window.r()), // forwarded event
_ => EventTargetCast::from_ref(self),
};
evtarget.set_event_handler_uncompiled(cx, url, reflector, evtarget.set_event_handler_uncompiled(cx, url, reflector,
&name[2..], &name[2..],
(**attr.value()).to_owned()); (**attr.value()).to_owned());