diff options
Diffstat (limited to 'components/script/dom/bindings/js.rs')
-rw-r--r-- | components/script/dom/bindings/js.rs | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index fa7999ebcb1..bdd2b81ce37 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -229,20 +229,6 @@ impl LayoutJS<Node> { } } - -/// A trait to be implemented for JS-managed types that can be stored in -/// mutable member fields. -/// -/// Do not implement this trait yourself. -pub trait HeapGCValue: JSTraceable { -} - -impl HeapGCValue for Heap<JSVal> { -} - -impl<T: DomObject> HeapGCValue for JS<T> { -} - /// A holder that provides interior mutability for GC-managed JSVals. /// /// Must be used in place of traditional interior mutability to ensure proper @@ -293,20 +279,20 @@ impl MutHeapJSVal { /// on `JS<T>`. #[must_root] #[derive(JSTraceable)] -pub struct MutHeap<T: HeapGCValue> { - val: UnsafeCell<T>, +pub struct MutJS<T: DomObject> { + val: UnsafeCell<JS<T>>, } -impl<T: DomObject> MutHeap<JS<T>> { - /// Create a new `MutHeap`. - pub fn new(initial: &T) -> MutHeap<JS<T>> { +impl<T: DomObject> MutJS<T> { + /// Create a new `MutJS`. + pub fn new(initial: &T) -> MutJS<T> { debug_assert!(thread_state::get().is_script()); - MutHeap { + MutJS { val: UnsafeCell::new(JS::from_ref(initial)), } } - /// Set this `MutHeap` to the given value. + /// Set this `MutJS` to the given value. pub fn set(&self, val: &T) { debug_assert!(thread_state::get().is_script()); unsafe { @@ -314,7 +300,7 @@ impl<T: DomObject> MutHeap<JS<T>> { } } - /// Get the value in this `MutHeap`. + /// Get the value in this `MutJS`. pub fn get(&self) -> Root<T> { debug_assert!(thread_state::get().is_script()); unsafe { @@ -323,14 +309,14 @@ impl<T: DomObject> MutHeap<JS<T>> { } } -impl<T: HeapGCValue> HeapSizeOf for MutHeap<T> { +impl<T: DomObject> HeapSizeOf for MutJS<T> { fn heap_size_of_children(&self) -> usize { // See comment on HeapSizeOf for JS<T>. 0 } } -impl<T: DomObject> PartialEq for MutHeap<JS<T>> { +impl<T: DomObject> PartialEq for MutJS<T> { fn eq(&self, other: &Self) -> bool { unsafe { *self.val.get() == *other.val.get() @@ -338,7 +324,7 @@ impl<T: DomObject> PartialEq for MutHeap<JS<T>> { } } -impl<T: DomObject + PartialEq> PartialEq<T> for MutHeap<JS<T>> { +impl<T: DomObject + PartialEq> PartialEq<T> for MutJS<T> { fn eq(&self, other: &T) -> bool { unsafe { **self.val.get() == *other @@ -354,15 +340,15 @@ impl<T: DomObject + PartialEq> PartialEq<T> for MutHeap<JS<T>> { /// on `JS<T>`. #[must_root] #[derive(JSTraceable)] -pub struct MutNullableHeap<T: HeapGCValue> { - ptr: UnsafeCell<Option<T>>, +pub struct MutNullableJS<T: DomObject> { + ptr: UnsafeCell<Option<JS<T>>>, } -impl<T: DomObject> MutNullableHeap<JS<T>> { - /// Create a new `MutNullableHeap`. - pub fn new(initial: Option<&T>) -> MutNullableHeap<JS<T>> { +impl<T: DomObject> MutNullableJS<T> { + /// Create a new `MutNullableJS`. + pub fn new(initial: Option<&T>) -> MutNullableJS<T> { debug_assert!(thread_state::get().is_script()); - MutNullableHeap { + MutNullableJS { ptr: UnsafeCell::new(initial.map(JS::from_ref)), } } @@ -400,7 +386,7 @@ impl<T: DomObject> MutNullableHeap<JS<T>> { } } - /// Set this `MutNullableHeap` to the given value. + /// Set this `MutNullableJS` to the given value. pub fn set(&self, val: Option<&T>) { debug_assert!(thread_state::get().is_script()); unsafe { @@ -416,7 +402,7 @@ impl<T: DomObject> MutNullableHeap<JS<T>> { } } -impl<T: DomObject> PartialEq for MutNullableHeap<JS<T>> { +impl<T: DomObject> PartialEq for MutNullableJS<T> { fn eq(&self, other: &Self) -> bool { unsafe { *self.ptr.get() == *other.ptr.get() @@ -424,7 +410,7 @@ impl<T: DomObject> PartialEq for MutNullableHeap<JS<T>> { } } -impl<'a, T: DomObject> PartialEq<Option<&'a T>> for MutNullableHeap<JS<T>> { +impl<'a, T: DomObject> PartialEq<Option<&'a T>> for MutNullableJS<T> { fn eq(&self, other: &Option<&T>) -> bool { unsafe { *self.ptr.get() == other.map(JS::from_ref) @@ -432,17 +418,17 @@ impl<'a, T: DomObject> PartialEq<Option<&'a T>> for MutNullableHeap<JS<T>> { } } -impl<T: HeapGCValue> Default for MutNullableHeap<T> { +impl<T: DomObject> Default for MutNullableJS<T> { #[allow(unrooted_must_root)] - fn default() -> MutNullableHeap<T> { + fn default() -> MutNullableJS<T> { debug_assert!(thread_state::get().is_script()); - MutNullableHeap { + MutNullableJS { ptr: UnsafeCell::new(None), } } } -impl<T: HeapGCValue> HeapSizeOf for MutNullableHeap<T> { +impl<T: DomObject> HeapSizeOf for MutNullableJS<T> { fn heap_size_of_children(&self) -> usize { // See comment on HeapSizeOf for JS<T>. 0 |