script: Eliminate the phantom type in Node, as it is no longer needed

for enforcing layout memory safety.
This commit is contained in:
Patrick Walton 2013-12-17 15:03:37 -08:00
parent 8f886e599e
commit 436b1e891d
10 changed files with 33 additions and 45 deletions

View file

@ -19,8 +19,7 @@ use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementType
use script::dom::element::{HTMLLinkElementTypeId}; use script::dom::element::{HTMLLinkElementTypeId};
use script::dom::htmliframeelement::HTMLIFrameElement; use script::dom::htmliframeelement::HTMLIFrameElement;
use script::dom::htmlimageelement::HTMLImageElement; use script::dom::htmlimageelement::HTMLImageElement;
use script::dom::node::{AbstractNode, DocumentNodeTypeId, ElementNodeTypeId, LayoutView, Node}; use script::dom::node::{AbstractNode, DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId};
use script::dom::node::{NodeTypeId};
use script::dom::text::Text; use script::dom::text::Text;
use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_msg::constellation_msg::{PipelineId, SubpageId};
use std::cast; 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 /// Returns the interior of this node as a `Node`. This is highly unsafe for layout to call
/// and as such is marked `unsafe`. /// and as such is marked `unsafe`.
pub unsafe fn get<'a>(&'a self) -> &'a Node<LayoutView> { pub unsafe fn get<'a>(&'a self) -> &'a Node {
cast::transmute(self.node.node()) cast::transmute(self.node.node())
} }

View file

@ -303,7 +303,7 @@ DOMInterfaces = {
'Node': { 'Node': {
'nativeType': 'AbstractNode', 'nativeType': 'AbstractNode',
'concreteType': 'Node<ScriptView>', 'concreteType': 'Node',
'pointerType': '', 'pointerType': '',
'needsAbstract': [ 'needsAbstract': [
'appendChild', 'appendChild',

View file

@ -5161,7 +5161,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::proxyhandler', 'dom::bindings::proxyhandler',
'dom::bindings::proxyhandler::*', 'dom::bindings::proxyhandler::*',
'dom::document::AbstractDocument', 'dom::document::AbstractDocument',
'dom::node::{AbstractNode, ScriptView}', 'dom::node::AbstractNode',
'dom::eventtarget::AbstractEventTarget', 'dom::eventtarget::AbstractEventTarget',
'dom::event::AbstractEvent', 'dom::event::AbstractEvent',
'servo_util::vec::zip_copies', 'servo_util::vec::zip_copies',

View file

@ -4,7 +4,7 @@
use dom::bindings::utils::{Reflectable, Reflector, Traceable}; use dom::bindings::utils::{Reflectable, Reflector, Traceable};
use dom::types::*; use dom::types::*;
use dom::node::{AbstractNode, ScriptView}; use dom::node::AbstractNode;
use std::cast; use std::cast;
use std::libc; use std::libc;
@ -21,7 +21,7 @@ impl Reflectable for AbstractNode {
} }
} }
impl Traceable for Node<ScriptView> { impl Traceable for Node {
fn trace(&self, tracer: *mut JSTracer) { fn trace(&self, tracer: *mut JSTracer) {
#[fixed_stack_segment] #[fixed_stack_segment]
fn trace_node(tracer: *mut JSTracer, node: Option<AbstractNode>, name: &str) { fn trace_node(tracer: *mut JSTracer, node: Option<AbstractNode>, name: &str) {

View file

@ -7,10 +7,10 @@
use dom::bindings::utils::{DOMString, ErrorResult, Fallible}; use dom::bindings::utils::{DOMString, ErrorResult, Fallible};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::node::{Node, NodeTypeId, ScriptView}; use dom::node::{Node, NodeTypeId};
pub struct CharacterData { pub struct CharacterData {
node: Node<ScriptView>, node: Node,
data: ~str data: ~str
} }

View file

@ -15,7 +15,7 @@ use dom::event::{AbstractEvent, Event};
use dom::htmlcollection::HTMLCollection; use dom::htmlcollection::HTMLCollection;
use dom::htmldocument::HTMLDocument; use dom::htmldocument::HTMLDocument;
use dom::mouseevent::MouseEvent; 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::text::Text;
use dom::uievent::UIEvent; use dom::uievent::UIEvent;
use dom::window::Window; use dom::window::Window;
@ -86,7 +86,7 @@ pub enum DocumentType {
} }
pub struct Document { pub struct Document {
node: Node<ScriptView>, node: Node,
reflector_: Reflector, reflector_: Reflector,
window: @mut Window, window: @mut Window,
doctype: DocumentType, doctype: DocumentType,

View file

@ -5,12 +5,11 @@
use dom::bindings::codegen::DocumentFragmentBinding; use dom::bindings::codegen::DocumentFragmentBinding;
use dom::bindings::utils::Fallible; use dom::bindings::utils::Fallible;
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::node::{ScriptView, Node, DocumentFragmentNodeTypeId}; use dom::node::{AbstractNode, DocumentFragmentNodeTypeId, Node};
use dom::node::{AbstractNode};
use dom::window::Window; use dom::window::Window;
pub struct DocumentFragment { pub struct DocumentFragment {
node: Node<ScriptView>, node: Node,
} }
impl DocumentFragment { impl DocumentFragment {

View file

@ -5,11 +5,11 @@
use dom::bindings::codegen::DocumentTypeBinding; use dom::bindings::codegen::DocumentTypeBinding;
use dom::bindings::utils::DOMString; use dom::bindings::utils::DOMString;
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::node::{AbstractNode, ScriptView, Node, DoctypeNodeTypeId}; use dom::node::{AbstractNode, Node, DoctypeNodeTypeId};
/// The `DOCTYPE` tag. /// The `DOCTYPE` tag.
pub struct DocumentType { pub struct DocumentType {
node: Node<ScriptView>, node: Node,
name: DOMString, name: DOMString,
public_id: DOMString, public_id: DOMString,
system_id: DOMString, system_id: DOMString,

View file

@ -4,6 +4,7 @@
//! Element nodes. //! Element nodes.
use dom::attr::Attr;
use dom::attrlist::AttrList; use dom::attrlist::AttrList;
use dom::bindings::utils::{Reflectable, DOMString, ErrorResult, Fallible, Reflector}; use dom::bindings::utils::{Reflectable, DOMString, ErrorResult, Fallible, Reflector};
use dom::bindings::utils::{null_str_as_empty, NamespaceError}; use dom::bindings::utils::{null_str_as_empty, NamespaceError};
@ -12,8 +13,7 @@ use dom::htmlcollection::HTMLCollection;
use dom::clientrect::ClientRect; use dom::clientrect::ClientRect;
use dom::clientrectlist::ClientRectList; use dom::clientrectlist::ClientRectList;
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode}; use dom::node::{AbstractNode, ElementNodeTypeId, Node};
use dom::attr:: Attr;
use dom::document; use dom::document;
use dom::namespace; use dom::namespace;
use dom::namespace::Namespace; use dom::namespace::Namespace;
@ -28,7 +28,7 @@ use std::str::{eq, eq_slice};
use std::ascii::StrAsciiExt; use std::ascii::StrAsciiExt;
pub struct Element { pub struct Element {
node: Node<ScriptView>, node: Node,
tag_name: ~str, // TODO: This should be an atom, not a ~str. tag_name: ~str, // TODO: This should be an atom, not a ~str.
namespace: Namespace, namespace: Namespace,
attrs: HashMap<~str, ~[@mut Attr]>, attrs: HashMap<~str, ~[@mut Attr]>,

View file

@ -36,17 +36,11 @@ use std::util;
/// FIXME: This should be replaced with a trait once they can inherit from structs. /// FIXME: This should be replaced with a trait once they can inherit from structs.
#[deriving(Eq)] #[deriving(Eq)]
pub struct AbstractNode { pub struct AbstractNode {
priv obj: *mut Box<Node<ScriptView>>, priv obj: *mut Box<Node>,
} }
/// 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. /// An HTML node.
pub struct Node<View> { pub struct Node {
/// The JavaScript reflector for this node. /// The JavaScript reflector for this node.
eventtarget: EventTarget, eventtarget: EventTarget,
@ -104,10 +98,10 @@ impl NodeFlags {
bitfield!(NodeFlags, is_in_doc, set_is_in_doc, 0x01) bitfield!(NodeFlags, is_in_doc, set_is_in_doc, 0x01)
#[unsafe_destructor] #[unsafe_destructor]
impl<T> Drop for Node<T> { impl Drop for Node {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let this: &mut Node<ScriptView> = cast::transmute(self); let this: &mut Node = cast::transmute(self);
this.reap_layout_data() this.reap_layout_data()
} }
} }
@ -196,13 +190,13 @@ impl Clone for AbstractNode {
} }
impl AbstractNode { impl AbstractNode {
pub fn node<'a>(&'a self) -> &'a Node<ScriptView> { pub fn node<'a>(&'a self) -> &'a Node {
unsafe { unsafe {
&(*self.obj).data &(*self.obj).data
} }
} }
pub fn mut_node<'a>(&'a self) -> &'a mut Node<ScriptView> { pub fn mut_node<'a>(&'a self) -> &'a mut Node {
unsafe { unsafe {
&mut (*self.obj).data &mut (*self.obj).data
} }
@ -257,7 +251,7 @@ impl<'self> AbstractNode {
/// FIXME(pcwalton): Mark unsafe? /// FIXME(pcwalton): Mark unsafe?
pub fn from_box<T>(ptr: *mut Box<T>) -> AbstractNode { pub fn from_box<T>(ptr: *mut Box<T>) -> AbstractNode {
AbstractNode { AbstractNode {
obj: ptr as *mut Box<Node<ScriptView>> obj: ptr as *mut Box<Node>
} }
} }
@ -298,7 +292,7 @@ impl<'self> AbstractNode {
pub fn transmute<T, R>(self, f: &fn(&T) -> R) -> R { pub fn transmute<T, R>(self, f: &fn(&T) -> R) -> R {
unsafe { unsafe {
let node_box: *mut Box<Node<ScriptView>> = transmute(self.obj); let node_box: *mut Box<Node> = transmute(self.obj);
let node = &mut (*node_box).data; let node = &mut (*node_box).data;
let old = node.abstract; let old = node.abstract;
node.abstract = Some(self); node.abstract = Some(self);
@ -311,7 +305,7 @@ impl<'self> AbstractNode {
pub fn transmute_mut<T, R>(self, f: &fn(&mut T) -> R) -> R { pub fn transmute_mut<T, R>(self, f: &fn(&mut T) -> R) -> R {
unsafe { unsafe {
let node_box: *mut Box<Node<ScriptView>> = transmute(self.obj); let node_box: *mut Box<Node> = transmute(self.obj);
let node = &mut (*node_box).data; let node = &mut (*node_box).data;
let old = node.abstract; let old = node.abstract;
node.abstract = Some(self); node.abstract = Some(self);
@ -444,11 +438,11 @@ impl<'self> AbstractNode {
self.type_id() == ElementNodeTypeId(HTMLAnchorElementTypeId) self.type_id() == ElementNodeTypeId(HTMLAnchorElementTypeId)
} }
pub unsafe fn raw_object(self) -> *mut Box<Node<ScriptView>> { pub unsafe fn raw_object(self) -> *mut Box<Node> {
self.obj self.obj
} }
pub fn from_raw(raw: *mut Box<Node<ScriptView>>) -> AbstractNode { pub fn from_raw(raw: *mut Box<Node>) -> AbstractNode {
AbstractNode { AbstractNode {
obj: raw obj: raw
} }
@ -736,13 +730,11 @@ impl AbstractNode {
} }
} }
impl<View> Node<View> { impl Node {
pub fn owner_doc(&self) -> AbstractDocument { pub fn owner_doc(&self) -> AbstractDocument {
self.owner_doc.unwrap() self.owner_doc.unwrap()
} }
}
impl Node<ScriptView> {
pub fn set_owner_doc(&mut self, document: AbstractDocument) { pub fn set_owner_doc(&mut self, document: AbstractDocument) {
self.owner_doc = Some(document); self.owner_doc = Some(document);
} }
@ -767,15 +759,15 @@ impl Node<ScriptView> {
} }
} }
pub fn new_inherited(type_id: NodeTypeId, doc: AbstractDocument) -> Node<ScriptView> { pub fn new_inherited(type_id: NodeTypeId, doc: AbstractDocument) -> Node {
Node::new_(type_id, Some(doc)) Node::new_(type_id, Some(doc))
} }
pub fn new_without_doc(type_id: NodeTypeId) -> Node<ScriptView> { pub fn new_without_doc(type_id: NodeTypeId) -> Node {
Node::new_(type_id, None) Node::new_(type_id, None)
} }
fn new_(type_id: NodeTypeId, doc: Option<AbstractDocument>) -> Node<ScriptView> { fn new_(type_id: NodeTypeId, doc: Option<AbstractDocument>) -> Node {
Node { Node {
eventtarget: EventTarget::new_inherited(NodeTypeId), eventtarget: EventTarget::new_inherited(NodeTypeId),
type_id: type_id, type_id: type_id,
@ -805,9 +797,7 @@ impl Node<ScriptView> {
(*js_window).data.page.reap_dead_layout_data(layout_data) (*js_window).data.page.reap_dead_layout_data(layout_data)
} }
} }
}
impl Node<ScriptView> {
// http://dom.spec.whatwg.org/#dom-node-nodetype // http://dom.spec.whatwg.org/#dom-node-nodetype
pub fn NodeType(&self) -> u16 { pub fn NodeType(&self) -> u16 {
match self.type_id { match self.type_id {
@ -1367,7 +1357,7 @@ impl Node<ScriptView> {
} }
} }
impl Reflectable for Node<ScriptView> { impl Reflectable for Node {
fn reflector<'a>(&'a self) -> &'a Reflector { fn reflector<'a>(&'a self) -> &'a Reflector {
self.eventtarget.reflector() self.eventtarget.reflector()
} }