Auto merge of #9137 - iszak:issue-9135, r=nox

Fixes https://github.com/servo/servo/issues/9135

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9137)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-01-03 11:33:00 +05:30
commit 4a141fb63f

View file

@ -12,6 +12,7 @@ use dom::attr::AttrValue;
use dom::attr::{Attr, AttrHelpersForLayout}; use dom::attr::{Attr, AttrHelpersForLayout};
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding; use dom::bindings::codegen::Bindings::ElementBinding;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
@ -772,12 +773,19 @@ impl Element {
// https://html.spec.whatwg.org/multipage/#root-element // https://html.spec.whatwg.org/multipage/#root-element
pub fn get_root_element(&self) -> Root<Element> { pub fn get_root_element(&self) -> Root<Element> {
if self.node.is_in_doc() {
self.upcast::<Node>()
.owner_doc()
.GetDocumentElement()
.unwrap()
} else {
self.upcast::<Node>() self.upcast::<Node>()
.inclusive_ancestors() .inclusive_ancestors()
.filter_map(Root::downcast) .filter_map(Root::downcast)
.last() .last()
.expect("We know inclusive_ancestors will return `self` which is an element") .expect("We know inclusive_ancestors will return `self` which is an element")
} }
}
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix // https://dom.spec.whatwg.org/#locate-a-namespace-prefix
pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> { pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> {