diff options
author | Arseniy Ivanov <freeatnet@freeatnet.com> | 2017-02-03 13:13:20 -0500 |
---|---|---|
committer | Arseniy Ivanov <freeatnet@freeatnet.com> | 2017-02-03 13:23:36 -0500 |
commit | 1bd1bddacffc5fc52f7a74396474f2ab36c57ad5 (patch) | |
tree | a6134e086c14df36747abe130f7b4886d71618f8 /components/script/dom/htmlelement.rs | |
parent | 60679d9b6d2d3787468c7dd0c271ab357ed8baee (diff) | |
download | servo-1bd1bddacffc5fc52f7a74396474f2ab36c57ad5.tar.gz servo-1bd1bddacffc5fc52f7a74396474f2ab36c57ad5.zip |
Extend window presence checks to non-native event handlers
Diffstat (limited to 'components/script/dom/htmlelement.rs')
-rw-r--r-- | components/script/dom/htmlelement.rs | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 6725fdb5dfb..0995c9cb54c 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -151,7 +151,11 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onload fn GetOnload(&self) -> Option<Rc<EventHandlerNonNull>> { if self.is_body_or_frameset() { - window_from_node(self).GetOnload() + if document_from_node(self).has_browsing_context() { + window_from_node(self).GetOnload() + } else { + None + } } else { self.upcast::<EventTarget>().get_event_handler_common("load") } @@ -160,7 +164,9 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onload fn SetOnload(&self, listener: Option<Rc<EventHandlerNonNull>>) { if self.is_body_or_frameset() { - window_from_node(self).SetOnload(listener) + if document_from_node(self).has_browsing_context() { + window_from_node(self).SetOnload(listener) + } } else { self.upcast::<EventTarget>().set_event_handler_common("load", listener) } @@ -169,7 +175,11 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onresize fn GetOnresize(&self) -> Option<Rc<EventHandlerNonNull>> { if self.is_body_or_frameset() { - window_from_node(self).GetOnload() + if document_from_node(self).has_browsing_context() { + window_from_node(self).GetOnload() + } else { + None + } } else { self.upcast::<EventTarget>().get_event_handler_common("resize") } @@ -178,7 +188,9 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onresize fn SetOnresize(&self, listener: Option<Rc<EventHandlerNonNull>>) { if self.is_body_or_frameset() { - window_from_node(self).SetOnresize(listener); + if document_from_node(self).has_browsing_context() { + window_from_node(self).SetOnresize(listener); + } } else { self.upcast::<EventTarget>().set_event_handler_common("resize", listener) } @@ -187,7 +199,11 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onblur fn GetOnblur(&self) -> Option<Rc<EventHandlerNonNull>> { if self.is_body_or_frameset() { - window_from_node(self).GetOnblur() + if document_from_node(self).has_browsing_context() { + window_from_node(self).GetOnblur() + } else { + None + } } else { self.upcast::<EventTarget>().get_event_handler_common("blur") } @@ -196,7 +212,9 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onblur fn SetOnblur(&self, listener: Option<Rc<EventHandlerNonNull>>) { if self.is_body_or_frameset() { - window_from_node(self).SetOnblur(listener) + if document_from_node(self).has_browsing_context() { + window_from_node(self).SetOnblur(listener) + } } else { self.upcast::<EventTarget>().set_event_handler_common("blur", listener) } @@ -205,7 +223,11 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onfocus fn GetOnfocus(&self) -> Option<Rc<EventHandlerNonNull>> { if self.is_body_or_frameset() { - window_from_node(self).GetOnfocus() + if document_from_node(self).has_browsing_context() { + window_from_node(self).GetOnfocus() + } else { + None + } } else { self.upcast::<EventTarget>().get_event_handler_common("focus") } @@ -214,7 +236,9 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onfocus fn SetOnfocus(&self, listener: Option<Rc<EventHandlerNonNull>>) { if self.is_body_or_frameset() { - window_from_node(self).SetOnfocus(listener) + if document_from_node(self).has_browsing_context() { + window_from_node(self).SetOnfocus(listener) + } } else { self.upcast::<EventTarget>().set_event_handler_common("focus", listener) } @@ -223,7 +247,11 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onscroll fn GetOnscroll(&self) -> Option<Rc<EventHandlerNonNull>> { if self.is_body_or_frameset() { - window_from_node(self).GetOnscroll() + if document_from_node(self).has_browsing_context() { + window_from_node(self).GetOnscroll() + } else { + None + } } else { self.upcast::<EventTarget>().get_event_handler_common("scroll") } @@ -232,7 +260,9 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#handler-onscroll fn SetOnscroll(&self, listener: Option<Rc<EventHandlerNonNull>>) { if self.is_body_or_frameset() { - window_from_node(self).SetOnscroll(listener) + if document_from_node(self).has_browsing_context() { + window_from_node(self).SetOnscroll(listener) + } } else { self.upcast::<EventTarget>().set_event_handler_common("scroll", listener) } |