mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Cleanup RootCollection methods
The methods `root` and `unroot` should both be unsafe and take a `*const Reflector`.
This commit is contained in:
parent
b45f1918d1
commit
d95f5edc2d
1 changed files with 15 additions and 18 deletions
|
@ -495,22 +495,20 @@ impl RootCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start tracking a stack-based root
|
/// 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());
|
debug_assert!(thread_state::get().is_script());
|
||||||
unsafe {
|
|
||||||
let mut roots = &mut *self.roots.get();
|
let mut roots = &mut *self.roots.get();
|
||||||
roots.push(untracked_reflector);
|
roots.push(untracked_reflector);
|
||||||
assert!(!(*untracked_reflector).get_jsobject().is_null())
|
assert!(!(*untracked_reflector).get_jsobject().is_null())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Stop tracking a stack-based root, asserting if the reflector isn't found
|
/// Stop tracking a stack-based reflector, asserting if it isn't found.
|
||||||
fn unroot<T: Reflectable>(&self, rooted: &Root<T>) {
|
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());
|
debug_assert!(thread_state::get().is_script());
|
||||||
unsafe {
|
|
||||||
let mut roots = &mut *self.roots.get();
|
let mut roots = &mut *self.roots.get();
|
||||||
let old_reflector = &*rooted.reflector();
|
match roots.iter().rposition(|r| *r == tracked_reflector) {
|
||||||
match roots.iter().rposition(|r| *r == old_reflector) {
|
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
roots.remove(idx);
|
roots.remove(idx);
|
||||||
},
|
},
|
||||||
|
@ -518,7 +516,6 @@ impl RootCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// SM Callback that traces the rooted reflectors
|
/// SM Callback that traces the rooted reflectors
|
||||||
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
||||||
|
@ -618,7 +615,7 @@ impl<T: Reflectable> Clone for Root<T> {
|
||||||
impl<T: Reflectable> Drop for Root<T> {
|
impl<T: Reflectable> Drop for Root<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*self.root_list).unroot(self);
|
(*self.root_list).unroot(self.reflector());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue