diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-05-15 03:35:37 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-05-15 03:35:37 -0500 |
commit | 65c30224a1d3ca81d0b8a8d46538af91f07dfebf (patch) | |
tree | d17cebc44d4924b7d18020ce8a9969bf4b2a7ebb /components/script/dom | |
parent | 09f5648153d9817aa4c89153030f69bf45ee7283 (diff) | |
parent | 3c56c58e38581a71db1eb3e8dea360bd404738f1 (diff) | |
download | servo-65c30224a1d3ca81d0b8a8d46538af91f07dfebf.tar.gz servo-65c30224a1d3ca81d0b8a8d46538af91f07dfebf.zip |
Auto merge of #6043 - mukilan:get_root_element, r=Ms2ger
The [current implementation](http://mxr.mozilla.org/servo/source/components/script/dom/element.rs#666) is wrong as it always tries to cast the furthest ancestor into an element.
When the method is invoked on an element that is in the document tree, this will be the `Document` node, which is not an element. The ```last().map(ElementCast::to_temporary)``` returns Some(None) hence the method will return ```None```, while the correct behaviour is to return the ```html``` node.
This PR interprets the line ```"furthest ancestor element node of whatever node is being discussed"``` in the spec to mean ```"find the furthest ancestor that is an element node"```.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6043)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/element.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index f6e34985f5c..f0ff55e2e5b 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -510,7 +510,7 @@ pub trait ElementHelpers<'a> { fn get_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>; fn get_important_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>; fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>; - fn get_root_element(self) -> Option<Temporary<Element>>; + fn get_root_element(self) -> Temporary<Element>; fn lookup_prefix(self, namespace: Option<DOMString>) -> Option<DOMString>; } @@ -663,12 +663,12 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { } // https://html.spec.whatwg.org/multipage/#root-element - fn get_root_element(self) -> Option<Temporary<Element>> { + fn get_root_element(self) -> Temporary<Element> { let node: JSRef<Node> = NodeCast::from_ref(self); - match node.ancestors().last().map(ElementCast::to_temporary) { - Some(n) => n, - None => Some(self).map(Temporary::from_rooted), - } + node.inclusive_ancestors() + .filter_map(ElementCast::to_temporary) + .last() + .expect("We know inclusive_ancestors will return `self` which is an element") } // https://dom.spec.whatwg.org/#locate-a-namespace-prefix |