From d95f5edc2d3fdb020798208f6c86945db01028a4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 31 May 2016 14:52:55 +0200 Subject: [PATCH] Cleanup RootCollection methods The methods `root` and `unroot` should both be unsafe and take a `*const Reflector`. --- components/script/dom/bindings/js.rs | 33 +++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 9adce87d7be..f276cd259f0 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -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(&self, rooted: &Root) { + /// 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 Clone for Root { impl Drop for Root { fn drop(&mut self) { unsafe { - (*self.root_list).unroot(self); + (*self.root_list).unroot(self.reflector()); } } }