implement Document#createAttribute

This commit is contained in:
Rohan Prinja 2014-11-22 14:41:47 +05:30
parent b4c3aec383
commit 4b754bd457
8 changed files with 43 additions and 66 deletions

View file

@ -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)