mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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.
This commit is contained in:
parent
e31ad01103
commit
6c7f37061b
1 changed files with 10 additions and 0 deletions
|
@ -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() });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue