Privatize DocumentType

This commit is contained in:
Tim Taubert 2014-10-12 12:57:15 +02:00
parent e15f8cb37f
commit ba073d7e99
3 changed files with 28 additions and 12 deletions

View file

@ -15,11 +15,12 @@ use servo_util::str::DOMString;
/// The `DOCTYPE` tag.
#[jstraceable]
#[must_root]
#[privatize]
pub struct DocumentType {
pub node: Node,
pub name: DOMString,
pub public_id: DOMString,
pub system_id: DOMString,
node: Node,
name: DOMString,
public_id: DOMString,
system_id: DOMString,
}
impl DocumentTypeDerived for EventTarget {
@ -53,6 +54,21 @@ impl DocumentType {
document);
Node::reflect_node(box documenttype, document, DocumentTypeBinding::Wrap)
}
#[inline]
pub fn name<'a>(&'a self) -> &'a DOMString {
&self.name
}
#[inline]
pub fn public_id<'a>(&'a self) -> &'a DOMString {
&self.public_id
}
#[inline]
pub fn system_id<'a>(&'a self) -> &'a DOMString {
&self.system_id
}
}
impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {

View file

@ -101,7 +101,7 @@ fn serialize_processing_instruction(processing_instruction: JSRef<ProcessingInst
fn serialize_doctype(doctype: JSRef<DocumentType>, html: &mut String) {
html.push_str("<!DOCTYPE");
html.push_str(doctype.name.as_slice());
html.push_str(doctype.name().as_slice());
html.push_char('>');
}

View file

@ -1458,9 +1458,9 @@ impl Node {
let copy: Root<Node> = match node.type_id() {
DoctypeNodeTypeId => {
let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
let doctype = DocumentType::new(doctype.name.clone(),
Some(doctype.public_id.clone()),
Some(doctype.system_id.clone()), *document);
let doctype = DocumentType::new(doctype.name().clone(),
Some(doctype.public_id().clone()),
Some(doctype.system_id().clone()), *document);
NodeCast::from_temporary(doctype)
},
DocumentFragmentNodeTypeId => {
@ -1612,7 +1612,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
CommentNodeTypeId => "#comment".to_string(),
DoctypeNodeTypeId => {
let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
doctype.name.clone()
doctype.name().clone()
},
DocumentFragmentNodeTypeId => "#document-fragment".to_string(),
DocumentNodeTypeId => "#document".to_string()
@ -1959,9 +1959,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
fn is_equal_doctype(node: JSRef<Node>, other: JSRef<Node>) -> bool {
let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
let other_doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap();
(doctype.name == other_doctype.name) &&
(doctype.public_id == other_doctype.public_id) &&
(doctype.system_id == other_doctype.system_id)
(*doctype.name() == *other_doctype.name()) &&
(*doctype.public_id() == *other_doctype.public_id()) &&
(*doctype.system_id() == *other_doctype.system_id())
}
fn is_equal_element(node: JSRef<Node>, other: JSRef<Node>) -> bool {
let element: JSRef<Element> = ElementCast::to_ref(node).unwrap();