Auto merge of #8097 - wenderen:8090-partialeq-for-mutheap, r=nox

implement PartialEq for MutHeap<JS<T>> and MutNullableHeap<JS<T>>

for #8090

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8097)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-26 06:08:01 -05:00
commit 6b95c3957b

View file

@ -273,6 +273,22 @@ impl<T: HeapGCValue> HeapSizeOf for MutHeap<T> {
}
}
impl<T: Reflectable> PartialEq for MutHeap<JS<T>> {
fn eq(&self, other: &Self) -> bool {
unsafe {
*self.val.get() == *other.val.get()
}
}
}
impl<T: Reflectable + PartialEq> PartialEq<T> for MutHeap<JS<T>> {
fn eq(&self, other: &T) -> bool {
unsafe {
**self.val.get() == *other
}
}
}
/// A holder that provides interior mutability for GC-managed values such as
/// `JS<T>`, with nullability represented by an enclosing Option wrapper.
/// Essentially a `Cell<Option<JS<T>>>`, but safer.
@ -334,6 +350,23 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
*self.ptr.get() = val.map(|p| JS::from_ref(p));
}
}
}
impl<T: Reflectable> PartialEq for MutNullableHeap<JS<T>> {
fn eq(&self, other: &Self) -> bool {
unsafe {
*self.ptr.get() == *other.ptr.get()
}
}
}
impl<'a, T: Reflectable> PartialEq<Option<&'a T>> for MutNullableHeap<JS<T>> {
fn eq(&self, other: &Option<&T>) -> bool {
unsafe {
*self.ptr.get() == other.map(JS::from_ref)
}
}
}
impl<T: HeapGCValue> Default for MutNullableHeap<T> {