Skip to content

Commit

Permalink
Implement RootedReference<T> for Option<JS<T>>
Browse files Browse the repository at this point in the history
An implementation of RootedReference for Option<JS<T>> based off of
other implementations of RootedReference for Option wrapped types.
  • Loading branch information
dlrobertson committed Feb 16, 2016
1 parent f0d4c03 commit 7a35ef1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions components/script/dom/bindings/js.rs
Expand Up @@ -444,6 +444,13 @@ impl<T: Reflectable> RootedReference<T> for Option<Root<T>> {
}
}

/// Get an `Option<&T> out of an `Option<JS<T>>`
impl<T: Reflectable> RootedReference<T> for Option<JS<T>> {
fn r(&self) -> Option<&T> {
self.as_ref().map(|inner| &**inner)
}
}

/// Get an `Option<Option<&T>>` out of an `Option<Option<Root<T>>>`
pub trait OptionalRootedReference<T> {
/// Obtain a safe optional optional reference to the wrapped JS owned-value
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/browsingcontext.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlinputelement.rs
Expand Up @@ -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
Expand Down

0 comments on commit 7a35ef1

Please sign in to comment.