diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 20 | ||||
-rw-r--r-- | components/script/dom/element.rs | 30 | ||||
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 7 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 12 | ||||
-rw-r--r-- | components/script/dom/htmlimageelement.rs | 5 | ||||
-rw-r--r-- | components/script/dom/node.rs | 26 | ||||
-rw-r--r-- | components/script/dom/servoparser/mod.rs | 5 | ||||
-rw-r--r-- | components/script/dom/treewalker.rs | 10 | ||||
-rw-r--r-- | components/script/dom/window.rs | 24 |
9 files changed, 42 insertions, 97 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 731b89a26cb..7852111b23f 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2072,10 +2072,9 @@ fn get_registrable_domain_suffix_of_or_is_equal_to(host_suffix_string: &str, ori }; // Step 4.2 - let (prefix, suffix) = match original_host.len().checked_sub(host.len()) { - Some(index) => original_host.split_at(index), - None => return None, - }; + let index = original_host.len().checked_sub(host.len())?; + let (prefix, suffix) = original_host.split_at(index); + if !prefix.ends_with(".") { return None; } @@ -2319,11 +2318,7 @@ impl Document { /// /// Also, shouldn't return an option, I'm quite sure. pub fn device(&self) -> Option<Device> { - let window_size = match self.window().window_size() { - Some(ws) => ws, - None => return None, - }; - + let window_size = self.window().window_size()?; let viewport_size = window_size.initial_viewport; let device_pixel_ratio = window_size.device_pixel_ratio; Some(Device::new(MediaType::screen(), viewport_size, device_pixel_ratio)) @@ -4017,12 +4012,9 @@ impl PendingInOrderScriptVec { fn take_next_ready_to_be_executed(&self) -> Option<(DomRoot<HTMLScriptElement>, ScriptResult)> { let mut scripts = self.scripts.borrow_mut(); - let pair = scripts.front_mut().and_then(PendingScript::take_result); - if pair.is_none() { - return None; - } + let pair = scripts.front_mut()?.take_result()?; scripts.pop_front(); - pair + Some(pair) } fn clear(&self) { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 0ca6a0e7e2e..57a18db3056 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1039,24 +1039,20 @@ impl Element { // https://dom.spec.whatwg.org/#locate-a-namespace-prefix pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> { for node in self.upcast::<Node>().inclusive_ancestors() { - match node.downcast::<Element>() { - Some(element) => { - // Step 1. - if *element.namespace() == namespace { - if let Some(prefix) = element.GetPrefix() { - return Some(prefix); - } - } + let element = node.downcast::<Element>()?; + // Step 1. + if *element.namespace() == namespace { + if let Some(prefix) = element.GetPrefix() { + return Some(prefix); + } + } - // Step 2. - for attr in element.attrs.borrow().iter() { - if attr.prefix() == Some(&namespace_prefix!("xmlns")) && - **attr.value() == *namespace { - return Some(attr.LocalName()); - } - } - }, - None => return None, + // Step 2. + for attr in element.attrs.borrow().iter() { + if attr.prefix() == Some(&namespace_prefix!("xmlns")) && + **attr.value() == *namespace { + return Some(attr.LocalName()); + } } } None diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 3e7de52fd29..a44c1fd1fa5 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -219,12 +219,7 @@ impl HTMLCanvasElement { let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender)); context.get_ipc_renderer().send(msg).unwrap(); - match receiver.recv().unwrap() { - Some(pixels) => pixels, - None => { - return None; - } - } + receiver.recv().unwrap()? }, Some(&CanvasContext::WebGL(_)) => { // TODO: add a method in WebGLRenderingContext to get the pixels. diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 64bd9926ca3..c1ec4a7435b 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -588,17 +588,13 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { // https://html.spec.whatwg.org/multipage/#concept-bcc-content-document fn GetContentDocument(&self) -> Option<DomRoot<Document>> { // Step 1. - let pipeline_id = match self.pipeline_id.get() { - None => return None, - Some(pipeline_id) => pipeline_id, - }; + let pipeline_id = self.pipeline_id.get()?; + // Step 2-3. // Note that this lookup will fail if the document is dissimilar-origin, // so we should return None in that case. - let document = match ScriptThread::find_document(pipeline_id) { - None => return None, - Some(document) => document, - }; + let document = ScriptThread::find_document(pipeline_id)?; + // Step 4. let current = GlobalScope::current().expect("No current global object").as_window().Document(); if !current.origin().same_origin_domain(document.origin()) { diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 498930624c4..39fb44ba224 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -661,10 +661,7 @@ impl HTMLImageElement { } pub fn areas(&self) -> Option<Vec<DomRoot<HTMLAreaElement>>> { let elem = self.upcast::<Element>(); - let usemap_attr = match elem.get_attribute(&ns!(), &local_name!("usemap")) { - Some(attr) => attr, - None => return None, - }; + let usemap_attr = elem.get_attribute(&ns!(), &local_name!("usemap"))?; let value = usemap_attr.value(); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 2e05eb30971..8f29298a496 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1206,11 +1206,7 @@ pub struct FollowingNodeIterator { impl FollowingNodeIterator { /// Skips iterating the children of the current node pub fn next_skipping_children(&mut self) -> Option<DomRoot<Node>> { - let current = match self.current.take() { - None => return None, - Some(current) => current, - }; - + let current = self.current.take()?; self.next_skipping_children_impl(current) } @@ -1244,10 +1240,7 @@ impl Iterator for FollowingNodeIterator { // https://dom.spec.whatwg.org/#concept-tree-following fn next(&mut self) -> Option<DomRoot<Node>> { - let current = match self.current.take() { - None => return None, - Some(current) => current, - }; + let current = self.current.take()?; if let Some(first_child) = current.GetFirstChild() { self.current = Some(first_child); @@ -1268,10 +1261,7 @@ impl Iterator for PrecedingNodeIterator { // https://dom.spec.whatwg.org/#concept-tree-preceding fn next(&mut self) -> Option<DomRoot<Node>> { - let current = match self.current.take() { - None => return None, - Some(current) => current, - }; + let current = self.current.take()?; self.current = if self.root == current { None @@ -1323,10 +1313,7 @@ impl TreeIterator { } pub fn next_skipping_children(&mut self) -> Option<DomRoot<Node>> { - let current = match self.current.take() { - None => return None, - Some(current) => current, - }; + let current = self.current.take()?; self.next_skipping_children_impl(current) } @@ -1353,10 +1340,7 @@ impl Iterator for TreeIterator { // https://dom.spec.whatwg.org/#concept-tree-order fn next(&mut self) -> Option<DomRoot<Node>> { - let current = match self.current.take() { - None => return None, - Some(current) => current, - }; + let current = self.current.take()?; if let Some(first_child) = current.GetFirstChild() { self.current = Some(first_child); self.depth += 1; diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index 08310326716..8f84ed5b721 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -480,10 +480,7 @@ impl<I> Iterator for FragmentParsingResult<I> type Item = DomRoot<Node>; fn next(&mut self) -> Option<DomRoot<Node>> { - let next = match self.inner.next() { - Some(next) => next, - None => return None, - }; + let next = self.inner.next()?; next.remove_self(); Some(next) } diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index de5219a608f..a11432a5d69 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -395,13 +395,9 @@ impl TreeWalker { None => { let mut candidate = DomRoot::from_ref(node); while !self.is_root_node(&candidate) && candidate.GetNextSibling().is_none() { - match candidate.GetParentNode() { - None => - // This can happen if the user set the current node to somewhere - // outside of the tree rooted at the original root. - return None, - Some(n) => candidate = n - } + // This can return None if the user set the current node to somewhere + // outside of the tree rooted at the original root. + candidate = candidate.GetParentNode()?; } if self.is_root_node(&candidate) { None diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 422abd7079e..58d463cc2a3 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -592,15 +592,11 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-frameelement fn GetFrameElement(&self) -> Option<DomRoot<Element>> { // Steps 1-3. - let window_proxy = match self.window_proxy.get() { - None => return None, - Some(window_proxy) => window_proxy, - }; + let window_proxy = self.window_proxy.get()?; + // Step 4-5. - let container = match window_proxy.frame_element() { - None => return None, - Some(container) => container, - }; + let container = window_proxy.frame_element()?; + // Step 6. let container_doc = document_from_node(container); let current_doc = GlobalScope::current().expect("No current global object").as_window().Document(); @@ -688,10 +684,8 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-parent fn GetParent(&self) -> Option<DomRoot<WindowProxy>> { // Steps 1-3. - let window_proxy = match self.undiscarded_window_proxy() { - Some(window_proxy) => window_proxy, - None => return None, - }; + let window_proxy = self.undiscarded_window_proxy()?; + // Step 4. if let Some(parent) = window_proxy.parent() { return Some(DomRoot::from_ref(parent)); @@ -703,10 +697,8 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-top fn GetTop(&self) -> Option<DomRoot<WindowProxy>> { // Steps 1-3. - let window_proxy = match self.undiscarded_window_proxy() { - Some(window_proxy) => window_proxy, - None => return None, - }; + let window_proxy = self.undiscarded_window_proxy()?; + // Steps 4-5. Some(DomRoot::from_ref(window_proxy.top())) } |