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:
bors-servo 2015-04-27 15:25:30 -05:00
commit 8ecb9d681c
2 changed files with 15 additions and 15 deletions

View file

@ -665,8 +665,7 @@ pub trait AttributeHandlers {
/// Returns the first attribute with any namespace and given case-sensitive
/// name, if any.
fn get_attribute_by_name(self, name: DOMString) -> Option<Temporary<Attr>>;
fn get_attributes(self, local_name: &Atom)
-> Vec<Temporary<Attr>>;
fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec<JS<Attr>>);
fn set_attribute_from_parser(self,
name: QualName,
value: DOMString,
@ -710,9 +709,9 @@ pub trait AttributeHandlers {
impl<'a> AttributeHandlers for JSRef<'a, Element> {
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Temporary<Attr>> {
self.get_attributes(local_name).into_iter().map(|attr| attr.root())
.find(|attr| attr.r().namespace() == namespace)
.map(|x| Temporary::from_rooted(x.r()))
let mut attributes = RootedVec::new();
self.get_attributes(local_name, &mut attributes);
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
@ -725,19 +724,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
.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)
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)
let attr = attr.r();
let attr_local_name = attr.local_name();
if attr_local_name == local_name {
Some(Temporary::from_rooted(attr))
} else {
None
attributes.push(JS::from_rooted(attr));
}
}).collect()
}
}
fn set_attribute_from_parser(self,
@ -1500,7 +1498,9 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
}
#[allow(unsafe_code)]
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)
let attr = attr.r();
let value: &str = &**attr.value();

View file

@ -2525,9 +2525,9 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> {
})
},
NamespaceConstraint::Any => {
self.as_element().get_attributes(local_name).into_iter()
.map(|attr| attr.root())
.any(|attr| {
let mut attributes: RootedVec<JS<Attr>> = RootedVec::new();
self.as_element().get_attributes(local_name, &mut attributes);
attributes.iter().map(|attr| attr.root()).any(|attr| {
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let attr = attr.r();
let value = attr.value();