aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/trace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/bindings/trace.rs')
-rw-r--r--src/components/script/dom/bindings/trace.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs
index 554c67e8dc6..cbbeddb8594 100644
--- a/src/components/script/dom/bindings/trace.rs
+++ b/src/components/script/dom/bindings/trace.rs
@@ -6,6 +6,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector};
use js::jsapi::{JSObject, JSTracer, JS_CallTracer, JSTRACE_OBJECT};
+use js::jsval::JSVal;
use libc;
use std::cast;
@@ -42,6 +43,22 @@ pub trait JSTraceable {
fn trace(&self, trc: *mut JSTracer);
}
+pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
+ if !val.is_gcthing() {
+ return;
+ }
+
+ unsafe {
+ description.to_c_str().with_ref(|name| {
+ (*tracer).debugPrinter = ptr::null();
+ (*tracer).debugPrintIndex = -1;
+ (*tracer).debugPrintArg = name as *libc::c_void;
+ debug!("tracing value {:s}", description);
+ JS_CallTracer(tracer as *JSTracer, val.to_gcthing(), val.trace_kind());
+ });
+ }
+}
+
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
trace_object(tracer, description, reflector.get_jsobject())
}
@@ -132,3 +149,10 @@ impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<*JSObject> {
Ok(())
}
}
+
+impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<JSVal> {
+ fn encode(&self, s: &mut S) -> Result<(), E> {
+ trace_jsval(get_jstracer(s), "val", **self);
+ Ok(())
+ }
+}