Make proxy finalizers retrieve the DOM object from the right slot.

This commit is contained in:
Josh Matthews 2013-10-02 00:49:41 -04:00
parent 92f6599854
commit bc81716c30
2 changed files with 11 additions and 6 deletions

View file

@ -4027,7 +4027,7 @@ def finalizeHook(descriptor, hookName, context):
pass pass
else: else:
assert descriptor.nativeIsISupports assert descriptor.nativeIsISupports
release = """let val = JS_GetReservedSlot(obj, 0); release = """let val = JS_GetReservedSlot(obj, dom_object_slot(obj));
let _: @mut %s = cast::transmute(RUST_JSVAL_TO_PRIVATE(val)); let _: @mut %s = cast::transmute(RUST_JSVAL_TO_PRIVATE(val));
debug!("%s finalize: %%p", this); debug!("%s finalize: %%p", this);
""" % (descriptor.concreteType, descriptor.concreteType) """ % (descriptor.concreteType, descriptor.concreteType)

View file

@ -121,14 +121,19 @@ pub fn is_dom_proxy(obj: *JSObject) -> bool {
} }
#[fixed_stack_segment] #[fixed_stack_segment]
pub unsafe fn unwrap<T>(obj: *JSObject) -> T { pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
let clasp = JS_GetClass(obj); let clasp = JS_GetClass(obj);
let slot = if is_dom_class(clasp) { if is_dom_class(clasp) {
DOM_OBJECT_SLOT DOM_OBJECT_SLOT as u32
} else { } else {
assert!(is_dom_proxy(obj)); assert!(is_dom_proxy(obj));
DOM_PROXY_OBJECT_SLOT DOM_PROXY_OBJECT_SLOT as u32
} as u32; }
}
#[fixed_stack_segment]
pub unsafe fn unwrap<T>(obj: *JSObject) -> T {
let slot = dom_object_slot(obj);
let val = JS_GetReservedSlot(obj, slot); let val = JS_GetReservedSlot(obj, slot);
cast::transmute(RUST_JSVAL_TO_PRIVATE(val)) cast::transmute(RUST_JSVAL_TO_PRIVATE(val))
} }