diff options
author | Josh Matthews <josh@joshmatthews.net> | 2016-06-21 19:35:36 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2016-09-22 16:16:48 -0400 |
commit | a1091772ec9258d4e2c4184e07edab730e4d559c (patch) | |
tree | f9a92d79c1d844a288f64c20260dabe5675047a5 /components/script/dom/bindings/js.rs | |
parent | 73b296350927bad6d526cce21434ce68a75216fa (diff) | |
download | servo-a1091772ec9258d4e2c4184e07edab730e4d559c.tar.gz servo-a1091772ec9258d4e2c4184e07edab730e4d559c.zip |
Implement binding support for returning and accepting Promises in WebIDL.
Diffstat (limited to 'components/script/dom/bindings/js.rs')
-rw-r--r-- | components/script/dom/bindings/js.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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<T: Reflectable> LayoutJS<T> { } } +/// Get an `&T` out of a `Rc<T>` +pub trait RootedRcReference<T> { + /// Obtain a safe reference to the wrapped non-JS owned value. + fn r(&self) -> &T; +} + +impl<T: Reflectable> RootedRcReference<T> for Rc<T> { + fn r(&self) -> &T { + &*self + } +} + /// Get an `Option<&T>` out of an `Option<Root<T>>` pub trait RootedReference<T> { /// Obtain a safe optional reference to the wrapped JS owned-value that @@ -446,6 +459,12 @@ pub trait RootedReference<T> { fn r(&self) -> Option<&T>; } +impl<T: Reflectable> RootedReference<T> for Option<Rc<T>> { + fn r(&self) -> Option<&T> { + self.as_ref().map(|root| &**root) + } +} + impl<T: Reflectable> RootedReference<T> for Option<Root<T>> { fn r(&self) -> Option<&T> { self.as_ref().map(|root| root.r()) |