Auto merge of #11522 - nox:root-ref, r=jdm

Remove all uses of &Root<T>

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11522)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-01 07:36:47 -05:00
commit 2be5f72113
14 changed files with 40 additions and 52 deletions

View file

@ -76,15 +76,6 @@ impl<T> JS<T> {
}
impl<T: Reflectable> JS<T> {
/// Create a JS<T> from a Root<T>
/// XXX Not a great API. Should be a call on Root<T> instead
#[allow(unrooted_must_root)]
pub fn from_rooted(root: &Root<T>) -> JS<T> {
debug_assert!(thread_state::get().is_script());
JS {
ptr: unsafe { NonZero::new(&**root) },
}
}
/// Create a JS<T> from a &T
#[allow(unrooted_must_root)]
pub fn from_ref(obj: &T) -> JS<T> {
@ -504,27 +495,24 @@ impl RootCollection {
}
/// Start tracking a stack-based root
fn root(&self, untracked_reflector: *const Reflector) {
unsafe fn root(&self, untracked_reflector: *const Reflector) {
debug_assert!(thread_state::get().is_script());
unsafe {
let mut roots = &mut *self.roots.get();
roots.push(untracked_reflector);
assert!(!(*untracked_reflector).get_jsobject().is_null())
}
let mut roots = &mut *self.roots.get();
roots.push(untracked_reflector);
assert!(!(*untracked_reflector).get_jsobject().is_null())
}
/// Stop tracking a stack-based root, asserting if the reflector isn't found
fn unroot<T: Reflectable>(&self, rooted: &Root<T>) {
/// Stop tracking a stack-based reflector, asserting if it isn't found.
unsafe fn unroot(&self, tracked_reflector: *const Reflector) {
assert!(!tracked_reflector.is_null());
assert!(!(*tracked_reflector).get_jsobject().is_null());
debug_assert!(thread_state::get().is_script());
unsafe {
let mut roots = &mut *self.roots.get();
let old_reflector = &*rooted.reflector();
match roots.iter().rposition(|r| *r == old_reflector) {
Some(idx) => {
roots.remove(idx);
},
None => panic!("Can't remove a root that was never rooted!"),
}
let mut roots = &mut *self.roots.get();
match roots.iter().rposition(|r| *r == tracked_reflector) {
Some(idx) => {
roots.remove(idx);
},
None => panic!("Can't remove a root that was never rooted!"),
}
}
}
@ -613,7 +601,7 @@ impl<T: Reflectable> Deref for Root<T> {
}
impl<T: Reflectable> PartialEq for Root<T> {
fn eq(&self, other: &Root<T>) -> bool {
fn eq(&self, other: &Self) -> bool {
self.ptr == other.ptr
}
}
@ -627,7 +615,7 @@ impl<T: Reflectable> Clone for Root<T> {
impl<T: Reflectable> Drop for Root<T> {
fn drop(&mut self) {
unsafe {
(*self.root_list).unroot(self);
(*self.root_list).unroot(self.reflector());
}
}
}

View file

@ -540,7 +540,7 @@ impl<A: JSTraceable + Reflectable> FromIterator<Root<A>> for RootedVec<JS<A>> {
let mut vec = unsafe {
RootedVec::new_with_destination_address(return_address() as *const libc::c_void)
};
vec.extend(iterable.into_iter().map(|item| JS::from_rooted(&item)));
vec.extend(iterable.into_iter().map(|item| JS::from_ref(&*item)));
vec
}
}