From 0d732ebb5f82b1b8b7c1556ac1b9a7af3a6eee62 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 11 Apr 2016 10:29:13 +0200 Subject: [PATCH 1/4] Implement Clone for Root. --- components/script/dom/bindings/js.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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 PartialEq for Root { } } +impl Clone for Root { + fn clone(&self) -> Root { + Root::from_ref(&*self) + } +} + impl Drop for Root { fn drop(&mut self) { unsafe { From 71f56d674497baa1dfc2eb97d23ea66a5adb9f9f Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 11 Apr 2016 10:29:32 +0200 Subject: [PATCH 2/4] Simplify PrecedingNodeIterator::next(). --- components/script/dom/node.rs | 36 +++++++++++------------------------ 1 file changed, 11 insertions(+), 25 deletions(-) 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 + None + } else if let Some(last_child) = previous_sibling.descending_last_children().last() { + Some(last_child) + } else { + Some(previous_sibling) } - - if let Some(last_child) = previous_sibling.descending_last_children().last() { - self.current = Some(last_child); - return previous_sibling.descending_last_children().last() - } - - 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() } } From 0633ca4144dd7a7f64df5ac604156a2c6ff439be Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 11 Apr 2016 10:29:51 +0200 Subject: [PATCH 3/4] Remove unused import from xmldocument. --- components/script/dom/xmldocument.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 8f614a0442c..aff37638603 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; From 3f95e4c8e13ac1253f662804229e3b37c85894b6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 11 Apr 2016 10:30:08 +0200 Subject: [PATCH 4/4] Use upcast() in XMLDocument methods. --- components/script/dom/xmldocument.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index aff37638603..9d156682fa2 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -76,16 +76,16 @@ impl XMLDocument { impl XMLDocumentMethods for XMLDocument { // https://html.spec.whatwg.org/multipage/#dom-document-location fn GetLocation(&self) -> Option> { - self.document.GetLocation() + self.upcast::().GetLocation() } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names fn SupportedPropertyNames(&self) -> Vec { - self.document.SupportedPropertyNames() + self.upcast::().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::().NamedGetter(_cx, name, found) } }