From 1953ab3cf0865b977c94885ecb444f64049f39f4 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Sun, 29 Oct 2023 22:35:30 +0100 Subject: [PATCH] avm2: Add a E4XNode::is_attribute helper --- core/src/avm2/e4x.rs | 12 ++++++++---- core/src/avm2/object/xml_list_object.rs | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/avm2/e4x.rs b/core/src/avm2/e4x.rs index 9628e04fa..afc8ee81d 100644 --- a/core/src/avm2/e4x.rs +++ b/core/src/avm2/e4x.rs @@ -182,6 +182,11 @@ impl<'gc> E4XNode<'gc> { )) } + /// Returns true when the node is an attribute (E4XNodeKind::Attribute) + pub fn is_attribute(&self) -> bool { + matches!(self.0.read().kind, E4XNodeKind::Attribute(_)) + } + /// Returns an iterator that yields ancestor nodes (including itself). pub fn ancestors(self) -> impl Iterator> { iterators::AnscIter::for_node(self) @@ -397,7 +402,7 @@ impl<'gc> E4XNode<'gc> { pub fn child_index(&self) -> Option { let parent = self.parent()?; - if let E4XNodeKind::Attribute(_) = &*self.kind() { + if self.is_attribute() { return None; } @@ -491,7 +496,7 @@ impl<'gc> E4XNode<'gc> { if let Some(xml) = value .as_object() .and_then(|x| x.as_xml_object()) - .filter(|x| !matches!(*x.node().kind(), E4XNodeKind::Attribute(_))) + .filter(|x| !x.node().is_attribute()) { // 5.a. If V.[[Class]] is “element” and (V is x or an ancestor of x) throw an Error exception if matches!(*xml.node().kind(), E4XNodeKind::Element { .. }) @@ -918,8 +923,7 @@ impl<'gc> E4XNode<'gc> { } pub fn matches_name(&self, name: &Multiname<'gc>) -> bool { - let self_is_attr = matches!(self.0.read().kind, E4XNodeKind::Attribute(_)); - if self_is_attr != name.is_attribute() { + if self.is_attribute() != name.is_attribute() { return false; } diff --git a/core/src/avm2/object/xml_list_object.rs b/core/src/avm2/object/xml_list_object.rs index 7248b357f..071aa4d83 100644 --- a/core/src/avm2/object/xml_list_object.rs +++ b/core/src/avm2/object/xml_list_object.rs @@ -689,7 +689,7 @@ impl<'gc> TObject<'gc> for XmlListObject<'gc> { index = self.length(); // 2.c.viii. If (y.[[Class]] is not equal to "attribute") - if !matches!(*y.kind(), E4XNodeKind::Attribute(_)) { + if !y.is_attribute() { // 2.c.viii.1. If r is not null if let Some(r) = r { let j = if let E4XNodeKind::Element { children, .. } = &*r.kind() { @@ -792,7 +792,7 @@ impl<'gc> TObject<'gc> for XmlListObject<'gc> { drop(children); // 2.e. If x[i].[[Class]] == "attribute" - if matches!(*child.kind(), E4XNodeKind::Attribute(_)) { + if child.is_attribute() { // FIXME: We probably need to take the namespace too. // 2.e.i. Let z = ToAttributeName(x[i].[[Name]]) let z = Multiname::attribute( @@ -1031,7 +1031,7 @@ impl<'gc> TObject<'gc> for XmlListObject<'gc> { let removed = write.children.remove(index); let removed_node = removed.node(); if let Some(parent) = removed_node.parent() { - if let E4XNodeKind::Attribute(_) = &*removed_node.kind() { + if removed_node.is_attribute() { parent .remove_attribute(activation.context.gc_context, &removed_node); } else {