From 436b1e891d5a6885e4004d110f707a2a665b5c34 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 17 Dec 2013 15:03:37 -0800 Subject: [PATCH] script: Eliminate the phantom type in `Node`, as it is no longer needed for enforcing layout memory safety. --- src/components/main/layout/wrapper.rs | 5 +-- .../script/dom/bindings/codegen/Bindings.conf | 2 +- .../dom/bindings/codegen/CodegenRust.py | 2 +- src/components/script/dom/bindings/node.rs | 4 +- src/components/script/dom/characterdata.rs | 4 +- src/components/script/dom/document.rs | 4 +- src/components/script/dom/documentfragment.rs | 5 +-- src/components/script/dom/documenttype.rs | 4 +- src/components/script/dom/element.rs | 6 +-- src/components/script/dom/node.rs | 42 +++++++------------ 10 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index ace4c9683c5..6ab1504df85 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -19,8 +19,7 @@ use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementType use script::dom::element::{HTMLLinkElementTypeId}; use script::dom::htmliframeelement::HTMLIFrameElement; use script::dom::htmlimageelement::HTMLImageElement; -use script::dom::node::{AbstractNode, DocumentNodeTypeId, ElementNodeTypeId, LayoutView, Node}; -use script::dom::node::{NodeTypeId}; +use script::dom::node::{AbstractNode, DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId}; use script::dom::text::Text; use servo_msg::constellation_msg::{PipelineId, SubpageId}; use std::cast; @@ -57,7 +56,7 @@ impl<'self> LayoutNode<'self> { /// Returns the interior of this node as a `Node`. This is highly unsafe for layout to call /// and as such is marked `unsafe`. - pub unsafe fn get<'a>(&'a self) -> &'a Node { + pub unsafe fn get<'a>(&'a self) -> &'a Node { cast::transmute(self.node.node()) } diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index daeae22bb31..b7e01242793 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -303,7 +303,7 @@ DOMInterfaces = { 'Node': { 'nativeType': 'AbstractNode', - 'concreteType': 'Node', + 'concreteType': 'Node', 'pointerType': '', 'needsAbstract': [ 'appendChild', diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 23359cae5fc..b426c2989ed 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -5161,7 +5161,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::proxyhandler', 'dom::bindings::proxyhandler::*', 'dom::document::AbstractDocument', - 'dom::node::{AbstractNode, ScriptView}', + 'dom::node::AbstractNode', 'dom::eventtarget::AbstractEventTarget', 'dom::event::AbstractEvent', 'servo_util::vec::zip_copies', diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs index a3b18c278f7..cdc4c58bce0 100644 --- a/src/components/script/dom/bindings/node.rs +++ b/src/components/script/dom/bindings/node.rs @@ -4,7 +4,7 @@ use dom::bindings::utils::{Reflectable, Reflector, Traceable}; use dom::types::*; -use dom::node::{AbstractNode, ScriptView}; +use dom::node::AbstractNode; use std::cast; use std::libc; @@ -21,7 +21,7 @@ impl Reflectable for AbstractNode { } } -impl Traceable for Node { +impl Traceable for Node { fn trace(&self, tracer: *mut JSTracer) { #[fixed_stack_segment] fn trace_node(tracer: *mut JSTracer, node: Option, name: &str) { diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index dbdf67f92c5..bf3c81fd0c5 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -7,10 +7,10 @@ use dom::bindings::utils::{DOMString, ErrorResult, Fallible}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::AbstractDocument; -use dom::node::{Node, NodeTypeId, ScriptView}; +use dom::node::{Node, NodeTypeId}; pub struct CharacterData { - node: Node, + node: Node, data: ~str } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 3e5b5dd60a2..0e366f76a80 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -15,7 +15,7 @@ use dom::event::{AbstractEvent, Event}; use dom::htmlcollection::HTMLCollection; use dom::htmldocument::HTMLDocument; use dom::mouseevent::MouseEvent; -use dom::node::{AbstractNode, ScriptView, Node, ElementNodeTypeId, DocumentNodeTypeId}; +use dom::node::{AbstractNode, Node, ElementNodeTypeId, DocumentNodeTypeId}; use dom::text::Text; use dom::uievent::UIEvent; use dom::window::Window; @@ -86,7 +86,7 @@ pub enum DocumentType { } pub struct Document { - node: Node, + node: Node, reflector_: Reflector, window: @mut Window, doctype: DocumentType, diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index fdee1c68aca..0b4c56d2c92 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -5,12 +5,11 @@ use dom::bindings::codegen::DocumentFragmentBinding; use dom::bindings::utils::Fallible; use dom::document::AbstractDocument; -use dom::node::{ScriptView, Node, DocumentFragmentNodeTypeId}; -use dom::node::{AbstractNode}; +use dom::node::{AbstractNode, DocumentFragmentNodeTypeId, Node}; use dom::window::Window; pub struct DocumentFragment { - node: Node, + node: Node, } impl DocumentFragment { diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index a15db60e415..66e731e724b 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -5,11 +5,11 @@ use dom::bindings::codegen::DocumentTypeBinding; use dom::bindings::utils::DOMString; use dom::document::AbstractDocument; -use dom::node::{AbstractNode, ScriptView, Node, DoctypeNodeTypeId}; +use dom::node::{AbstractNode, Node, DoctypeNodeTypeId}; /// The `DOCTYPE` tag. pub struct DocumentType { - node: Node, + node: Node, name: DOMString, public_id: DOMString, system_id: DOMString, diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 10a7b4865ec..31dd20596f4 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -4,6 +4,7 @@ //! Element nodes. +use dom::attr::Attr; use dom::attrlist::AttrList; use dom::bindings::utils::{Reflectable, DOMString, ErrorResult, Fallible, Reflector}; use dom::bindings::utils::{null_str_as_empty, NamespaceError}; @@ -12,8 +13,7 @@ use dom::htmlcollection::HTMLCollection; use dom::clientrect::ClientRect; use dom::clientrectlist::ClientRectList; use dom::document::AbstractDocument; -use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode}; -use dom::attr:: Attr; +use dom::node::{AbstractNode, ElementNodeTypeId, Node}; use dom::document; use dom::namespace; use dom::namespace::Namespace; @@ -28,7 +28,7 @@ use std::str::{eq, eq_slice}; use std::ascii::StrAsciiExt; pub struct Element { - node: Node, + node: Node, tag_name: ~str, // TODO: This should be an atom, not a ~str. namespace: Namespace, attrs: HashMap<~str, ~[@mut Attr]>, diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 40088abf6c7..53296d12da7 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -36,17 +36,11 @@ use std::util; /// FIXME: This should be replaced with a trait once they can inherit from structs. #[deriving(Eq)] pub struct AbstractNode { - priv obj: *mut Box>, + priv obj: *mut Box, } -/// The script task's mutable view of a node. -pub struct ScriptView; - -/// The layout task's mutable view of a node. -pub struct LayoutView; - /// An HTML node. -pub struct Node { +pub struct Node { /// The JavaScript reflector for this node. eventtarget: EventTarget, @@ -104,10 +98,10 @@ impl NodeFlags { bitfield!(NodeFlags, is_in_doc, set_is_in_doc, 0x01) #[unsafe_destructor] -impl Drop for Node { +impl Drop for Node { fn drop(&mut self) { unsafe { - let this: &mut Node = cast::transmute(self); + let this: &mut Node = cast::transmute(self); this.reap_layout_data() } } @@ -196,13 +190,13 @@ impl Clone for AbstractNode { } impl AbstractNode { - pub fn node<'a>(&'a self) -> &'a Node { + pub fn node<'a>(&'a self) -> &'a Node { unsafe { &(*self.obj).data } } - pub fn mut_node<'a>(&'a self) -> &'a mut Node { + pub fn mut_node<'a>(&'a self) -> &'a mut Node { unsafe { &mut (*self.obj).data } @@ -257,7 +251,7 @@ impl<'self> AbstractNode { /// FIXME(pcwalton): Mark unsafe? pub fn from_box(ptr: *mut Box) -> AbstractNode { AbstractNode { - obj: ptr as *mut Box> + obj: ptr as *mut Box } } @@ -298,7 +292,7 @@ impl<'self> AbstractNode { pub fn transmute(self, f: &fn(&T) -> R) -> R { unsafe { - let node_box: *mut Box> = transmute(self.obj); + let node_box: *mut Box = transmute(self.obj); let node = &mut (*node_box).data; let old = node.abstract; node.abstract = Some(self); @@ -311,7 +305,7 @@ impl<'self> AbstractNode { pub fn transmute_mut(self, f: &fn(&mut T) -> R) -> R { unsafe { - let node_box: *mut Box> = transmute(self.obj); + let node_box: *mut Box = transmute(self.obj); let node = &mut (*node_box).data; let old = node.abstract; node.abstract = Some(self); @@ -444,11 +438,11 @@ impl<'self> AbstractNode { self.type_id() == ElementNodeTypeId(HTMLAnchorElementTypeId) } - pub unsafe fn raw_object(self) -> *mut Box> { + pub unsafe fn raw_object(self) -> *mut Box { self.obj } - pub fn from_raw(raw: *mut Box>) -> AbstractNode { + pub fn from_raw(raw: *mut Box) -> AbstractNode { AbstractNode { obj: raw } @@ -736,13 +730,11 @@ impl AbstractNode { } } -impl Node { +impl Node { pub fn owner_doc(&self) -> AbstractDocument { self.owner_doc.unwrap() } -} -impl Node { pub fn set_owner_doc(&mut self, document: AbstractDocument) { self.owner_doc = Some(document); } @@ -767,15 +759,15 @@ impl Node { } } - pub fn new_inherited(type_id: NodeTypeId, doc: AbstractDocument) -> Node { + pub fn new_inherited(type_id: NodeTypeId, doc: AbstractDocument) -> Node { Node::new_(type_id, Some(doc)) } - pub fn new_without_doc(type_id: NodeTypeId) -> Node { + pub fn new_without_doc(type_id: NodeTypeId) -> Node { Node::new_(type_id, None) } - fn new_(type_id: NodeTypeId, doc: Option) -> Node { + fn new_(type_id: NodeTypeId, doc: Option) -> Node { Node { eventtarget: EventTarget::new_inherited(NodeTypeId), type_id: type_id, @@ -805,9 +797,7 @@ impl Node { (*js_window).data.page.reap_dead_layout_data(layout_data) } } -} -impl Node { // http://dom.spec.whatwg.org/#dom-node-nodetype pub fn NodeType(&self) -> u16 { match self.type_id { @@ -1367,7 +1357,7 @@ impl Node { } } -impl Reflectable for Node { +impl Reflectable for Node { fn reflector<'a>(&'a self) -> &'a Reflector { self.eventtarget.reflector() }