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

Throwing errors on event compilation, without panics and at least sometimes test-passingly #25249

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Enabling handler compile error events + #25249 + fix to 25249

  • Loading branch information
Manishearth authored and pshaughn committed Feb 15, 2020
commit 923435b6cc7ca3810143392531aa8f90c9c986b5
@@ -553,8 +553,8 @@ impl EventTarget {
// Step 3.7
unsafe {
let _ac = JSAutoRealm::new(*cx, self.reflector().get_jsobject().get());
// FIXME(#13152): dispatch error event.
report_pending_exception(*cx, false);
// FIXME(#13152): this might not be timed correctly
report_pending_exception(*cx, true);
}
return None;
}
@@ -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);
}
}
@@ -775,21 +775,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) {
@@ -2,13 +2,19 @@
* 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::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLFrameSetElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLFrameSetElementBinding::HTMLFrameSetElementMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::AttributeMutation;
use crate::dom::eventtarget::EventTarget;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::{document_from_node, Node};
use crate::dom::node::{document_from_node, window_from_node, Node};
use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};

@@ -48,3 +54,34 @@ impl HTMLFrameSetElementMethods for HTMLFrameSetElement {
// https://html.spec.whatwg.org/multipage/#windoweventhandlers
window_event_handlers!(ForwardToWindow);
}

impl VirtualMethods for HTMLFrameSetElement {
fn super_type(&self) -> Option<&dyn VirtualMethods> {
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
}

fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
use crate::dom::macros::BODY_FRAMESET_EVENT_HANDLERS;
match (attr.local_name(), mutation) {
(name, AttributeMutation::Set(_)) if name.starts_with("on") => {
// https://html.spec.whatwg.org/multipage/
// #event-handlers-on-elements,-document-objects,-and-window-objects:event-handlers-3
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;
}
},
_ => (),
};
self.super_type().unwrap().attribute_mutated(attr, mutation);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.