aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/domimplementation.rs
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-04-08 22:44:45 -0400
committerBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-04-21 09:30:36 -0300
commit41898f0a7696848aef1fcf49df151e5295d261b3 (patch)
tree902393598c6e333e8bc90783a2882ae5f30d87eb /src/components/script/dom/domimplementation.rs
parentbb8a037cb249ee0bc17c16b7ce7b7df0222ee66e (diff)
downloadservo-41898f0a7696848aef1fcf49df151e5295d261b3.tar.gz
servo-41898f0a7696848aef1fcf49df151e5295d261b3.zip
Implement DOMImplementation::createDocument
Spec: http://dom.spec.whatwg.org/#dom-domimplementation-createdocument Closes #1509.
Diffstat (limited to 'src/components/script/dom/domimplementation.rs')
-rw-r--r--src/components/script/dom/domimplementation.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs
index 71f63f52066..aaf4d427b9f 100644
--- a/src/components/script/dom/domimplementation.rs
+++ b/src/components/script/dom/domimplementation.rs
@@ -8,7 +8,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::error::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
-use dom::document::{Document, HTMLDocument};
+use dom::document::{Document, HTMLDocument, NonHTMLDocument};
use dom::documenttype::DocumentType;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement;
@@ -63,6 +63,42 @@ impl DOMImplementation {
}
}
+ // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument
+ pub fn CreateDocument(&self, namespace: Option<DOMString>, qname: DOMString,
+ maybe_doctype: Option<JS<DocumentType>>) -> Fallible<JS<Document>> {
+ // Step 1.
+ let doc = Document::new(&self.owner, None, NonHTMLDocument, None);
+ let mut doc_node: JS<Node> = NodeCast::from(&doc);
+
+ // Step 2-3.
+ let maybe_elem = if qname.is_empty() {
+ None
+ } else {
+ match doc.get().CreateElementNS(&doc, namespace, qname) {
+ Err(error) => return Err(error),
+ Ok(elem) => Some(elem)
+ }
+ };
+
+ // Step 4.
+ match maybe_doctype {
+ None => (),
+ Some(ref doctype) => assert!(doc_node.AppendChild(&mut NodeCast::from(doctype)).is_ok())
+ }
+
+ // Step 5.
+ match maybe_elem {
+ None => (),
+ Some(ref elem) => assert!(doc_node.AppendChild(&mut NodeCast::from(elem)).is_ok())
+ }
+
+ // Step 6.
+ // FIXME: https://github.com/mozilla/servo/issues/1522
+
+ // Step 7.
+ Ok(doc)
+ }
+
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> {
// Step 1-2.