Make debug logging for tracing JS objects more informative.

This commit is contained in:
Josh Matthews 2016-05-10 12:12:10 -04:00
parent 835f443865
commit 293d465c59
6 changed files with 22 additions and 5 deletions

View file

@ -38,6 +38,7 @@ use script_thread::STACK_ROOTS;
use std::cell::UnsafeCell;
use std::default::Default;
use std::hash::{Hash, Hasher};
use std::intrinsics::type_name;
use std::mem;
use std::ops::Deref;
use std::ptr;
@ -106,7 +107,16 @@ impl<T: Reflectable> Deref for JS<T> {
impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
trace_reflector(trc, "", unsafe { (**self.ptr).reflector() });
#[cfg(debug_assertions)]
let trace_str = format!("for {} on heap", unsafe { type_name::<T>() });
#[cfg(debug_assertions)]
let trace_info = &trace_str[..];
#[cfg(not(debug_assertions))]
let trace_info = "for DOM object on heap";
trace_reflector(trc,
trace_info,
unsafe { (**self.ptr).reflector() });
}
}
@ -520,11 +530,12 @@ impl RootCollection {
/// SM Callback that traces the rooted reflectors
pub unsafe fn trace_roots(tracer: *mut JSTracer) {
debug!("tracing stack roots");
STACK_ROOTS.with(|ref collection| {
let RootCollectionPtr(collection) = collection.get().unwrap();
let collection = &*(*collection).roots.get();
for root in collection {
trace_reflector(tracer, "reflector", &**root);
trace_reflector(tracer, "on stack", &**root);
}
});
}