diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index 1e0bd248a16..fe005db9a3c 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -142,14 +142,14 @@ impl Content { } } - fn handle_msg(msg: Either) -> bool { + fn handle_msg(+msg: Either) -> bool { match msg { Left(control_msg) => self.handle_control_msg(control_msg), Right(event) => self.handle_event(event) } } - fn handle_control_msg(control_msg: ControlMsg) -> bool { + fn handle_control_msg(+control_msg: ControlMsg) -> bool { match control_msg { ParseMsg(url) => { debug!("content: Received url `%s` to parse", url_to_str(copy url)); @@ -173,14 +173,14 @@ impl Content { let document = Document(root, self.scope, css_rules); let window = Window(self.from_master); - self.relayout(document, &url); + self.relayout(&document, &url); self.document = Some(@document); self.window = Some(@window); self.doc_url = Some(copy url); let compartment = option::expect(&self.compartment, ~"TODO error checking"); compartment.define_functions(debug_fns); - define_bindings(*compartment, + define_bindings(compartment, option::get(&self.document), option::get(&self.window)); @@ -202,7 +202,7 @@ impl Content { //TODO: support extra args. requires passing a *jsval argv JS_CallFunctionValue(self.cx.ptr, thisValue, timerData.funval, 0, null(), ptr::to_unsafe_ptr(&rval)); - self.relayout(*option::get(&self.document), &option::get(&self.doc_url)); + self.relayout(self.document.get(), &option::get(&self.doc_url)); return true; } @@ -249,7 +249,7 @@ impl Content { join the layout task, and then request a new layout run. It won't wait for the new layout computation to finish. */ - fn relayout(document: Document, doc_url: &Url) { + fn relayout(document: &Document, doc_url: &Url) { debug!("content: performing relayout"); // Now, join the layout so that they will see the latest @@ -266,7 +266,7 @@ impl Content { } fn query_layout(query: layout_task::LayoutQuery) -> layout_task::LayoutQueryResponse { - self.relayout(*self.document.get(), &self.doc_url.get()); + self.relayout(self.document.get(), &self.doc_url.get()); self.join_layout(); let response_port = Port(); @@ -288,7 +288,7 @@ impl Content { } Some(document) => { assert self.doc_url.is_some(); - self.relayout(*document, &self.doc_url.get()); + self.relayout(document, &self.doc_url.get()); } } return true; @@ -301,7 +301,7 @@ impl Content { } Some(document) => { assert self.doc_url.is_some(); - self.relayout(*document, &self.doc_url.get()); + self.relayout(document, &self.doc_url.get()); } } return true; diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 4df3d88003b..e7796c7b98d 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -119,7 +119,7 @@ impl Node : StyleMethods { fail ~"get_style() called on a node without a style!"; } // TODO: return a safe reference; don't copy! - return copy *self.aux(|x| copy x).style; + return copy *self.aux(|x| copy *x).style; } /** diff --git a/src/servo/dom/bindings/document.rs b/src/servo/dom/bindings/document.rs index cf63afafc3a..422763204a3 100644 --- a/src/servo/dom/bindings/document.rs +++ b/src/servo/dom/bindings/document.rs @@ -88,7 +88,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { } } -pub fn init(compartment: bare_compartment, doc: @Document) { +pub fn init(compartment: &bare_compartment, doc: @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 024ede2533c..62478f35358 100644 --- a/src/servo/dom/bindings/element.rs +++ b/src/servo/dom/bindings/element.rs @@ -30,7 +30,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { } } -pub fn init(compartment: bare_compartment) { +pub fn init(compartment: &bare_compartment) { let obj = utils::define_empty_prototype(~"Element", Some(~"Node"), compartment); let attrs = @~[ {name: compartment.add_name(~"tagName"), @@ -74,7 +74,7 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsva let bundle = unwrap(obj); let node = (*bundle).payload.node; let scope = (*bundle).payload.scope; - let width = scope.write(node, |nd| { + let width = scope.write(&node, |nd| { match nd.kind { ~Element(ed) => { match ed.kind { @@ -105,7 +105,7 @@ extern fn HTMLImageElement_setWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsva } let bundle = unwrap(obj); - do (*bundle).payload.scope.write((*bundle).payload.node) |nd| { + do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| { match nd.kind { ~Element(ed) => { match ed.kind { @@ -131,11 +131,11 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval) } let bundle = unwrap(obj); - do (*bundle).payload.scope.write((*bundle).payload.node) |nd| { + do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| { match nd.kind { ~Element(ed) => { let s = str(copy ed.tag_name); - *vp = domstring_to_jsval(cx, s); + *vp = domstring_to_jsval(cx, &s); } _ => { //XXXjdm should probably read the spec to figure out what to do here @@ -148,7 +148,7 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval) } pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe { - let proto = scope.write(node, |nd| { + let proto = scope.write(&node, |nd| { match nd.kind { ~Element(ed) => { match ed.kind { diff --git a/src/servo/dom/bindings/node.rs b/src/servo/dom/bindings/node.rs index 9f3a0eb86b9..f27849df520 100644 --- a/src/servo/dom/bindings/node.rs +++ b/src/servo/dom/bindings/node.rs @@ -14,7 +14,7 @@ use utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval, use libc::c_uint; use ptr::null; -pub fn init(compartment: bare_compartment) { +pub fn init(compartment: &bare_compartment) { let obj = utils::define_empty_prototype(~"Node", None, compartment); let attrs = @~[ @@ -42,7 +42,7 @@ pub fn init(compartment: bare_compartment) { } pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe { - do scope.write(node) |nd| { + do scope.write(&node) |nd| { match nd.kind { ~Element(*) => { element::create(cx, node, scope) @@ -85,7 +85,7 @@ extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool } let bundle = unwrap(obj); - do (*bundle).payload.scope.write((*bundle).payload.node) |nd| { + do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| { match nd.tree.first_child { Some(n) => { let obj = create(cx, n, (*bundle).payload.scope).ptr; @@ -108,7 +108,7 @@ extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBoo } let bundle = unwrap(obj); - do (*bundle).payload.scope.write((*bundle).payload.node) |nd| { + do (*bundle).payload.scope.write(&(*bundle).payload.node) |nd| { match nd.tree.next_sibling { Some(n) => { let obj = create(cx, n, (*bundle).payload.scope).ptr; diff --git a/src/servo/dom/bindings/utils.rs b/src/servo/dom/bindings/utils.rs index 43566c83b3e..a6ccf0dd29b 100644 --- a/src/servo/dom/bindings/utils.rs +++ b/src/servo/dom/bindings/utils.rs @@ -56,8 +56,8 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> Result<~str, ()> { } } -unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval { - match str { +unsafe fn domstring_to_jsval(cx: *JSContext, str: &DOMString) -> jsval { + match *str { null_string => { JSVAL_NULL } @@ -94,8 +94,8 @@ extern fn has_instance(_cx: *JSContext, obj: **JSObject, v: *jsval, bp: *mut JSB return 1; } -pub fn prototype_jsclass(name: ~str) -> fn(+compartment: bare_compartment) -> JSClass { - |+compartment: bare_compartment, copy name| { +pub fn prototype_jsclass(+name: ~str) -> fn(+compartment: bare_compartment) -> JSClass { + |+compartment: bare_compartment| { {name: compartment.add_name(name), flags: 0, addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8, @@ -122,9 +122,9 @@ pub fn prototype_jsclass(name: ~str) -> fn(+compartment: bare_compartment) -> JS } } -pub fn instance_jsclass(name: ~str, finalize: *u8) +pub fn instance_jsclass(+name: ~str, finalize: *u8) -> fn(+compartment: bare_compartment) -> JSClass { - |+compartment: bare_compartment, copy name| { + |+compartment: bare_compartment| { {name: compartment.add_name(name), flags: JSCLASS_HAS_RESERVED_SLOTS(1), addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8, @@ -151,7 +151,7 @@ pub fn instance_jsclass(name: ~str, finalize: *u8) } } -pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: bare_compartment) +pub fn define_empty_prototype(+name: ~str, +proto: Option<~str>, compartment: &bare_compartment) -> js::rust::jsobj { compartment.register_class(utils::prototype_jsclass(name)); diff --git a/src/servo/dom/bindings/window.rs b/src/servo/dom/bindings/window.rs index ebe70ab3ecb..b2026cb9255 100644 --- a/src/servo/dom/bindings/window.rs +++ b/src/servo/dom/bindings/window.rs @@ -64,7 +64,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { } } -pub fn init(compartment: bare_compartment, win: @Window) { +pub fn init(compartment: &bare_compartment, win: @Window) { let proto = utils::define_empty_prototype(~"Window", None, compartment); compartment.register_class(utils::instance_jsclass(~"WindowInstance", finalize)); diff --git a/src/servo/dom/document.rs b/src/servo/dom/document.rs index a07ae5f9c6f..fbeacf77535 100644 --- a/src/servo/dom/document.rs +++ b/src/servo/dom/document.rs @@ -8,7 +8,7 @@ struct Document { css_rules: ARC, } -fn Document(root: Node, scope: NodeScope, -css_rules: Stylesheet) -> Document { +fn Document(+root: Node, +scope: NodeScope, +css_rules: Stylesheet) -> Document { Document { root : root, scope : scope, diff --git a/src/servo/dom/element.rs b/src/servo/dom/element.rs index 8547d3bad19..54112eb8b12 100644 --- a/src/servo/dom/element.rs +++ b/src/servo/dom/element.rs @@ -11,24 +11,24 @@ struct ElementData { } impl ElementData { - fn get_attr(name: ~str) -> Option<~str> { - let found = do self.attrs.find |attr| { attr.name == name }; + fn get_attr(name: &str) -> Option<~str> { + let found = do self.attrs.find |attr| { name == attr.name }; match found { Some(attr) => Some(copy attr.value), None => None } } - fn set_attr(name: ~str, value: ~str) { - let idx = do self.attrs.position |attr| { attr.name == name }; + fn set_attr(name: &str, +value: ~str) { + let idx = do self.attrs.position |attr| { name == attr.name }; match idx { - Some(idx) => self.attrs.set_elt(idx, ~Attr(name, value)), + Some(idx) => self.attrs.set_elt(idx, ~Attr(name.to_str(), value)), None => {} } } } -fn ElementData(tag_name: ~str, kind: ~ElementKind) -> ElementData { +fn ElementData(+tag_name: ~str, +kind: ~ElementKind) -> ElementData { ElementData { tag_name : tag_name, kind : kind, @@ -41,7 +41,7 @@ struct Attr { value: ~str, } -fn Attr(name: ~str, value: ~str) -> Attr { +fn Attr(+name: ~str, +value: ~str) -> Attr { Attr { name : name, value : value, diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 442b9d51edc..6f7f580dc00 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -53,8 +53,8 @@ impl Node { with a generic implementation of rcu::Handle */ impl Node : cmp::Eq { pure fn eq(other : &Node) -> bool unsafe { - let my_data : @LayoutData = @self.aux(|a| a); - let ot_data : @LayoutData = @other.aux(|a| a); + let my_data : @LayoutData = @self.aux(|a| *a); + let ot_data : @LayoutData = @other.aux(|a| *a); core::box::ptr_eq(my_data, ot_data) } pure fn ne(other : &Node) -> bool unsafe { @@ -101,8 +101,8 @@ struct DoctypeData { force_quirks: bool } -fn DoctypeData(name: ~str, public_id: Option<~str>, - system_id: Option<~str>, force_quirks: bool) -> DoctypeData { +fn DoctypeData(+name: ~str, +public_id: Option<~str>, + +system_id: Option<~str>, force_quirks: bool) -> DoctypeData { DoctypeData { name : name, public_id : public_id, @@ -113,7 +113,7 @@ fn DoctypeData(name: ~str, public_id: Option<~str>, -fn define_bindings(compartment: bare_compartment, doc: @Document, +fn define_bindings(compartment: &bare_compartment, doc: @Document, win: @Window) { bindings::window::init(compartment, win); bindings::document::init(compartment, doc); @@ -141,13 +141,13 @@ fn NodeScope() -> NodeScope { } trait NodeScopeExtensions { - fn new_node(-k: NodeKind) -> Node; + fn new_node(+k: NodeKind) -> Node; } #[allow(non_implicitly_copyable_typarams)] impl NodeScope : NodeScopeExtensions { - fn new_node(-k: NodeKind) -> Node { - self.handle(NodeData({tree: tree::empty(), kind: ~k})) + fn new_node(+k: NodeKind) -> Node { + self.handle(&NodeData({tree: tree::empty(), kind: ~k})) } } @@ -162,7 +162,7 @@ impl NodeScope : tree::ReadMethods { } fn with_tree_fields(node: &Node, f: fn(&tree::Tree) -> R) -> R { - self.read(*node, |n| f(&n.tree)) + self.read(node, |n| f(&n.tree)) } } @@ -173,6 +173,6 @@ impl NodeScope : tree::WriteMethods { } fn with_tree_fields(node: &Node, f: fn(&tree::Tree) -> R) -> R { - self.write(*node, |n| f(&n.tree)) + self.write(node, |n| f(&n.tree)) } } diff --git a/src/servo/dom/rcu.rs b/src/servo/dom/rcu.rs index 5b4aef7b234..a469daf077b 100644 --- a/src/servo/dom/rcu.rs +++ b/src/servo/dom/rcu.rs @@ -67,7 +67,7 @@ struct ScopeResource { } } -fn ScopeResource(d : ScopeData) -> ScopeResource { +fn ScopeResource(+d : ScopeData) -> ScopeResource { ScopeResource { d: d } } @@ -99,8 +99,8 @@ impl Handle { impl Handle { #[doc(str = "Access the reader's view of the handle's data.")] - fn read(f: fn(T) -> U) -> U unsafe { - f(*self.read_ptr()) + fn read(f: fn(&T) -> U) -> U unsafe { + f(&*self.read_ptr()) } #[doc(str = "True if auxiliary data is associated with this handle.")] @@ -117,9 +117,9 @@ impl Handle { } #[doc(str = "access the auxiliary data associated with this handle.")] - fn aux(f: fn(A) -> U) -> U unsafe { + fn aux(f: fn(&A) -> U) -> U unsafe { assert self.has_aux(); - f(*self.read_aux()) + f(&*self.read_aux()) } } @@ -192,29 +192,30 @@ impl Scope { self.d.layout_active = false; } - fn read(h: Handle, f: fn(T) -> U) -> U unsafe { + fn read(h: &Handle, f: fn(&T) -> U) -> U unsafe { // Use the write_ptr, which may be more up to date than the read_ptr or may not - f(*h.write_ptr()) + f(&*h.write_ptr()) } - fn write(h: Handle, f: fn(T) -> U) -> U unsafe { + fn write(h: &Handle, f: fn(&T) -> U) -> U unsafe { let const_read_ptr = ptr::const_offset(h.read_ptr(), 0); let const_write_ptr = ptr::const_offset(h.write_ptr(), 0); if self.d.layout_active && const_read_ptr == const_write_ptr { #debug["marking handle %? as dirty", h]; h.set_write_ptr(cast::reinterpret_cast(&self.clone(h.read_ptr()))); h.set_next_dirty(self.d.first_dirty); - self.d.first_dirty = h; + self.d.first_dirty = *h; } - f(*h.write_ptr()) + f(&*h.write_ptr()) } + // FIXME: This could avoid a deep copy by taking ownership of `v` #[allow(non_implicitly_copyable_typarams)] - fn handle(v: T) -> Handle unsafe { + fn handle(v: &T) -> Handle unsafe { let d: *HandleData = cast::reinterpret_cast( &libc::malloc(sys::size_of::>() as size_t)); - (*d).read_ptr = self.clone(ptr::to_unsafe_ptr(&v)); + (*d).read_ptr = self.clone(ptr::to_unsafe_ptr(v)); (*d).write_ptr = cast::reinterpret_cast(&(*d).read_ptr); (*d).read_aux = ptr::null(); (*d).next_dirty = null_handle(); @@ -242,18 +243,18 @@ mod test { #[test] fn handles_get_freed() { let s: animal_scope = Scope(); - s.handle({name:~"henrietta", species:chicken(~{mut eggs_per_day:22u})}); - s.handle({name:~"ferdinand", species:bull(~{mut horns:3u})}); + s.handle(&{name:~"henrietta", species:chicken(~{mut eggs_per_day:22u})}); + s.handle(&{name:~"ferdinand", species:bull(~{mut horns:3u})}); } - fn mutate(a: animal) { + fn mutate(a: &animal) { match a.species { chicken(c) => c.eggs_per_day += 1u, bull(c) => c.horns += 1u } } - fn read_characteristic(a: animal) -> uint { + fn read_characteristic(a: &animal) -> uint { match a.species { chicken(c) => c.eggs_per_day, bull(c) => c.horns @@ -264,10 +265,10 @@ mod test { fn interspersed_execution() { let s: animal_scope = Scope(); let henrietta = - s.handle({name:~"henrietta", + s.handle(&{name:~"henrietta", species:chicken(~{mut eggs_per_day:0u})}); let ferdinand = - s.handle({name:~"ferdinand", + s.handle(&{name:~"ferdinand", species:bull(~{mut horns:0u})}); let iter1 = 3u; @@ -294,9 +295,9 @@ mod test { for uint::range(0u, iter2) |_i| { assert hrc == comm::recv(read_port); - s.write(henrietta, mutate); + s.write(&henrietta, mutate); assert frc == comm::recv(read_port); - s.write(ferdinand, mutate); + s.write(&ferdinand, mutate); comm::send(wait_chan, ()); } s.reader_joined(); diff --git a/src/servo/engine.rs b/src/servo/engine.rs index ace4fdd900b..0965744cf02 100644 --- a/src/servo/engine.rs +++ b/src/servo/engine.rs @@ -22,9 +22,9 @@ pub struct Engine { content_task: ContentTask } -pub fn Engine(compositor: C, - resource_task: ResourceTask, - image_cache_task: ImageCacheTask) -> Engine { +pub fn Engine(+compositor: C, + +resource_task: ResourceTask, + +image_cache_task: ImageCacheTask) -> Engine { let render_task = RenderTask(compositor); let layout_task = LayoutTask(render_task, image_cache_task); let content_task = ContentTask(layout_task, compositor, resource_task, image_cache_task); @@ -48,7 +48,7 @@ impl Engine { } } - fn handle_request(request: Msg) -> bool { + fn handle_request(+request: Msg) -> bool { match request { LoadURLMsg(url) => { // TODO: change copy to move once we have match move diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index 79af4717e06..1616de10d6a 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -86,7 +86,7 @@ impl Layout { match query { ContentBox(node) => { // TODO: extract me to a method when I get sibling arms - let response = match node.aux(|a| a).flow { + let response = match node.aux(|a| *a).flow { None => Err(()), Some(flow) => { let start_val : Option> = None;