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.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index f7208237cc1..a0c099769f0 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -70,6 +70,15 @@ pub struct Temporary<T> {
_js_ptr: *mut JSObject,
}
+impl<T> Clone for Temporary<T> {
+ fn clone(&self) -> Temporary<T> {
+ Temporary {
+ inner: self.inner,
+ _js_ptr: self._js_ptr,
+ }
+ }
+}
+
impl<T> PartialEq for Temporary<T> {
fn eq(&self, other: &Temporary<T>) -> bool {
self.inner == other.inner
@@ -92,10 +101,12 @@ impl<T: Reflectable> Temporary<T> {
/// Create a stack-bounded root for this value.
pub fn root(self) -> Root<T> {
- let collection = StackRoots.get().unwrap();
- unsafe {
- Root::new(&**collection, &self.inner)
- }
+ StackRoots.with(|ref collection| {
+ let RootCollectionPtr(collection) = collection.get().unwrap();
+ unsafe {
+ Root::new(&*collection, &self.inner)
+ }
+ })
}
unsafe fn inner(&self) -> JS<T> {
@@ -114,6 +125,8 @@ pub struct JS<T> {
ptr: *const T
}
+impl<T> Copy for JS<T> {}
+
impl<T> PartialEq for JS<T> {
#[allow(unrooted_must_root)]
fn eq(&self, other: &JS<T>) -> bool {
@@ -151,10 +164,12 @@ impl<T: Reflectable> JS<T> {
/// Root this JS-owned value to prevent its collection as garbage.
pub fn root(&self) -> Root<T> {
- let collection = StackRoots.get().unwrap();
- unsafe {
- Root::new(&**collection, self)
- }
+ StackRoots.with(|ref collection| {
+ let RootCollectionPtr(collection) = collection.get().unwrap();
+ unsafe {
+ Root::new(&*collection, self)
+ }
+ })
}
}
@@ -270,7 +285,7 @@ impl<T: Reflectable> MutNullableJS<T> {
Some(inner) => inner,
None => {
let inner = cb();
- self.assign(Some(inner));
+ self.assign(Some(inner.clone()));
inner
},
}
@@ -450,6 +465,10 @@ pub struct RootCollection {
roots: UnsafeCell<SmallVec16<*mut JSObject>>,
}
+pub struct RootCollectionPtr(pub *const RootCollection);
+
+impl Copy for RootCollectionPtr {}
+
impl RootCollection {
/// Create an empty collection of roots
pub fn new() -> RootCollection {
@@ -548,6 +567,8 @@ pub struct JSRef<'a, T> {
chain: ContravariantLifetime<'a>,
}
+impl<'a, T> Copy for JSRef<'a, T> {}
+
impl<'a, T> Clone for JSRef<'a, T> {
fn clone(&self) -> JSRef<'a, T> {
JSRef {