Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all uses of &Root<T> #11522

Merged
merged 3 commits into from Jun 1, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Cleanup RootCollection methods

The methods `root` and `unroot` should both be unsafe and take
a `*const Reflector`.
  • Loading branch information
nox committed May 31, 2016
commit d95f5edc2d3fdb020798208f6c86945db01028a4
@@ -495,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!"),
}
}
}
@@ -618,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());
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.