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.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index f24115a349a..c9f3e157b75 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -575,3 +575,24 @@ impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
self.deref().reflector()
}
}
+
+/// A trait for comparing smart pointers ignoring the lifetimes
+pub trait Comparable<T> {
+ fn equals(&self, other: T) -> bool;
+}
+
+impl<'a, 'b, T> Comparable<JSRef<'a, T>> for JSRef<'b, T> {
+ fn equals(&self, other: JSRef<'a, T>) -> bool {
+ self.ptr == other.ptr
+ }
+}
+
+impl<'a, 'b, T> Comparable<Option<JSRef<'a, T>>> for Option<JSRef<'b, T>> {
+ fn equals(&self, other: Option<JSRef<'a, T>>) -> bool {
+ match (*self, other) {
+ (Some(x), Some(y)) => x.ptr == y.ptr,
+ (None, None) => true,
+ _ => false
+ }
+ }
+}