diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 37d673f3c267..1736758e7399 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -444,6 +444,13 @@ impl RootedReference for Option> { } } +/// Get an `Option<&T> out of an `Option>` +impl RootedReference for Option> { + fn r(&self) -> Option<&T> { + self.as_ref().map(|inner| &**inner) + } +} + /// Get an `Option>` out of an `Option>>` pub trait OptionalRootedReference { /// Obtain a safe optional optional reference to the wrapped JS owned-value diff --git a/components/script/dom/browsingcontext.rs b/components/script/dom/browsingcontext.rs index 51baa7ba08ed..7cd856cad7cf 100644 --- a/components/script/dom/browsingcontext.rs +++ b/components/script/dom/browsingcontext.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject}; -use dom::bindings::js::{JS, Root}; +use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; use dom::bindings::reflector::{Reflectable, Reflector}; use dom::bindings::utils::WindowProxyHandler; @@ -78,7 +78,7 @@ impl BrowsingContext { } pub fn frame_element(&self) -> Option<&Element> { - self.frame_element.as_ref().map(|element| &**element) + self.frame_element.r() } pub fn window_proxy(&self) -> *mut JSObject { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 639ca24225cb..b1941b0db1aa 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -812,7 +812,7 @@ impl Activatable for HTMLInputElement { // We want to restore state only if the element had been changed in the first place if cache.was_mutable { let name = self.get_radio_group_name(); - match cache.checked_radio.as_ref().map(|t| &*t) { + match cache.checked_radio.r() { Some(o) => { // Avoiding iterating through the whole tree here, instead // we can check if the conditions for radio group siblings apply