trace window.location and window.navigator

This commit is contained in:
Tom Schuster 2013-11-17 16:14:06 +01:00
parent ccc7fa7be0
commit f9433e357c
2 changed files with 26 additions and 20 deletions

View file

@ -29,7 +29,7 @@ use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer}; use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor}; use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses}; use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
use js::jsapi::{JSString}; use js::jsapi::{JSString, JS_CallTracer, JSTRACE_OBJECT};
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS}; use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER}; use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
@ -588,6 +588,24 @@ pub trait Traceable {
fn trace(&self, trc: *mut JSTracer); fn trace(&self, trc: *mut JSTracer);
} }
#[fixed_stack_segment]
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
unsafe {
do description.to_c_str().with_ref |name| {
(*tracer).debugPrinter = ptr::null();
(*tracer).debugPrintIndex = -1;
(*tracer).debugPrintArg = name as *libc::c_void;
debug!("tracing {:s}", description);
JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(),
JSTRACE_OBJECT as u32);
}
}
}
pub fn trace_option<T: Reflectable>(tracer: *mut JSTracer, description: &str, option: Option<@mut T>) {
option.map(|some| trace_reflector(tracer, description, some.reflector()));
}
#[fixed_stack_segment] #[fixed_stack_segment]
pub fn initialize_global(global: *JSObject) { pub fn initialize_global(global: *JSObject) {
let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]); let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);

View file

@ -4,6 +4,7 @@
use dom::bindings::codegen::WindowBinding; use dom::bindings::codegen::WindowBinding;
use dom::bindings::utils::{Reflectable, Reflector, Traceable}; use dom::bindings::utils::{Reflectable, Reflector, Traceable};
use dom::bindings::utils::{trace_option, trace_reflector};
use dom::bindings::utils::DOMString; use dom::bindings::utils::DOMString;
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::eventtarget::{EventTarget, WindowTypeId}; use dom::eventtarget::{EventTarget, WindowTypeId};
@ -17,8 +18,8 @@ use servo_msg::compositor_msg::ScriptListener;
use servo_net::image_cache_task::ImageCacheTask; use servo_net::image_cache_task::ImageCacheTask;
use js::glue::*; use js::glue::*;
use js::jsapi::{JSObject, JSContext, JS_DefineProperty, JS_CallTracer}; use js::jsapi::{JSObject, JSContext, JS_DefineProperty};
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JSTracer, JSTRACE_OBJECT}; use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JSTracer};
use js::{JSVAL_NULL, JSPROP_ENUMERATE}; use js::{JSVAL_NULL, JSPROP_ENUMERATE};
use std::cell::Cell; use std::cell::Cell;
@ -251,24 +252,11 @@ impl Window {
} }
impl Traceable for Window { impl Traceable for Window {
#[fixed_stack_segment]
fn trace(&self, tracer: *mut JSTracer) { fn trace(&self, tracer: *mut JSTracer) {
debug!("tracing window"); debug!("tracing window");
unsafe {
match self.page.frame { self.page.frame.map(|frame| trace_reflector(tracer, "document", frame.document.reflector()));
Some(frame) => { trace_option(tracer, "location", self.location);
(*tracer).debugPrinter = ptr::null(); trace_option(tracer, "navigator", self.navigator);
(*tracer).debugPrintIndex = -1;
do "document".to_c_str().with_ref |name| {
(*tracer).debugPrintArg = name as *libc::c_void;
debug!("tracing document");
JS_CallTracer(tracer as *JSTracer,
frame.document.reflector().get_jsobject(),
JSTRACE_OBJECT as u32);
}
}
None => ()
}
}
} }
} }