From 4b754bd457309b76b10f9f665753f85d3dd632d0 Mon Sep 17 00:00:00 2001 From: Rohan Prinja Date: Sat, 22 Nov 2014 14:41:47 +0530 Subject: implement Document#createAttribute --- components/script/dom/document.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'components/script/dom/document.rs') 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> { + 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::new(self) -- cgit v1.2.3