aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/callback.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2013-11-30 21:04:49 +0100
committerJosh Matthews <josh@joshmatthews.net>2014-02-24 15:16:42 -0500
commit625325434b5c7dc72e784a592f7e014c16cf1018 (patch)
tree9078f192cd7f41132a64124b7f70a3bb51e0936d /src/components/script/dom/bindings/callback.rs
parent061269f9639199a7419e2467ebbe3c28cac1e8ff (diff)
downloadservo-625325434b5c7dc72e784a592f7e014c16cf1018.tar.gz
servo-625325434b5c7dc72e784a592f7e014c16cf1018.zip
Implement JSManaged for DOM objects.
Diffstat (limited to 'src/components/script/dom/bindings/callback.rs')
-rw-r--r--src/components/script/dom/bindings/callback.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/components/script/dom/bindings/callback.rs b/src/components/script/dom/bindings/callback.rs
index 40b3bd7b5fa..10cb35c3af4 100644
--- a/src/components/script/dom/bindings/callback.rs
+++ b/src/components/script/dom/bindings/callback.rs
@@ -4,12 +4,15 @@
use dom::bindings::utils::Reflectable;
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JSVal, JS_ObjectIsCallable};
-use js::jsapi::JS_GetProperty;
-use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT};
+use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer};
+use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT, JSTRACE_OBJECT};
+use std::cast;
use std::libc;
use std::ptr;
+use extra::serialize::{Encodable, Encoder};
+
pub enum ExceptionHandling {
// Report any exception and don't throw it to the caller code.
eReportExceptions,
@@ -26,6 +29,20 @@ pub struct CallbackInterface {
callback: *JSObject
}
+impl<S: Encoder> Encodable<S> for CallbackInterface {
+ fn encode(&self, s: &mut S) {
+ unsafe {
+ let tracer: *mut JSTracer = cast::transmute(s);
+ "callback".to_c_str().with_ref(|name| {
+ (*tracer).debugPrinter = ptr::null();
+ (*tracer).debugPrintIndex = -1;
+ (*tracer).debugPrintArg = name as *libc::c_void;
+ JS_CallTracer(tracer as *JSTracer, self.callback, JSTRACE_OBJECT as u32);
+ });
+ }
+ }
+}
+
pub trait CallbackContainer {
fn callback(&self) -> *JSObject;
}
@@ -66,7 +83,7 @@ pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
_scope: *JSObject,
- p: @mut T) -> *JSObject {
+ p: ~T) -> *JSObject {
let obj = GetJSObjectFromCallback(p);
assert!(obj.is_not_null());