diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2015-10-17 01:58:52 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2015-10-17 01:58:52 +0200 |
commit | 6c7f37061b5c356c4d045bfd23b33e84220e39f9 (patch) | |
tree | b0e96b402143a4a186f27db902db59f4bb454bc9 /components/script/dom | |
parent | e31ad011033ae076efecf61888daa1f6a5900589 (diff) | |
download | servo-6c7f37061b5c356c4d045bfd23b33e84220e39f9.tar.gz servo-6c7f37061b5c356c4d045bfd23b33e84220e39f9.zip |
Implement Deref<Target=T> for JS<T> where T: Reflectable
We can only borrow JS<T> from rooted things, so it's safe to deref it.
The only types that provide mutable JS<T> things are MutHeap<JS<T>> and
MutNullableHeap<JS<T>>, which don't actually expose that they contain
JS<T> values.
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/js.rs | 10 |
1 files changed, 10 insertions, 0 deletions
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<T: Reflectable> JS<T> { } } +impl<T: Reflectable> Deref for JS<T> { + type Target = T; + + fn deref(&self) -> &T { + // We can only have &JS<T> from a rooted thing, so it's safe to deref + // it to &T. + unsafe { &**self.ptr } + } +} + impl<T: Reflectable> JSTraceable for JS<T> { fn trace(&self, trc: *mut JSTracer) { trace_reflector(trc, "", unsafe { (**self.ptr).reflector() }); |