servo: Merge #10516 - Various cleanup (from Ms2ger:cleanup); r=nox
authorMs2ger <Ms2ger@gmail.com>
Mon, 11 Apr 2016 13:44:18 +0500
changeset 476639 989283b5ecb69d298781213c71854f995391d7dd
parent 476638 e81b35c89383c52211e04e53842f52f2dc125db4
child 476640 0a9be544718fa3a3f2043a08f286ae8359a65d1a
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersnox
servo: Merge #10516 - Various cleanup (from Ms2ger:cleanup); r=nox Source-Repo: https://github.com/servo/servo Source-Revision: 5adf36231e739f57dc7d1d85b37fb2a47b8f5d74
servo/components/script/dom/bindings/js.rs
servo/components/script/dom/node.rs
servo/components/script/dom/xmldocument.rs
--- a/servo/components/script/dom/bindings/js.rs
+++ b/servo/components/script/dom/bindings/js.rs
@@ -601,15 +601,21 @@ impl<T: Reflectable> Deref for Root<T> {
 }
 
 impl<T: Reflectable> PartialEq for Root<T> {
     fn eq(&self, other: &Root<T>) -> bool {
         self.ptr == other.ptr
     }
 }
 
+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 {
             (*self.root_list).unroot(self);
         }
     }
 }
--- a/servo/components/script/dom/node.rs
+++ b/servo/components/script/dom/node.rs
@@ -1161,44 +1161,30 @@ impl Iterator for PrecedingNodeIterator 
 
     // https://dom.spec.whatwg.org/#concept-tree-preceding
     fn next(&mut self) -> Option<Root<Node>> {
         let current = match self.current.take() {
             None => return None,
             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()
     }
 }
 
 pub struct LastChildIterator {
     current: Option<Root<Node>>,
 }
 
 impl Iterator for LastChildIterator {
--- a/servo/components/script/dom/xmldocument.rs
+++ b/servo/components/script/dom/xmldocument.rs
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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;
 use dom::bindings::js::{Root, RootedReference};
 use dom::bindings::reflector::{Reflectable, reflect_dom_object};
 use dom::browsingcontext::BrowsingContext;
 use dom::document::{Document, DocumentSource, IsHTMLDocument};
 use dom::location::Location;
@@ -72,21 +71,21 @@ impl XMLDocument {
         }
         doc
     }
 }
 
 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)
     }
 }