auto merge of #5307 : frewsxcv/servo/document-set-body, r=jdm

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
This commit is contained in:
bors-servo 2015-03-22 10:09:46 -06:00
commit 445f1c891a

View file

@ -1216,22 +1216,23 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
return Ok(()); return Ok(());
} }
// Step 3. match (self.get_html_element().root(), old_body) {
match self.get_html_element().root() { // Step 3.
// Step 4. (Some(ref root), Some(ref child)) => {
None => return Err(HierarchyRequest),
Some(ref root) => {
let new_body: JSRef<Node> = NodeCast::from_ref(new_body);
let root: JSRef<Node> = NodeCast::from_ref(root.r()); let root: JSRef<Node> = NodeCast::from_ref(root.r());
match old_body { let child: JSRef<Node> = NodeCast::from_ref(child.r());
Some(ref child) => { let new_body: JSRef<Node> = NodeCast::from_ref(new_body);
let child: JSRef<Node> = NodeCast::from_ref(child.r()); assert!(root.ReplaceChild(new_body, child).is_ok())
},
assert!(root.ReplaceChild(new_body, child).is_ok()) // Step 4.
} (None, _) => return Err(HierarchyRequest),
None => assert!(root.AppendChild(new_body).is_ok())
}; // Step 5.
(Some(ref root), None) => {
let root: JSRef<Node> = NodeCast::from_ref(root.r());
let new_body: JSRef<Node> = NodeCast::from_ref(new_body);
assert!(root.AppendChild(new_body).is_ok());
} }
} }
Ok(()) Ok(())