From a1091772ec9258d4e2c4184e07edab730e4d559c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 21 Jun 2016 19:35:36 -0400 Subject: Implement binding support for returning and accepting Promises in WebIDL. --- components/script/dom/bindings/js.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'components/script/dom/bindings/js.rs') diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index a7ecc975129..50cae7e1f04 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -43,6 +43,7 @@ use std::intrinsics::type_name; use std::mem; use std::ops::Deref; use std::ptr; +use std::rc::Rc; use style::thread_state; /// A traced reference to a DOM object @@ -439,6 +440,18 @@ impl LayoutJS { } } +/// Get an `&T` out of a `Rc` +pub trait RootedRcReference { + /// Obtain a safe reference to the wrapped non-JS owned value. + fn r(&self) -> &T; +} + +impl RootedRcReference for Rc { + fn r(&self) -> &T { + &*self + } +} + /// Get an `Option<&T>` out of an `Option>` pub trait RootedReference { /// Obtain a safe optional reference to the wrapped JS owned-value that @@ -446,6 +459,12 @@ pub trait RootedReference { fn r(&self) -> Option<&T>; } +impl RootedReference for Option> { + fn r(&self) -> Option<&T> { + self.as_ref().map(|root| &**root) + } +} + impl RootedReference for Option> { fn r(&self) -> Option<&T> { self.as_ref().map(|root| root.r()) -- cgit v1.2.3