From 6c7f37061b5c356c4d045bfd23b33e84220e39f9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 17 Oct 2015 01:58:52 +0200 Subject: [PATCH] Implement Deref for JS where T: Reflectable We can only borrow JS from rooted things, so it's safe to deref it. The only types that provide mutable JS things are MutHeap> and MutNullableHeap>, which don't actually expose that they contain JS values. --- components/script/dom/bindings/js.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index aea80d88431..1ef1d93a86d 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -96,6 +96,16 @@ impl JS { } } +impl Deref for JS { + type Target = T; + + fn deref(&self) -> &T { + // We can only have &JS from a rooted thing, so it's safe to deref + // it to &T. + unsafe { &**self.ptr } + } +} + impl JSTraceable for JS { fn trace(&self, trc: *mut JSTracer) { trace_reflector(trc, "", unsafe { (**self.ptr).reflector() });