mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #5692 - pgonda:get_attributes-memory-safety, r=jdm
Changes Element::get_attributes to use a `&mut Rooted<JS<Attr>>` param instead of returning a `Vec<Temporary<Attr>>`, fixes #5684. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5692) <!-- Reviewable:end -->
This commit is contained in:
commit
8ecb9d681c
2 changed files with 15 additions and 15 deletions
|
@ -665,8 +665,7 @@ pub trait AttributeHandlers {
|
||||||
/// 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: DOMString) -> 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, attributes: &mut RootedVec<JS<Attr>>);
|
||||||
-> Vec<Temporary<Attr>>;
|
|
||||||
fn set_attribute_from_parser(self,
|
fn set_attribute_from_parser(self,
|
||||||
name: QualName,
|
name: QualName,
|
||||||
value: DOMString,
|
value: DOMString,
|
||||||
|
@ -710,9 +709,9 @@ pub trait AttributeHandlers {
|
||||||
|
|
||||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>> {
|
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>> {
|
||||||
self.get_attributes(local_name).into_iter().map(|attr| attr.root())
|
let mut attributes = RootedVec::new();
|
||||||
.find(|attr| attr.r().namespace() == namespace)
|
self.get_attributes(local_name, &mut attributes);
|
||||||
.map(|x| Temporary::from_rooted(x.r()))
|
attributes.iter().map(|attr| attr.root()).find(|attr| attr.r().namespace() == namespace).map(|x| Temporary::from_rooted(x.r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
|
@ -725,19 +724,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
.map(|x| Temporary::from_rooted(x.r()))
|
.map(|x| Temporary::from_rooted(x.r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
|
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
|
||||||
|
fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec<JS<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();
|
||||||
attrs.iter().map(|attr| attr.root()).filter_map(|attr| {
|
for attr in attrs.iter().map(|attr| attr.root()) {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let attr_local_name = attr.local_name();
|
let attr_local_name = attr.local_name();
|
||||||
if attr_local_name == local_name {
|
if attr_local_name == local_name {
|
||||||
Some(Temporary::from_rooted(attr))
|
attributes.push(JS::from_rooted(attr));
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}).collect()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_attribute_from_parser(self,
|
fn set_attribute_from_parser(self,
|
||||||
|
@ -1500,7 +1498,9 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> {
|
fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> {
|
||||||
self.get_attributes(local_name).into_iter().map(|attr| attr.root()).map(|attr| {
|
let mut attributes = RootedVec::new();
|
||||||
|
self.get_attributes(local_name, &mut attributes);
|
||||||
|
attributes.iter().map(|attr| attr.root()).map(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let value: &str = &**attr.value();
|
let value: &str = &**attr.value();
|
||||||
|
|
|
@ -2525,9 +2525,9 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => {
|
||||||
self.as_element().get_attributes(local_name).into_iter()
|
let mut attributes: RootedVec<JS<Attr>> = RootedVec::new();
|
||||||
.map(|attr| attr.root())
|
self.as_element().get_attributes(local_name, &mut attributes);
|
||||||
.any(|attr| {
|
attributes.iter().map(|attr| attr.root()).any(|attr| {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attr = attr.r();
|
let attr = attr.r();
|
||||||
let value = attr.value();
|
let value = attr.value();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue