aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/eventtarget.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-16 10:16:44 -0800
committerGitHub <noreply@github.com>2017-01-16 10:16:44 -0800
commite891277dd5a52bc3a2b76dfd78da9b82b4c11b40 (patch)
treeda47fb84567db690b8c4649619cbe89b577c708d /components/script/dom/eventtarget.rs
parent44fa478d7bb87fea52ef4af78267738316f22587 (diff)
parent3f35c3eee22cb52de04dea764e529517f6bfef0d (diff)
downloadservo-e891277dd5a52bc3a2b76dfd78da9b82b4c11b40.tar.gz
servo-e891277dd5a52bc3a2b76dfd78da9b82b4c11b40.zip
Auto merge of #14994 - jdm:callback_rooting, r=Manishearth,Ms2ger
Make WebIDL callbacks permanently rooted This replicates the same model that Promise uses right now, because it requires less thinking than coming up with something else. - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14447 - [ ] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14994) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/eventtarget.rs')
-rw-r--r--components/script/dom/eventtarget.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs
index 09cafb65bac..1023b97600f 100644
--- a/components/script/dom/eventtarget.rs
+++ b/components/script/dom/eventtarget.rs
@@ -441,13 +441,13 @@ impl EventTarget {
assert!(!funobj.is_null());
// Step 1.14
if is_error {
- Some(CommonEventHandler::ErrorEventHandler(OnErrorEventHandlerNonNull::new(funobj)))
+ Some(CommonEventHandler::ErrorEventHandler(OnErrorEventHandlerNonNull::new(cx, funobj)))
} else {
if ty == &atom!("beforeunload") {
Some(CommonEventHandler::BeforeUnloadEventHandler(
- OnBeforeUnloadEventHandlerNonNull::new(funobj)))
+ OnBeforeUnloadEventHandlerNonNull::new(cx, funobj)))
} else {
- Some(CommonEventHandler::EventHandler(EventHandlerNonNull::new(funobj)))
+ Some(CommonEventHandler::EventHandler(EventHandlerNonNull::new(cx, funobj)))
}
}
}
@@ -455,36 +455,47 @@ impl EventTarget {
pub fn set_event_handler_common<T: CallbackContainer>(
&self, ty: &str, listener: Option<Rc<T>>)
{
+ let cx = self.global().get_cx();
+
let event_listener = listener.map(|listener|
InlineEventListener::Compiled(
CommonEventHandler::EventHandler(
- EventHandlerNonNull::new(listener.callback()))));
+ EventHandlerNonNull::new(cx, listener.callback()))));
self.set_inline_event_listener(Atom::from(ty), event_listener);
}
pub fn set_error_event_handler<T: CallbackContainer>(
&self, ty: &str, listener: Option<Rc<T>>)
{
+ let cx = self.global().get_cx();
+
let event_listener = listener.map(|listener|
InlineEventListener::Compiled(
CommonEventHandler::ErrorEventHandler(
- OnErrorEventHandlerNonNull::new(listener.callback()))));
+ OnErrorEventHandlerNonNull::new(cx, listener.callback()))));
self.set_inline_event_listener(Atom::from(ty), event_listener);
}
pub fn set_beforeunload_event_handler<T: CallbackContainer>(&self, ty: &str,
- listener: Option<Rc<T>>) {
+ listener: Option<Rc<T>>) {
+ let cx = self.global().get_cx();
+
let event_listener = listener.map(|listener|
InlineEventListener::Compiled(
CommonEventHandler::BeforeUnloadEventHandler(
- OnBeforeUnloadEventHandlerNonNull::new(listener.callback())))
+ OnBeforeUnloadEventHandlerNonNull::new(cx, listener.callback())))
);
self.set_inline_event_listener(Atom::from(ty), event_listener);
}
+ #[allow(unsafe_code)]
pub fn get_event_handler_common<T: CallbackContainer>(&self, ty: &str) -> Option<Rc<T>> {
+ let cx = self.global().get_cx();
let listener = self.get_inline_event_listener(&Atom::from(ty));
- listener.map(|listener| CallbackContainer::new(listener.parent().callback_holder().get()))
+ unsafe {
+ listener.map(|listener|
+ CallbackContainer::new(cx, listener.parent().callback_holder().get()))
+ }
}
pub fn has_handlers(&self) -> bool {