From 41395412eb724db393ff546cb232b5ffd5a651a4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 4 Dec 2014 09:43:40 +0100 Subject: [PATCH 1/4] Cleanup Document::GetDoctype. --- components/script/dom/document.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index c3c71cb5101..e5ecf461a6c 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -520,12 +520,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-doctype fn GetDoctype(self) -> Option> { let node: JSRef = NodeCast::from_ref(self); - node.children().find(|child| { - child.is_doctype() - }).map(|node| { - let doctype: JSRef = DocumentTypeCast::to_ref(node).unwrap(); - Temporary::from_rooted(doctype) - }) + node.children() + .filter_map(DocumentTypeCast::to_ref) + .next() + .map(Temporary::from_rooted) } // http://dom.spec.whatwg.org/#dom-document-documentelement From 2ce4c6c52971383e492cb1b4754f100874a2713e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 4 Dec 2014 09:44:01 +0100 Subject: [PATCH 2/4] Cleanup Document::GetDocumentElement. --- components/script/dom/document.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e5ecf461a6c..53c8e78e513 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -529,7 +529,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-documentelement fn GetDocumentElement(self) -> Option> { let node: JSRef = NodeCast::from_ref(self); - node.child_elements().next().map(|elem| Temporary::from_rooted(elem)) + node.child_elements().next().map(Temporary::from_rooted) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname From d22964792adce78cc166de3528d0ef3bff5f7d1a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 4 Dec 2014 11:38:54 +0100 Subject: [PATCH 3/4] Cleanup Document::SetBody. --- components/script/dom/document.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 53c8e78e513..f7cd7f9435e 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -821,21 +821,21 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body fn SetBody(self, new_body: Option>) -> ErrorResult { // Step 1. - match new_body { - Some(ref htmlelem) => { - let node: JSRef = NodeCast::from_ref(*htmlelem); - match node.type_id() { - ElementNodeTypeId(HTMLBodyElementTypeId) | ElementNodeTypeId(HTMLFrameSetElementTypeId) => {} - _ => return Err(HierarchyRequest) - } - } - None => return Err(HierarchyRequest) + let new_body = match new_body { + Some(new_body) => new_body, + None => return Err(HierarchyRequest), + }; + + let node: JSRef = NodeCast::from_ref(new_body); + match node.type_id() { + ElementNodeTypeId(HTMLBodyElementTypeId) | + ElementNodeTypeId(HTMLFrameSetElementTypeId) => {} + _ => return Err(HierarchyRequest) } // Step 2. let old_body = self.GetBody().root(); - //FIXME: covariant lifetime workaround. do not judge. - if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { + if old_body.as_ref().map(|body| **body) == Some(new_body) { return Ok(()); } @@ -844,8 +844,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // Step 4. None => return Err(HierarchyRequest), Some(ref root) => { - let new_body_unwrapped = new_body.unwrap(); - let new_body: JSRef = NodeCast::from_ref(new_body_unwrapped); + let new_body: JSRef = NodeCast::from_ref(new_body); let root: JSRef = NodeCast::from_ref(**root); match old_body { From 9416e9b11a33a3f9728e19565203919e1088264b Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 4 Dec 2014 11:40:44 +0100 Subject: [PATCH 4/4] Cleanup Document::GetElementsByName. --- components/script/dom/document.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index f7cd7f9435e..726e7e69516 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -863,11 +863,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname fn GetElementsByName(self, name: DOMString) -> Temporary { self.createNodeList(|node| { - if !node.is_element() { - return false; - } - - let element: JSRef = ElementCast::to_ref(node).unwrap(); + let element: JSRef = match ElementCast::to_ref(node) { + Some(element) => element, + None => return false, + }; element.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| { attr.value().as_slice() == name.as_slice() })