diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ad8e2355113..268b263fc41 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -543,15 +543,12 @@ impl Element { // https://html.spec.whatwg.org/multipage/#the-directionality pub fn directionality(&self) -> String { - if let Some(directionality) = self - .downcast::() + self.downcast::() .and_then(|html_element| html_element.directionality()) - { - directionality - } else { - let node = self.upcast::(); - node.parent_directionality() - } + .unwrap_or_else(|| { + let node = self.upcast::(); + node.parent_directionality() + }) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 50175ebccfc..a24a70648ea 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -438,21 +438,19 @@ impl Node { loop { match current { - Some(parent) => { - if let Some(directionality) = parent + Some(node) => { + if let Some(directionality) = node .downcast::() .and_then(|html_element| html_element.directionality()) { return directionality; } else { - current = parent.GetParentNode(); + current = node.GetParentNode(); } }, - None => break, + None => return "ltr".to_owned(), } } - - "ltr".to_owned() } }