diff --git a/components/script/page.rs b/components/script/page.rs index c8e46463077..a99f1b37c03 100644 --- a/components/script/page.rs +++ b/components/script/page.rs @@ -434,11 +434,10 @@ impl Page { pub fn hit_test(&self, point: &Point2D) -> Option { let frame = self.frame(); let document = frame.as_ref().unwrap().document.root(); - let root = document.GetDocumentElement().root(); - if root.is_none() { - return None; - } - let root = root.unwrap(); + let root = match document.GetDocumentElement().root() { + None => return None, + Some(root) => root, + }; let root: JSRef = NodeCast::from_ref(*root); let address = match self.layout().hit_test(root.to_trusted_node_address(), *point) { Ok(HitTestResponse(node_address)) => { @@ -455,11 +454,10 @@ impl Page { pub fn get_nodes_under_mouse(&self, point: &Point2D) -> Option> { let frame = self.frame(); let document = frame.as_ref().unwrap().document.root(); - let root = document.GetDocumentElement().root(); - if root.is_none() { - return None; - } - let root = root.unwrap(); + let root = match document.GetDocumentElement().root() { + None => return None, + Some(root) => root, + }; let root: JSRef = NodeCast::from_ref(*root); let address = match self.layout().mouse_over(root.to_trusted_node_address(), *point) { Ok(MouseOverResponse(node_address)) => {