Make Attr::prefix return an Option<&Prefix>

This commit is contained in:
Anthony Ramine 2016-11-30 13:57:22 +01:00
parent a377caa7e9
commit fb206e2b10
3 changed files with 7 additions and 7 deletions

View file

@ -81,8 +81,8 @@ impl Attr {
} }
#[inline] #[inline]
pub fn prefix(&self) -> &Option<Prefix> { pub fn prefix(&self) -> Option<&Prefix> {
&self.identifier.prefix self.identifier.prefix.as_ref()
} }
} }
@ -153,7 +153,7 @@ impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-prefix // https://dom.spec.whatwg.org/#dom-attr-prefix
fn GetPrefix(&self) -> Option<DOMString> { fn GetPrefix(&self) -> Option<DOMString> {
// FIXME(ajeffrey): convert directly from LocalName to DOMString // FIXME(ajeffrey): convert directly from LocalName to DOMString
self.prefix().as_ref().map(|p| DOMString::from(&**p)) self.prefix().map(|p| DOMString::from(&**p))
} }
// https://dom.spec.whatwg.org/#dom-attr-ownerelement // https://dom.spec.whatwg.org/#dom-attr-ownerelement

View file

@ -820,7 +820,7 @@ impl Element {
// Step 2. // Step 2.
for attr in element.attrs.borrow().iter() { for attr in element.attrs.borrow().iter() {
if *attr.prefix() == Some(namespace_prefix!("xmlns")) && if attr.prefix() == Some(&namespace_prefix!("xmlns")) &&
**attr.value() == *namespace { **attr.value() == *namespace {
return Some(attr.LocalName()); return Some(attr.LocalName());
} }

View file

@ -1768,7 +1768,7 @@ impl Node {
attr.value().clone(), attr.value().clone(),
attr.name().clone(), attr.name().clone(),
attr.namespace().clone(), attr.namespace().clone(),
attr.prefix().clone()); attr.prefix().cloned());
} }
}, },
_ => () _ => ()
@ -1815,10 +1815,10 @@ impl Node {
defined_prefix: &Option<LocalName>) -> bool { defined_prefix: &Option<LocalName>) -> bool {
*attr.namespace() == ns!(xmlns) && *attr.namespace() == ns!(xmlns) &&
match (attr.prefix(), defined_prefix) { match (attr.prefix(), defined_prefix) {
(&Some(ref attr_prefix), &Some(ref defined_prefix)) => (Some(attr_prefix), &Some(ref defined_prefix)) =>
attr_prefix == &namespace_prefix!("xmlns") && attr_prefix == &namespace_prefix!("xmlns") &&
attr.local_name() == defined_prefix, attr.local_name() == defined_prefix,
(&None, &None) => *attr.local_name() == local_name!("xmlns"), (None, &None) => *attr.local_name() == local_name!("xmlns"),
_ => false _ => false
} }
} }