Cleanup Document::SetBody.

This commit is contained in:
Ms2ger 2014-12-04 11:38:54 +01:00
parent 2ce4c6c529
commit d22964792a

View file

@ -821,21 +821,21 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
fn SetBody(self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult { fn SetBody(self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult {
// Step 1. // Step 1.
match new_body { let new_body = match new_body {
Some(ref htmlelem) => { Some(new_body) => new_body,
let node: JSRef<Node> = NodeCast::from_ref(*htmlelem); None => return Err(HierarchyRequest),
match node.type_id() { };
ElementNodeTypeId(HTMLBodyElementTypeId) | ElementNodeTypeId(HTMLFrameSetElementTypeId) => {}
_ => return Err(HierarchyRequest) let node: JSRef<Node> = NodeCast::from_ref(new_body);
} match node.type_id() {
} ElementNodeTypeId(HTMLBodyElementTypeId) |
None => return Err(HierarchyRequest) ElementNodeTypeId(HTMLFrameSetElementTypeId) => {}
_ => return Err(HierarchyRequest)
} }
// Step 2. // Step 2.
let old_body = self.GetBody().root(); let old_body = self.GetBody().root();
//FIXME: covariant lifetime workaround. do not judge. if old_body.as_ref().map(|body| **body) == Some(new_body) {
if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) {
return Ok(()); return Ok(());
} }
@ -844,8 +844,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// Step 4. // Step 4.
None => return Err(HierarchyRequest), None => return Err(HierarchyRequest),
Some(ref root) => { Some(ref root) => {
let new_body_unwrapped = new_body.unwrap(); let new_body: JSRef<Node> = NodeCast::from_ref(new_body);
let new_body: JSRef<Node> = NodeCast::from_ref(new_body_unwrapped);
let root: JSRef<Node> = NodeCast::from_ref(**root); let root: JSRef<Node> = NodeCast::from_ref(**root);
match old_body { match old_body {