mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Refactoring, added conversion to lowercase for get_attribute_by_name method. (fixes #5561)
This commit is contained in:
parent
bdcf606f48
commit
6a31a75bc6
2 changed files with 6 additions and 8 deletions
|
@ -452,7 +452,6 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||||
&self.extended_deref().local_name
|
&self.extended_deref().local_name
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
|
||||||
fn parsed_name(self, name: DOMString) -> DOMString {
|
fn parsed_name(self, name: DOMString) -> DOMString {
|
||||||
if self.html_element_in_html_document() {
|
if self.html_element_in_html_document() {
|
||||||
name.to_ascii_lowercase()
|
name.to_ascii_lowercase()
|
||||||
|
@ -655,7 +654,7 @@ pub trait AttributeHandlers {
|
||||||
-> Option<Temporary<Attr>>;
|
-> Option<Temporary<Attr>>;
|
||||||
/// Returns the first attribute with any namespace and given case-sensitive
|
/// Returns the first attribute with any namespace and given case-sensitive
|
||||||
/// name, if any.
|
/// name, if any.
|
||||||
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>>;
|
fn get_attribute_by_name(self, name: DOMString) -> Option<Temporary<Attr>>;
|
||||||
fn get_attributes(self, local_name: &Atom)
|
fn get_attributes(self, local_name: &Atom)
|
||||||
-> Vec<Temporary<Attr>>;
|
-> Vec<Temporary<Attr>>;
|
||||||
fn set_attribute_from_parser(self,
|
fn set_attribute_from_parser(self,
|
||||||
|
@ -706,7 +705,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
.map(|x| Temporary::from_rooted(x.r()))
|
.map(|x| Temporary::from_rooted(x.r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>> {
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
|
fn get_attribute_by_name(self, name: DOMString) -> Option<Temporary<Attr>> {
|
||||||
|
let name = &Atom::from_slice(&self.parsed_name(name));
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = self.attrs.borrow();
|
let attrs = self.attrs.borrow();
|
||||||
attrs.iter().map(|attr| attr.root())
|
attrs.iter().map(|attr| attr.root())
|
||||||
|
@ -714,7 +715,6 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
.map(|x| Temporary::from_rooted(x.r()))
|
.map(|x| Temporary::from_rooted(x.r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
|
||||||
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
|
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = self.attrs.borrow();
|
let attrs = self.attrs.borrow();
|
||||||
|
@ -1047,8 +1047,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-getattribute
|
// https://dom.spec.whatwg.org/#dom-element-getattribute
|
||||||
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
|
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
|
||||||
let name = self.parsed_name(name);
|
self.get_attribute_by_name(name).root()
|
||||||
self.get_attribute_by_name(&Atom::from_slice(&name)).root()
|
|
||||||
.map(|s| s.r().Value())
|
.map(|s| s.r().Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,7 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let owner = owner.r();
|
let owner = owner.r();
|
||||||
let name = owner.parsed_name(name);
|
owner.get_attribute_by_name(name)
|
||||||
owner.get_attribute_by_name(&Atom::from_slice(&name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns
|
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue