diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index 64c9a2ec0ff..9582103c088 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -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, window_size: Size2D, @@ -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); diff --git a/src/servo/dom/bindings/clientrect.rs b/src/servo/dom/bindings/clientrect.rs index 03e97163b92..1c7c0726af3 100644 --- a/src/servo/dom/bindings/clientrect.rs +++ b/src/servo/dom/bindings/clientrect.rs @@ -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) } } diff --git a/src/servo/dom/bindings/clientrectlist.rs b/src/servo/dom/bindings/clientrectlist.rs index 4241faf3717..92ac7da6d78 100644 --- a/src/servo/dom/bindings/clientrectlist.rs +++ b/src/servo/dom/bindings/clientrectlist.rs @@ -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) } } diff --git a/src/servo/dom/bindings/codegen/CodegenRust.py b/src/servo/dom/bindings/codegen/CodegenRust.py index a20f5ff2966..e35be6e3148 100644 --- a/src/servo/dom/bindings/codegen/CodegenRust.py +++ b/src/servo/dom/bindings/codegen/CodegenRust.py @@ -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) diff --git a/src/servo/dom/bindings/conversions.rs b/src/servo/dom/bindings/conversions.rs index c6575f1e907..a53951379c5 100644 --- a/src/servo/dom/bindings/conversions.rs +++ b/src/servo/dom/bindings/conversions.rs @@ -6,7 +6,7 @@ pub trait JSValConvertible { static fn from_jsval(val: JSVal) -> Option; } -pub impl JSValConvertible for u32 { +impl JSValConvertible for u32 { fn to_jsval(&self) -> JSVal { RUST_INT_TO_JSVAL(*self as i32) } diff --git a/src/servo/dom/bindings/document.rs b/src/servo/dom/bindings/document.rs index 53668365bef..8c8df125c61 100644 --- a/src/servo/dom/bindings/document.rs +++ b/src/servo/dom/bindings/document.rs @@ -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 { +unsafe fn unwrap(obj: *JSObject) -> *mut rust_box { //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 } 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 = @~[ diff --git a/src/servo/dom/bindings/element.rs b/src/servo/dom/bindings/element.rs index 072a4a47fe5..ba2c139003a 100644 --- a/src/servo/dom/bindings/element.rs +++ b/src/servo/dom/bindings/element.rs @@ -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>(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)); } diff --git a/src/servo/dom/bindings/node.rs b/src/servo/dom/bindings/node.rs index e5c5fd2181b..f32128fd69d 100644 --- a/src/servo/dom/bindings/node.rs +++ b/src/servo/dom/bindings/node.rs @@ -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 { +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 { - 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 { - 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 { - 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) } } } diff --git a/src/servo/dom/bindings/proxyhandler.rs b/src/servo/dom/bindings/proxyhandler.rs index 03ccbd747f4..4d984271414 100644 --- a/src/servo/dom/bindings/proxyhandler.rs +++ b/src/servo/dom/bindings/proxyhandler.rs @@ -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(); diff --git a/src/servo/dom/bindings/utils.rs b/src/servo/dom/bindings/utils.rs index 9e633205e8c..9d2b5a135b4 100644 --- a/src/servo/dom/bindings/utils.rs +++ b/src/servo/dom/bindings/utils.rs @@ -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, - mut attribute_ids: linear::LinearMap, - mut method_ids: linear::LinearMap, - mut constant_ids: linear::LinearMap + proxy_handlers: linear::LinearMap, + attribute_ids: linear::LinearMap, + method_ids: linear::LinearMap, + constant_ids: linear::LinearMap } pub fn GlobalStaticData() -> GlobalStaticData { @@ -107,7 +107,7 @@ pub unsafe fn unwrap(obj: *JSObject) -> T { cast::transmute(RUST_JSVAL_TO_PRIVATE(val)) } -pub unsafe fn squirrel_away(x: @T) -> *rust_box { +pub unsafe fn squirrel_away(x: @mut T) -> *rust_box { let y: *rust_box = 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(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(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(Either<~T, @T>); +pub struct BindingReference(Either<~T, @mut T>); pub trait BindingObject { fn GetParentObject(&self, cx: *JSContext) -> OpaqueBindingReference; @@ -637,17 +641,19 @@ pub impl BindingReference { } } - 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(obj: BindingReference) -> *rust_box { +pub fn squirrel_away_ref(obj: &mut BindingReference) -> *rust_box { + let mut tmp: BindingReference = 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 { } } -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 { diff --git a/src/servo/dom/bindings/window.rs b/src/servo/dom/bindings/window.rs index 469cf10c681..475fe4a2b7a 100644 --- a/src/servo/dom/bindings/window.rs +++ b/src/servo/dom/bindings/window.rs @@ -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) } } diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 408c60942a8..54a86bf871f 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -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)); }