Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of work on bindings #397

Merged
merged 10 commits into from Apr 24, 2013

Make text nodes use same private slot representation as DOM elements.

  • Loading branch information
jdm committed Apr 23, 2013
commit 535bfb3cbb343b969e46e556f5f20ee77560c1b4
@@ -1,37 +1,35 @@
use dom::bindings::element;
use dom::bindings::node::unwrap;
use dom::bindings::utils;
use dom::bindings::utils::{DOM_OBJECT_SLOT, CacheableWrapper};
use dom::node::{AbstractNode, Text, Comment, Doctype, TextNodeTypeId, CommentNodeTypeId};
use dom::node::{DoctypeNodeTypeId};

use js::jsapi::{JSFreeOp, JSObject, JSContext};
use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot};
use js::glue::bindgen::{RUST_JSVAL_TO_PRIVATE, RUST_PRIVATE_TO_JSVAL};
use js::jsapi::bindgen::{JS_SetReservedSlot};
use js::glue::bindgen::{RUST_PRIVATE_TO_JSVAL};
use js::rust::{Compartment, jsobj};

extern fn finalize_text(_fop: *JSFreeOp, obj: *JSObject) {
debug!("text finalize: %?!", obj as uint);
unsafe {
let val = JS_GetReservedSlot(obj, DOM_OBJECT_SLOT as u32);
let node: AbstractNode = cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val));
let node: AbstractNode = unwrap(obj);
let _elem: ~Text = cast::transmute(node.raw_object());
}
}

extern fn finalize_comment(_fop: *JSFreeOp, obj: *JSObject) {
debug!("comment finalize: %?!", obj as uint);
unsafe {
let val = JS_GetReservedSlot(obj, DOM_OBJECT_SLOT as u32);
let node: AbstractNode = cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val));
let node: AbstractNode = unwrap(obj);
let _elem: ~Comment = cast::transmute(node.raw_object());
}
}

extern fn finalize_doctype(_fop: *JSFreeOp, obj: *JSObject) {
debug!("doctype finalize: %?!", obj as uint);
unsafe {
let val = JS_GetReservedSlot(obj, DOM_OBJECT_SLOT as u32);
let node: AbstractNode = cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val));
let node: AbstractNode = unwrap(obj);
let _elem: ~Doctype = cast::transmute(node.raw_object());
}
}
@@ -82,7 +80,7 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
cache.set_wrapper(obj.ptr);

unsafe {
let raw_ptr = ptr::to_unsafe_ptr(node) as *libc::c_void;
let raw_ptr = node.raw_object() as *libc::c_void;
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.