Skip to content

Commit

Permalink
Make Element.remove_attribute take &str instead of DOMString
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Jul 13, 2014
1 parent e6f2342 commit 130cf76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/components/script/dom/document.rs
Expand Up @@ -439,7 +439,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
QName => {}
}

let (prefix_from_qname, local_name_from_qname) = get_attribute_parts(qualified_name);
let (prefix_from_qname,
local_name_from_qname) = get_attribute_parts(qualified_name.as_slice());
match (&ns, prefix_from_qname.clone(), local_name_from_qname.as_slice()) {
// throw if prefix is not null and namespace is null
(&namespace::Null, Some(_), _) => {
Expand Down
20 changes: 10 additions & 10 deletions src/components/script/dom/element.rs
Expand Up @@ -230,7 +230,7 @@ pub trait AttributeHandlers {
fn parse_attribute(&self, namespace: &Namespace, local_name: &str,
value: DOMString) -> AttrValue;

fn remove_attribute(&self, namespace: Namespace, name: DOMString) -> ErrorResult;
fn remove_attribute(&self, namespace: Namespace, name: &str) -> ErrorResult;
fn notify_attribute_changed(&self, local_name: DOMString);
fn has_class(&self, name: &str) -> bool;

Expand Down Expand Up @@ -313,8 +313,8 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
}

fn remove_attribute(&self, namespace: Namespace, name: DOMString) -> ErrorResult {
let (_, local_name) = get_attribute_parts(name.clone());
fn remove_attribute(&self, namespace: Namespace, name: &str) -> ErrorResult {
let (_, local_name) = get_attribute_parts(name);

let idx = self.deref().attrs.borrow().iter().map(|attr| attr.root()).position(|attr| {
attr.local_name == local_name
Expand Down Expand Up @@ -603,7 +603,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
}

// Step 4.
let (prefix, local_name) = get_attribute_parts(name.clone());
let (prefix, local_name) = get_attribute_parts(name.as_slice());
match prefix {
Some(ref prefix_str) => {
// Step 5.
Expand Down Expand Up @@ -651,15 +651,15 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
} else {
name
};
self.remove_attribute(namespace::Null, name)
self.remove_attribute(namespace::Null, name.as_slice())
}

// http://dom.spec.whatwg.org/#dom-element-removeattributens
fn RemoveAttributeNS(&self,
namespace: Option<DOMString>,
localname: DOMString) -> ErrorResult {
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
self.remove_attribute(namespace, localname)
self.remove_attribute(namespace, localname.as_slice())
}

// http://dom.spec.whatwg.org/#dom-element-hasattribute
Expand Down Expand Up @@ -759,14 +759,14 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
}
}

pub fn get_attribute_parts(name: DOMString) -> (Option<String>, String) {
pub fn get_attribute_parts(name: &str) -> (Option<String>, String) {
//FIXME: Throw for XML-invalid names
//FIXME: Throw for XMLNS-invalid names
let (prefix, local_name) = if name.as_slice().contains(":") {
let mut parts = name.as_slice().splitn(':', 1);
let (prefix, local_name) = if name.contains(":") {
let mut parts = name.splitn(':', 1);
(Some(parts.next().unwrap().to_string()), parts.next().unwrap().to_string())
} else {
(None, name)
(None, name.to_string())
};

(prefix, local_name)
Expand Down

0 comments on commit 130cf76

Please sign in to comment.