Navigation Menu

Skip to content

Commit

Permalink
Generalise RootedVec::<JS<T>>::r as [JS<T>]::r
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Oct 11, 2016
1 parent 45c9aa7 commit 3a547cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 7 additions & 0 deletions components/script/dom/bindings/js.rs
Expand Up @@ -461,6 +461,13 @@ pub trait RootedReference<'root> {
fn r(&'root self) -> Self::Ref;
}

impl<'root, T: JSTraceable + Reflectable + 'root> RootedReference<'root> for [JS<T>] {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(self) }
}
}

impl<'root, T: Reflectable + 'root> RootedReference<'root> for Rc<T> {
type Ref = &'root T;
fn r(&'root self) -> &'root T {
Expand Down
10 changes: 1 addition & 9 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -36,7 +36,7 @@ use devtools_traits::CSSError;
use devtools_traits::WorkerId;
use dom::abstractworker::SharedRt;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::js::{JS, Root, RootedReference};
use dom::bindings::js::{JS, Root};
use dom::bindings::refcounted::{Trusted, TrustedPromise};
use dom::bindings::reflector::{Reflectable, Reflector};
use dom::bindings::str::{DOMString, USVString};
Expand Down Expand Up @@ -80,7 +80,6 @@ use std::boxed::FnBox;
use std::cell::{Cell, UnsafeCell};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::hash::{BuildHasher, Hash};
use std::mem;
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::rc::Rc;
Expand Down Expand Up @@ -553,13 +552,6 @@ impl<'a, T: JSTraceable + Reflectable> RootedVec<'a, JS<T>> {
}
}

impl<'a, 'root, T: JSTraceable + Reflectable + 'root> RootedReference<'root> for RootedVec<'a, JS<T>> {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(&self[..]) }
}
}

impl<'a, T: JSTraceable> Drop for RootedVec<'a, T> {
fn drop(&mut self) {
self.clear();
Expand Down

0 comments on commit 3a547cc

Please sign in to comment.