diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/js.rs | 6 | ||||
-rw-r--r-- | components/script/dom/node.rs | 36 | ||||
-rw-r--r-- | components/script/dom/xmldocument.rs | 7 |
3 files changed, 20 insertions, 29 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 1736758e739..d171715d474 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -606,6 +606,12 @@ impl<T: Reflectable> PartialEq for Root<T> { } } +impl<T: Reflectable> Clone for Root<T> { + fn clone(&self) -> Root<T> { + Root::from_ref(&*self) + } +} + impl<T: Reflectable> Drop for Root<T> { fn drop(&mut self) { unsafe { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 99648369357..748b7b8249e 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1166,34 +1166,20 @@ impl Iterator for PrecedingNodeIterator { Some(current) => current, }; - if self.root == current { - self.current = None; - return None - } - - let node = current; - if let Some(previous_sibling) = node.GetPreviousSibling() { + self.current = if self.root == current { + None + } else if let Some(previous_sibling) = current.GetPreviousSibling() { if self.root == previous_sibling { - self.current = None; - return None - } - - if let Some(last_child) = previous_sibling.descending_last_children().last() { - self.current = Some(last_child); - return previous_sibling.descending_last_children().last() + None + } else if let Some(last_child) = previous_sibling.descending_last_children().last() { + Some(last_child) + } else { + Some(previous_sibling) } - - self.current = Some(previous_sibling); - return node.GetPreviousSibling() + } else { + current.GetParentNode() }; - - if let Some(parent_node) = node.GetParentNode() { - self.current = Some(parent_node); - return node.GetParentNode() - } - - self.current = None; - None + self.current.clone() } } diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 8f614a0442c..9d156682fa2 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -4,7 +4,6 @@ use document_loader::DocumentLoader; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods}; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; @@ -77,16 +76,16 @@ impl XMLDocument { impl XMLDocumentMethods for XMLDocument { // https://html.spec.whatwg.org/multipage/#dom-document-location fn GetLocation(&self) -> Option<Root<Location>> { - self.document.GetLocation() + self.upcast::<Document>().GetLocation() } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names fn SupportedPropertyNames(&self) -> Vec<DOMString> { - self.document.SupportedPropertyNames() + self.upcast::<Document>().SupportedPropertyNames() } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) -> *mut JSObject { - self.document.NamedGetter(_cx, name, found) + self.upcast::<Document>().NamedGetter(_cx, name, found) } } |