implement "has event listener", plug into (before)unload

This commit is contained in:
Gregory Terzian 2018-04-27 13:35:53 +08:00
parent 427eaed535
commit 29d1cf6270
9 changed files with 66 additions and 56 deletions

View file

@ -277,6 +277,12 @@ impl EventListeners {
}
}).collect()
}
fn has_listeners(&self) -> bool {
// TODO: add, and take into account, a 'removed' field?
// https://dom.spec.whatwg.org/#event-listener-removed
self.0.len() > 0
}
}
#[dom_struct]
@ -303,6 +309,15 @@ impl EventTarget {
Ok(EventTarget::new(global))
}
pub fn has_listeners_for(&self,
type_: &Atom)
-> bool {
match self.handlers.borrow().get(type_) {
Some(listeners) => listeners.has_listeners(),
None => false
}
}
pub fn get_listeners_for(&self,
type_: &Atom,
specific_phase: Option<ListenerPhase>)