diff options
author | Rohan Prinja <rohan.prinja@gmail.com> | 2014-11-22 14:41:47 +0530 |
---|---|---|
committer | Rohan Prinja <rohan.prinja@gmail.com> | 2014-11-23 14:51:04 +0530 |
commit | 4b754bd457309b76b10f9f665753f85d3dd632d0 (patch) | |
tree | 5020fcde350f5d52abb7f6fd1fabbb73c9819095 /components/script/dom/document.rs | |
parent | b4c3aec383b2b1cd19ab6267775f9fb3735aa977 (diff) | |
download | servo-4b754bd457309b76b10f9f665753f85d3dd632d0.tar.gz servo-4b754bd457309b76b10f9f665753f85d3dd632d0.zip |
implement Document#createAttribute
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index eaa4f2ca840..538678d31f7 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::AttrHelpers; +use dom::attr::{Attr, AttrHelpers, StringAttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; @@ -622,6 +622,22 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { ScriptCreated)) } + // http://dom.spec.whatwg.org/#dom-document-createattribute + fn CreateAttribute(self, local_name: DOMString) -> Fallible<Temporary<Attr>> { + if xml_name_type(local_name.as_slice()) == InvalidXMLName { + debug!("Not a valid element name"); + return Err(InvalidCharacter); + } + + let window = self.window.root(); + let name = Atom::from_slice(local_name.as_slice()); + // repetition used because string_cache::atom::Atom is non-copyable + let l_name = Atom::from_slice(local_name.as_slice()); + let value = StringAttrValue("".to_string()); + + Ok(Attr::new(*window, name, value, l_name, ns!(""), None, None)) + } + // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment fn CreateDocumentFragment(self) -> Temporary<DocumentFragment> { DocumentFragment::new(self) |