From 5e4d80fa3a291c77879c9798329410eb87b4a344 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 21 Mar 2015 17:46:30 -0400 Subject: [PATCH] Tidy up script::dom::document.SetBody There were a few things that were bothering me with `SetBody`: * The 'Step 3' comment is in the wrong place * The logic of 'Step 4' comes before 'Step 3' * 'Step 5' was not documented --- components/script/dom/document.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 10931e0dc5d..243951600e5 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1216,22 +1216,23 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { return Ok(()); } - // Step 3. - match self.get_html_element().root() { - // Step 4. - None => return Err(HierarchyRequest), - Some(ref root) => { - let new_body: JSRef = NodeCast::from_ref(new_body); - + match (self.get_html_element().root(), old_body) { + // Step 3. + (Some(ref root), Some(ref child)) => { let root: JSRef = NodeCast::from_ref(root.r()); - match old_body { - Some(ref child) => { - let child: JSRef = NodeCast::from_ref(child.r()); + let child: JSRef = NodeCast::from_ref(child.r()); + let new_body: JSRef = NodeCast::from_ref(new_body); + assert!(root.ReplaceChild(new_body, child).is_ok()) + }, - assert!(root.ReplaceChild(new_body, child).is_ok()) - } - None => assert!(root.AppendChild(new_body).is_ok()) - }; + // Step 4. + (None, _) => return Err(HierarchyRequest), + + // Step 5. + (Some(ref root), None) => { + let root: JSRef = NodeCast::from_ref(root.r()); + let new_body: JSRef = NodeCast::from_ref(new_body); + assert!(root.AppendChild(new_body).is_ok()); } } Ok(())