mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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
This commit is contained in:
parent
29a36adbe7
commit
5e4d80fa3a
1 changed files with 15 additions and 14 deletions
|
@ -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<Node> = NodeCast::from_ref(new_body);
|
||||
|
||||
match (self.get_html_element().root(), old_body) {
|
||||
// Step 3.
|
||||
(Some(ref root), Some(ref child)) => {
|
||||
let root: JSRef<Node> = NodeCast::from_ref(root.r());
|
||||
match old_body {
|
||||
Some(ref child) => {
|
||||
let child: JSRef<Node> = NodeCast::from_ref(child.r());
|
||||
let child: JSRef<Node> = NodeCast::from_ref(child.r());
|
||||
let new_body: JSRef<Node> = 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<Node> = NodeCast::from_ref(root.r());
|
||||
let new_body: JSRef<Node> = NodeCast::from_ref(new_body);
|
||||
assert!(root.AppendChild(new_body).is_ok());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue