mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Language changes.
This commit is contained in:
parent
134be0dae0
commit
2cfbe2b000
12 changed files with 116 additions and 110 deletions
|
@ -96,8 +96,8 @@ pub struct Content {
|
|||
cx: @Cx,
|
||||
dom_static: GlobalStaticData,
|
||||
|
||||
document: Option<@Document>,
|
||||
window: Option<@Window>,
|
||||
document: Option<@mut Document>,
|
||||
window: Option<@mut Window>,
|
||||
doc_url: Option<Url>,
|
||||
window_size: Size2D<uint>,
|
||||
|
||||
|
@ -159,7 +159,7 @@ pub fn Content(layout_task: LayoutTask,
|
|||
|
||||
pub fn task_from_context(cx: *JSContext) -> *mut Content {
|
||||
unsafe {
|
||||
JS_GetContextPrivate(cx) as *Content
|
||||
JS_GetContextPrivate(cx) as *mut Content
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,8 +213,8 @@ pub impl Content {
|
|||
let js_scripts = result.js_port.recv();
|
||||
debug!("js_scripts: %?", js_scripts);
|
||||
|
||||
let document = @Document(root);
|
||||
let window = @Window(self.control_chan.clone());
|
||||
let document = @mut Document(root);
|
||||
let window = @mut Window(self.control_chan.clone());
|
||||
|
||||
self.damage.add(MatchSelectorsDamage);
|
||||
self.relayout(document, &url);
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct ClientRectImpl {
|
|||
right: f32,
|
||||
}
|
||||
|
||||
pub impl ClientRect for ClientRectImpl {
|
||||
impl ClientRect for ClientRectImpl {
|
||||
fn Top() -> f32 {
|
||||
self.top
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ pub fn ClientRect(top: f32, bottom: f32, left: f32, right: f32) -> ClientRectImp
|
|||
}
|
||||
}
|
||||
|
||||
pub impl CacheableWrapper for ClientRectImpl {
|
||||
fn get_wrappercache(&self) -> &WrapperCache {
|
||||
impl CacheableWrapper for ClientRectImpl {
|
||||
fn get_wrappercache(&mut self) -> &mut WrapperCache {
|
||||
unsafe { cast::transmute(&self.wrapper) }
|
||||
}
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ impl ClientRectListImpl {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl CacheableWrapper for ClientRectListImpl {
|
||||
fn get_wrappercache(&self) -> &WrapperCache {
|
||||
impl CacheableWrapper for ClientRectListImpl {
|
||||
fn get_wrappercache(&mut self) -> &mut WrapperCache {
|
||||
unsafe { cast::transmute(&self.wrapper) }
|
||||
}
|
||||
|
||||
|
|
|
@ -2424,7 +2424,7 @@ class CGAbstractMethod(CGThing):
|
|||
|
||||
def CreateBindingJSObject(descriptor, parent):
|
||||
if descriptor.proxy:
|
||||
handler = """ let cache = ptr::to_unsafe_ptr(aObject.get_wrappercache());
|
||||
handler = """ //let cache = ptr::to_unsafe_ptr(aObject.get_wrappercache());
|
||||
|
||||
let content = task_from_context(aCx);
|
||||
let handler = (*content).dom_static.proxy_handlers.get(&(prototypes::id::%s as uint));
|
||||
|
@ -2453,7 +2453,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
def __init__(self, descriptor):
|
||||
assert descriptor.interface.hasInterfacePrototypeObject()
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aScope'),
|
||||
Argument('BindingReference<' + descriptor.nativeType + '>', 'aObject'),
|
||||
Argument('&mut BindingReference<' + descriptor.nativeType + '>', 'aObject'),
|
||||
Argument('*mut bool', 'aTriedToWrap')]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap_', '*JSObject', args)
|
||||
|
||||
|
@ -2463,8 +2463,8 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
return aObject->GetJSObject();"""
|
||||
|
||||
return """ *aTriedToWrap = true;
|
||||
|
||||
let parent = WrapNativeParent(aCx, aScope, aObject.GetParentObject(aCx));
|
||||
let mut parent = aObject.GetParentObject(aCx);
|
||||
let parent = WrapNativeParent(aCx, aScope, &mut parent);
|
||||
if parent.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
@ -2477,7 +2477,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
return ptr::null();
|
||||
}
|
||||
|
||||
let cache = ptr::to_unsafe_ptr(aObject.get_wrappercache());
|
||||
let cache = ptr::to_mut_unsafe_ptr(aObject.get_wrappercache());
|
||||
|
||||
%s
|
||||
//NS_ADDREF(aObject);
|
||||
|
@ -2496,7 +2496,8 @@ class CGWrapMethod(CGAbstractMethod):
|
|||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', '*JSObject', args, inline=True, pub=True)
|
||||
|
||||
def definition_body(self):
|
||||
return " return Wrap_(aCx, aScope, BindingReference(Left(aObject)), aTriedToWrap);"
|
||||
return " let mut binding = BindingReference(Left(aObject)); \
|
||||
return Wrap_(aCx, aScope, &mut binding, aTriedToWrap);"
|
||||
|
||||
class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
|
||||
def __init__(self, descriptor):
|
||||
|
@ -3848,6 +3849,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::clientrect::*', #XXXjdm
|
||||
'dom::bindings::clientrectlist::*', #XXXjdm
|
||||
'dom::bindings::proxyhandler::*',
|
||||
'content::content_task::task_from_context'
|
||||
],
|
||||
curr)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub trait JSValConvertible<T> {
|
|||
static fn from_jsval(val: JSVal) -> Option<T>;
|
||||
}
|
||||
|
||||
pub impl JSValConvertible<u32> for u32 {
|
||||
impl JSValConvertible<u32> for u32 {
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
RUST_INT_TO_JSVAL(*self as i32)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use dom::bindings::node::create;
|
|||
use dom::document::Document;
|
||||
use dom::bindings::node;
|
||||
use dom::bindings::utils;
|
||||
use dom::node::Node;
|
||||
|
||||
enum DOMException {
|
||||
INVALID_CHARACTER_ERR
|
||||
|
@ -70,16 +71,16 @@ extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> J
|
|||
return 0;
|
||||
}
|
||||
|
||||
let doc = &(*unwrap(obj)).payload;
|
||||
*vp = RUST_OBJECT_TO_JSVAL(node::create(cx, doc.root).ptr);
|
||||
let doc = &mut (*unwrap(obj)).payload;
|
||||
*vp = RUST_OBJECT_TO_JSVAL(node::create(cx, &mut doc.root).ptr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn unwrap(obj: *JSObject) -> *rust_box<Document> {
|
||||
unsafe fn unwrap(obj: *JSObject) -> *mut rust_box<Document> {
|
||||
//TODO: some kind of check if this is a Document object
|
||||
let val = JS_GetReservedSlot(obj, 0);
|
||||
cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val))
|
||||
RUST_JSVAL_TO_PRIVATE(val) as *mut rust_box<Document>
|
||||
}
|
||||
|
||||
extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
|
||||
|
@ -90,7 +91,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init(compartment: @mut Compartment, doc: @Document) {
|
||||
pub fn init(compartment: @mut Compartment, doc: @mut Document) {
|
||||
let obj = utils::define_empty_prototype(~"Document", None, compartment);
|
||||
|
||||
let attrs = @~[
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use content::content_task::{Content, task_from_context};
|
||||
use dom::bindings::node::unwrap;
|
||||
use dom::bindings::utils::{rust_box, squirrel_away_unique, get_compartment};
|
||||
use dom::bindings::utils::{domstring_to_jsval, WrapNewBindingObject};
|
||||
use dom::bindings::utils::{str, CacheableWrapper, DOM_OBJECT_SLOT};
|
||||
|
@ -26,7 +25,8 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
|
|||
debug!("element finalize!");
|
||||
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 = cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val));
|
||||
let elem: ~Element = cast::transmute(node.raw_object());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,8 @@ pub fn init(compartment: @mut Compartment) {
|
|||
extern fn getClientRects(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, vp);
|
||||
let box = utils::unwrap::<*rust_box<AbstractNode>>(obj);
|
||||
let node = &(*box).payload;
|
||||
let mut box = utils::unwrap::<*mut AbstractNode>(obj);
|
||||
let node = &mut *box;
|
||||
let rval = do node.with_imm_element |elem| {
|
||||
elem.getClientRects()
|
||||
};
|
||||
|
@ -102,9 +102,9 @@ extern fn getClientRects(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
|
|||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||
} else {
|
||||
let cache = node.get_wrappercache();
|
||||
assert WrapNewBindingObject(cx, cache.get_wrapper(),
|
||||
rval.get(),
|
||||
cast::transmute(vp));
|
||||
fail_unless!(WrapNewBindingObject(cx, cache.get_wrapper(),
|
||||
rval.get(),
|
||||
cast::transmute(vp)));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -118,7 +118,8 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVa
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let mut box = utils::unwrap::<*mut AbstractNode>(obj);
|
||||
let node = &mut *box;
|
||||
let width = match node.type_id() {
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
let content = task_from_context(cx);
|
||||
|
@ -147,7 +148,8 @@ extern fn HTMLImageElement_setWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVa
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let mut box = utils::unwrap::<*mut AbstractNode>(obj);
|
||||
let node = &mut *box;
|
||||
match node.type_id() {
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
do node.as_mut_element |elem| {
|
||||
|
@ -171,7 +173,8 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let mut box = utils::unwrap::<*mut AbstractNode>(obj);
|
||||
let node = &mut *box;
|
||||
do node.with_imm_element |elem| {
|
||||
let s = str(copy elem.tag_name);
|
||||
*vp = domstring_to_jsval(cx, &s);
|
||||
|
@ -181,7 +184,7 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
|||
}
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
pub fn create(cx: *JSContext, node: AbstractNode) -> jsobj {
|
||||
pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
|
||||
let proto = match node.type_id() {
|
||||
ElementNodeTypeId(HTMLDivElementTypeId) => ~"HTMLDivElement",
|
||||
ElementNodeTypeId(HTMLHeadElementTypeId) => ~"HTMLHeadElement",
|
||||
|
@ -201,7 +204,7 @@ pub fn create(cx: *JSContext, node: AbstractNode) -> jsobj {
|
|||
node.get_wrappercache().set_wrapper(obj.ptr);
|
||||
|
||||
unsafe {
|
||||
let raw_ptr = squirrel_away_unique(~node) as *libc::c_void;
|
||||
let raw_ptr = ptr::addr_of(node) as *libc::c_void;
|
||||
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn init(compartment: @mut Compartment) {
|
|||
}
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
pub fn create(cx: *JSContext, node: AbstractNode) -> jsobj {
|
||||
pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
|
||||
match node.type_id() {
|
||||
ElementNodeTypeId(_) => element::create(cx, node),
|
||||
TextNodeTypeId => fail!(~"no text node bindings yet"),
|
||||
|
@ -69,7 +69,7 @@ pub fn create(cx: *JSContext, node: AbstractNode) -> jsobj {
|
|||
}
|
||||
}
|
||||
|
||||
pub unsafe fn unwrap(obj: *JSObject) -> *rust_box<AbstractNode> {
|
||||
pub unsafe fn unwrap(obj: *JSObject) -> *AbstractNode {
|
||||
let val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT as u64);
|
||||
cast::transmute(JSVAL_TO_PRIVATE(val))
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let rval = do node.with_imm_node |node| {
|
||||
let node = *unwrap(obj);
|
||||
let rval = do node.with_mut_node |node| {
|
||||
node.getFirstChild()
|
||||
};
|
||||
match rval {
|
||||
|
@ -105,19 +105,9 @@ extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBoo
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let rval = do node.with_imm_node |node| {
|
||||
let node = *unwrap(obj);
|
||||
let rval = do node.with_mut_node |node| {
|
||||
node.getNextSibling()
|
||||
<<<<<<< HEAD
|
||||
};
|
||||
match rval {
|
||||
Some(n) => {
|
||||
let obj = create(cx, n).ptr;
|
||||
*vp = RUST_OBJECT_TO_JSVAL(obj)
|
||||
}
|
||||
None => *vp = JSVAL_NULL
|
||||
}
|
||||
=======
|
||||
};
|
||||
match rval {
|
||||
Some(n) => {
|
||||
|
@ -126,7 +116,6 @@ extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBoo
|
|||
}
|
||||
None => *vp = JSVAL_NULL
|
||||
};
|
||||
>>>>>>> Generate working ClientRectList and ClientRect bindings that can wrap, call methods, and access properties.
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -141,20 +130,23 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
fn getNextSibling(&self) -> Option<AbstractNode> {
|
||||
self.next_sibling
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
fn getNextSibling(&mut self) -> Option<&mut AbstractNode> {
|
||||
match self.next_sibling {
|
||||
// transmute because the compiler can't deduce that the reference
|
||||
// is safe outside of with_mut_node blocks.
|
||||
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
fn getFirstChild(&self) -> Option<AbstractNode> {
|
||||
self.first_child
|
||||
>>>>>>> Generate working ClientRectList and ClientRect bindings that can wrap, call methods, and access properties.
|
||||
fn getFirstChild(&mut self) -> Option<&mut AbstractNode> {
|
||||
match self.first_child {
|
||||
// transmute because the compiler can't deduce that the reference
|
||||
// is safe outside of with_mut_node blocks.
|
||||
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
fn getFirstChild(&self) -> Option<AbstractNode> {
|
||||
self.first_child
|
||||
}
|
||||
}
|
||||
|
||||
extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
||||
|
@ -164,7 +156,7 @@ extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
|||
return 0;
|
||||
}
|
||||
|
||||
let node = &(*unwrap(obj)).payload;
|
||||
let node = *unwrap(obj);
|
||||
let rval = do node.with_imm_node |node| {
|
||||
node.getNodeType()
|
||||
};
|
||||
|
@ -174,8 +166,8 @@ extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
|||
}
|
||||
|
||||
impl CacheableWrapper for AbstractNode {
|
||||
fn get_wrappercache(&self) -> &WrapperCache {
|
||||
do self.with_imm_node |n| {
|
||||
fn get_wrappercache(&mut self) -> &mut WrapperCache {
|
||||
do self.with_mut_node |n| {
|
||||
unsafe { cast::transmute(&n.wrapper) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use core::sys::size_of;
|
|||
|
||||
type c_bool = libc::c_int;
|
||||
|
||||
extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
set: c_bool, desc: *mut JSPropertyDescriptor) -> c_bool {
|
||||
unsafe {
|
||||
if _getOwnPropertyDescriptor(cx, proxy, id, set, desc) == 0 {
|
||||
|
@ -50,12 +50,12 @@ fn _getOwnPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
|||
}
|
||||
}
|
||||
|
||||
extern fn getOwnPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
pub extern fn getOwnPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
set: c_bool, desc: *mut JSPropertyDescriptor) -> c_bool {
|
||||
_getOwnPropertyDescriptor(cx, proxy, id, set, desc)
|
||||
}
|
||||
|
||||
fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
||||
pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
||||
unsafe {
|
||||
let name = str::raw::from_buf(className as *u8);
|
||||
let nchars = "[object ]".len() + name.len();
|
||||
|
|
|
@ -14,8 +14,8 @@ use js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_Repor
|
|||
JS_GetInternedStringCharsAndLength, JS_DefineProperties,
|
||||
JS_WrapValue, JS_GetObjectPrototype, JS_ForwardGetPropertyTo,
|
||||
JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
|
||||
use js::jsfriendapi::bindgen::{DefineFunctionWithReserved, GetObjectJSClass,
|
||||
JS_NewObjectWithUniqueType};
|
||||
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||
use js::glue::bindgen::{DefineFunctionWithReserved, GetObjectJSClass};
|
||||
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB,
|
||||
RESOLVE_STUB};
|
||||
use js::glue::bindgen::*;
|
||||
|
@ -29,10 +29,10 @@ const TOSTRING_CLASS_RESERVED_SLOT: u64 = 0;
|
|||
const TOSTRING_NAME_RESERVED_SLOT: u64 = 1;
|
||||
|
||||
struct GlobalStaticData {
|
||||
mut proxy_handlers: linear::LinearMap<uint, *libc::c_void>,
|
||||
mut attribute_ids: linear::LinearMap<uint, ~[mut jsid]>,
|
||||
mut method_ids: linear::LinearMap<uint, ~[mut jsid]>,
|
||||
mut constant_ids: linear::LinearMap<uint, ~[mut jsid]>
|
||||
proxy_handlers: linear::LinearMap<uint, *libc::c_void>,
|
||||
attribute_ids: linear::LinearMap<uint, ~[jsid]>,
|
||||
method_ids: linear::LinearMap<uint, ~[jsid]>,
|
||||
constant_ids: linear::LinearMap<uint, ~[jsid]>
|
||||
}
|
||||
|
||||
pub fn GlobalStaticData() -> GlobalStaticData {
|
||||
|
@ -107,7 +107,7 @@ pub unsafe fn unwrap<T>(obj: *JSObject) -> T {
|
|||
cast::transmute(RUST_JSVAL_TO_PRIVATE(val))
|
||||
}
|
||||
|
||||
pub unsafe fn squirrel_away<T>(x: @T) -> *rust_box<T> {
|
||||
pub unsafe fn squirrel_away<T>(x: @mut T) -> *rust_box<T> {
|
||||
let y: *rust_box<T> = cast::reinterpret_cast(&x);
|
||||
cast::forget(x);
|
||||
y
|
||||
|
@ -341,15 +341,15 @@ pub struct DOMJSClass {
|
|||
dom_class: DOMClass
|
||||
}
|
||||
|
||||
fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
|
||||
pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
|
||||
unsafe {
|
||||
/*assert ((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0;*/
|
||||
cast::transmute(RUST_JSVAL_TO_PRIVATE(JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT)))
|
||||
}
|
||||
}
|
||||
|
||||
mod prototypes {
|
||||
mod id {
|
||||
pub mod prototypes {
|
||||
pub mod id {
|
||||
pub enum Prototype {
|
||||
ClientRect,
|
||||
ClientRectList,
|
||||
|
@ -417,7 +417,7 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
|||
JS_NewObject(cx, constructorClass, functionProto, global)
|
||||
}
|
||||
} else {
|
||||
assert constructorNative.is_not_null();
|
||||
fail_unless!(constructorNative.is_not_null());
|
||||
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
||||
JSFUN_CONSTRUCTOR, global, name);
|
||||
if fun.is_null() {
|
||||
|
@ -540,7 +540,7 @@ pub extern fn ThrowingConstructor(cx: *JSContext, argc: uint, vp: *JSVal) -> JSB
|
|||
}
|
||||
|
||||
pub fn initialize_global(global: *JSObject) {
|
||||
let protoArray = @[0 as *JSObject, ..2]; //XXXjdm number of constructors
|
||||
let protoArray = @mut [0 as *JSObject, ..2]; //XXXjdm number of constructors
|
||||
unsafe {
|
||||
//XXXjdm we should be storing the box pointer instead of the inner
|
||||
let box = squirrel_away(protoArray);
|
||||
|
@ -552,21 +552,21 @@ pub fn initialize_global(global: *JSObject) {
|
|||
}
|
||||
|
||||
pub trait CacheableWrapper {
|
||||
fn get_wrappercache(&self) -> &WrapperCache;
|
||||
fn get_wrappercache(&mut self) -> &mut WrapperCache;
|
||||
fn wrap_object_unique(~self, cx: *JSContext, scope: *JSObject) -> *JSObject;
|
||||
fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject;
|
||||
}
|
||||
|
||||
pub struct WrapperCache {
|
||||
mut wrapper: *JSObject
|
||||
wrapper: *JSObject
|
||||
}
|
||||
|
||||
impl WrapperCache {
|
||||
pub impl WrapperCache {
|
||||
fn get_wrapper(&self) -> *JSObject {
|
||||
unsafe { cast::transmute(self.wrapper) }
|
||||
}
|
||||
|
||||
fn set_wrapper(&self, wrapper: *JSObject) {
|
||||
fn set_wrapper(&mut self, wrapper: *JSObject) {
|
||||
unsafe { self.wrapper = wrapper; }
|
||||
}
|
||||
|
||||
|
@ -578,7 +578,7 @@ impl WrapperCache {
|
|||
}
|
||||
|
||||
pub fn WrapNewBindingObject<T: CacheableWrapper>(cx: *JSContext, scope: *JSObject,
|
||||
value: ~T, vp: *mut JSVal) -> bool {
|
||||
mut value: ~T, vp: *mut JSVal) -> bool {
|
||||
unsafe {
|
||||
let obj = value.get_wrappercache().get_wrapper();
|
||||
if obj.is_not_null() /*&& js::GetObjectCompartment(obj) == js::GetObjectCompartment(scope)*/ {
|
||||
|
@ -604,17 +604,21 @@ pub fn WrapNewBindingObject<T: CacheableWrapper>(cx: *JSContext, scope: *JSObjec
|
|||
|
||||
pub struct OpaqueBindingReference(Either<~CacheableWrapper, @CacheableWrapper>);
|
||||
|
||||
pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, p: OpaqueBindingReference) -> *JSObject {
|
||||
pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, p: &mut OpaqueBindingReference) -> *JSObject {
|
||||
match p {
|
||||
OpaqueBindingReference(Left(p)) => {
|
||||
let obj = p.get_wrappercache().get_wrapper();
|
||||
&OpaqueBindingReference(Left(ref mut p)) => {
|
||||
let cache = p.get_wrappercache();
|
||||
let obj = cache.get_wrapper();
|
||||
if obj.is_not_null() {
|
||||
return obj;
|
||||
}
|
||||
p.wrap_object_unique(cx, scope)
|
||||
let mut tmp: ~CacheableWrapper = unstable::intrinsics::init();
|
||||
tmp <-> *p;
|
||||
tmp.wrap_object_unique(cx, scope)
|
||||
}
|
||||
OpaqueBindingReference(Right(p)) => {
|
||||
let obj = p.get_wrappercache().get_wrapper();
|
||||
&OpaqueBindingReference(Right(ref mut p)) => {
|
||||
let cache = p.get_wrappercache();
|
||||
let obj = cache.get_wrapper();
|
||||
if obj.is_not_null() {
|
||||
return obj;
|
||||
}
|
||||
|
@ -623,7 +627,7 @@ pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, p: OpaqueBindingRefere
|
|||
}
|
||||
}
|
||||
|
||||
pub struct BindingReference<T>(Either<~T, @T>);
|
||||
pub struct BindingReference<T>(Either<~T, @mut T>);
|
||||
|
||||
pub trait BindingObject {
|
||||
fn GetParentObject(&self, cx: *JSContext) -> OpaqueBindingReference;
|
||||
|
@ -637,17 +641,19 @@ pub impl<T: BindingObject + CacheableWrapper> BindingReference<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_wrappercache(&self) -> &self/WrapperCache {
|
||||
fn get_wrappercache(&mut self) -> &self/mut WrapperCache {
|
||||
match **self {
|
||||
Left(ref obj) => obj.get_wrappercache(),
|
||||
Right(ref obj) => obj.get_wrappercache()
|
||||
Left(ref mut obj) => obj.get_wrappercache(),
|
||||
Right(ref mut obj) => obj.get_wrappercache()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn squirrel_away_ref<R>(obj: BindingReference<R>) -> *rust_box<R> {
|
||||
pub fn squirrel_away_ref<R>(obj: &mut BindingReference<R>) -> *rust_box<R> {
|
||||
let mut tmp: BindingReference<R> = unstable::intrinsics::init();
|
||||
tmp <-> *obj;
|
||||
unsafe {
|
||||
match obj {
|
||||
match tmp {
|
||||
BindingReference(Left(obj)) => squirrel_away_unique(obj),
|
||||
BindingReference(Right(obj)) => squirrel_away(obj)
|
||||
}
|
||||
|
@ -756,7 +762,7 @@ fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &[mut jsid]) -> bool {
|
||||
pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool {
|
||||
let mut rval = true;
|
||||
for specs.eachi |i, spec| {
|
||||
if spec.name.is_null() == true {
|
||||
|
|
|
@ -76,7 +76,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init(compartment: @mut Compartment, win: @Window) {
|
||||
pub fn init(compartment: @mut Compartment, win: @mut Window) {
|
||||
let proto = utils::define_empty_prototype(~"Window", None, compartment);
|
||||
compartment.register_class(utils::instance_jsclass(~"WindowInstance", finalize));
|
||||
|
||||
|
@ -132,8 +132,8 @@ pub fn init(compartment: @mut Compartment, win: @Window) {
|
|||
JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
pub impl CacheableWrapper for Window {
|
||||
fn get_wrappercache(&self) -> &WrapperCache {
|
||||
impl CacheableWrapper for Window {
|
||||
fn get_wrappercache(&mut self) -> &mut WrapperCache {
|
||||
unsafe { cast::transmute(&self.wrapper) }
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ use std::arc::ARC;
|
|||
/// FIXME: This should be replaced with a trait once they can inherit from structs.
|
||||
pub struct AbstractNode {
|
||||
priv obj: *mut Node,
|
||||
//wrapper: WrapperCache
|
||||
}
|
||||
|
||||
impl Eq for AbstractNode {
|
||||
|
@ -316,6 +315,10 @@ pub impl AbstractNode {
|
|||
fn is_style_element(self) -> bool {
|
||||
self.type_id() == ElementNodeTypeId(HTMLStyleElementTypeId)
|
||||
}
|
||||
|
||||
unsafe fn raw_object(self) -> *mut Node {
|
||||
self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugMethods for AbstractNode {
|
||||
|
@ -355,7 +358,6 @@ impl Node {
|
|||
// This surrenders memory management of the node!
|
||||
AbstractNode {
|
||||
obj: transmute(node),
|
||||
//wrapper: WrapperCache::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,17 +377,17 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn define_bindings(compartment: @mut Compartment, doc: @Document, win: @Window) {
|
||||
pub fn define_bindings(compartment: @mut Compartment, doc: @mut Document, win: @mut Window) {
|
||||
bindings::window::init(compartment, win);
|
||||
bindings::document::init(compartment, doc);
|
||||
bindings::node::init(compartment);
|
||||
bindings::element::init(compartment);
|
||||
bindings::utils::initialize_global(compartment.global_obj.ptr);
|
||||
let mut unused = false;
|
||||
assert codegen::ClientRectBinding::DefineDOMInterface(compartment.cx.ptr,
|
||||
compartment.global_obj.ptr,
|
||||
&mut unused);
|
||||
assert codegen::ClientRectListBinding::DefineDOMInterface(compartment.cx.ptr,
|
||||
compartment.global_obj.ptr,
|
||||
&mut unused);
|
||||
fail_unless!(codegen::ClientRectBinding::DefineDOMInterface(compartment.cx.ptr,
|
||||
compartment.global_obj.ptr,
|
||||
&mut unused));
|
||||
fail_unless!(codegen::ClientRectListBinding::DefineDOMInterface(compartment.cx.ptr,
|
||||
compartment.global_obj.ptr,
|
||||
&mut unused));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue