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

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

View file

@ -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',

View file

@ -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<ScriptView> {
impl Traceable for Node {
fn trace(&self, tracer: *mut JSTracer) {
#[fixed_stack_segment]
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::{Reflectable, Reflector};
use dom::document::AbstractDocument;
use dom::node::{Node, NodeTypeId, ScriptView};
use dom::node::{Node, NodeTypeId};
pub struct CharacterData {
node: Node<ScriptView>,
node: Node,
data: ~str
}

View file

@ -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<ScriptView>,
node: Node,
reflector_: Reflector,
window: @mut Window,
doctype: DocumentType,

View file

@ -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<ScriptView>,
node: Node,
}
impl DocumentFragment {

View file

@ -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<ScriptView>,
node: Node,
name: DOMString,
public_id: DOMString,
system_id: DOMString,

View file

@ -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<ScriptView>,
node: Node,
tag_name: ~str, // TODO: This should be an atom, not a ~str.
namespace: Namespace,
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.
#[deriving(Eq)]
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.
pub struct Node<View> {
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<T> Drop for Node<T> {
impl Drop for Node {
fn drop(&mut self) {
unsafe {
let this: &mut Node<ScriptView> = 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<ScriptView> {
pub fn node<'a>(&'a self) -> &'a Node {
unsafe {
&(*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 {
&mut (*self.obj).data
}
@ -257,7 +251,7 @@ impl<'self> AbstractNode {
/// FIXME(pcwalton): Mark unsafe?
pub fn from_box<T>(ptr: *mut Box<T>) -> 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 {
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 old = node.abstract;
node.abstract = Some(self);
@ -311,7 +305,7 @@ impl<'self> AbstractNode {
pub fn transmute_mut<T, R>(self, f: &fn(&mut T) -> R) -> R {
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 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<Node<ScriptView>> {
pub unsafe fn raw_object(self) -> *mut Box<Node> {
self.obj
}
pub fn from_raw(raw: *mut Box<Node<ScriptView>>) -> AbstractNode {
pub fn from_raw(raw: *mut Box<Node>) -> AbstractNode {
AbstractNode {
obj: raw
}
@ -736,13 +730,11 @@ impl AbstractNode {
}
}
impl<View> Node<View> {
impl Node {
pub fn owner_doc(&self) -> AbstractDocument {
self.owner_doc.unwrap()
}
}
impl Node<ScriptView> {
pub fn set_owner_doc(&mut self, document: AbstractDocument) {
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))
}
pub fn new_without_doc(type_id: NodeTypeId) -> Node<ScriptView> {
pub fn new_without_doc(type_id: NodeTypeId) -> Node {
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 {
eventtarget: EventTarget::new_inherited(NodeTypeId),
type_id: type_id,
@ -805,9 +797,7 @@ impl Node<ScriptView> {
(*js_window).data.page.reap_dead_layout_data(layout_data)
}
}
}
impl Node<ScriptView> {
// http://dom.spec.whatwg.org/#dom-node-nodetype
pub fn NodeType(&self) -> u16 {
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 {
self.eventtarget.reflector()
}