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

Only compile applicable event handler content attributes #25274

Closed
wants to merge 6 commits into from

Use new shiny statics for element/body mutation

  • Loading branch information
Manishearth committed Dec 13, 2019
commit b68057d3c3bd82d842076929f910722a46b1d26c
@@ -183,48 +183,27 @@ impl VirtualMethods for HTMLBodyElement {
}

fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
let do_super_mutate = match (attr.local_name(), mutation) {
use crate::dom::macros::BODY_FRAMESET_EVENT_HANDLERS;
match (attr.local_name(), mutation) {
(name, AttributeMutation::Set(_)) if name.starts_with("on") => {
let window = window_from_node(self);
// https://html.spec.whatwg.org/multipage/
// #event-handlers-on-elements,-document-objects,-and-window-objects:event-handlers-3
match name {
&local_name!("onfocus") |
&local_name!("onload") |
&local_name!("onscroll") |
&local_name!("onafterprint") |
&local_name!("onbeforeprint") |
&local_name!("onbeforeunload") |
&local_name!("onhashchange") |
&local_name!("onlanguagechange") |
&local_name!("onmessage") |
&local_name!("onoffline") |
&local_name!("ononline") |
&local_name!("onpagehide") |
&local_name!("onpageshow") |
&local_name!("onpopstate") |
&local_name!("onstorage") |
&local_name!("onresize") |
&local_name!("onunload") |
&local_name!("onerror") => {
let evtarget = window.upcast::<EventTarget>(); // forwarded event
let source_line = 1; //TODO(#9604) obtain current JS execution line
evtarget.set_event_handler_uncompiled(
window.get_url(),
source_line,
&name[2..],
DOMString::from((**attr.value()).to_owned()),
);
false
},
_ => true, // HTMLElement::attribute_mutated will take care of this.
if BODY_FRAMESET_EVENT_HANDLERS.contains(name) {
let window = window_from_node(self);
let evtarget = window.upcast::<EventTarget>(); // forwarded event
let source_line = 1; //TODO(#9604) obtain current JS execution line
evtarget.set_event_handler_uncompiled(
window.get_url(),
source_line,
&name[2..],
DOMString::from((**attr.value()).to_owned()),
);
// No need to call supertype mutation checks; we're done
return;
}
},
_ => true,
_ => (),
};

if do_super_mutate {
self.super_type().unwrap().attribute_mutated(attr, mutation);
}
self.super_type().unwrap().attribute_mutated(attr, mutation);
}
}
@@ -723,21 +723,25 @@ impl VirtualMethods for HTMLElement {
}

fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
use crate::dom::macros::ELEMENT_EVENT_HANDLERS;
match (attr.local_name(), mutation) {
(name, AttributeMutation::Set(_)) if name.starts_with("on") => {
let evtarget = self.upcast::<EventTarget>();
let source_line = 1; //TODO(#9604) get current JS execution line
evtarget.set_event_handler_uncompiled(
window_from_node(self).get_url(),
source_line,
&name[2..],
// FIXME(ajeffrey): Convert directly from AttrValue to DOMString
DOMString::from(&**attr.value()),
);
if ELEMENT_EVENT_HANDLERS.contains(name) {
let evtarget = self.upcast::<EventTarget>();
let source_line = 1; //TODO(#9604) get current JS execution line
evtarget.set_event_handler_uncompiled(
window_from_node(self).get_url(),
source_line,
&name[2..],
// FIXME(ajeffrey): Convert directly from AttrValue to DOMString
DOMString::from(&**attr.value()),
);
// No need to call supertype mutation checks; we're done
}
},
_ => {},
}
self.super_type().unwrap().attribute_mutated(attr, mutation);
}

fn bind_to_tree(&self, context: &BindContext) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.