mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement JSManaged for DOM objects.
This commit is contained in:
parent
061269f963
commit
625325434b
137 changed files with 3644 additions and 2778 deletions
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue