aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/js.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/js.rs')
-rw-r--r--components/script/dom/bindings/js.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index a7ecc975129..1fd127b3b28 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
@@ -269,6 +270,12 @@ impl MutHeapJSVal {
debug_assert!(thread_state::get().is_script());
unsafe { (*self.val.get()).get() }
}
+
+ /// Get the underlying unsafe pointer to the contained value.
+ pub unsafe fn get_unsafe(&self) -> *mut JSVal {
+ debug_assert!(thread_state::get().is_script());
+ (*self.val.get()).get_unsafe()
+ }
}
@@ -439,6 +446,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 +465,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())