Skip to content

Commit f19e216

Browse files
committed
avm1: add Value::as_xml_node convenience method
This avoids having to call `coerce_to_object`
1 parent 8a86535 commit f19e216

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

core/src/avm1/globals/xml_node.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ fn append_child<'gc>(
6969
) -> Result<Value<'gc>, Error<'gc>> {
7070
if let (Some(xmlnode), Some(child_xmlnode)) = (
7171
this.as_xml_node(),
72-
args.get(0)
73-
.and_then(|n| n.coerce_to_object(activation).as_xml_node()),
72+
args.get(0).and_then(|n| n.as_xml_node()),
7473
) {
7574
if !xmlnode.has_child(child_xmlnode) {
7675
let position = xmlnode.children_len();
@@ -89,10 +88,8 @@ fn insert_before<'gc>(
8988
) -> Result<Value<'gc>, Error<'gc>> {
9089
if let (Some(xmlnode), Some(child_xmlnode), Some(insertpoint_xmlnode)) = (
9190
this.as_xml_node(),
92-
args.get(0)
93-
.and_then(|n| n.coerce_to_object(activation).as_xml_node()),
94-
args.get(1)
95-
.and_then(|n| n.coerce_to_object(activation).as_xml_node()),
91+
args.get(0).and_then(|n| n.as_xml_node()),
92+
args.get(1).and_then(|n| n.as_xml_node()),
9693
) {
9794
if !xmlnode.has_child(child_xmlnode) {
9895
if let Some(position) = xmlnode.child_position(insertpoint_xmlnode) {

core/src/avm1/value.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ impl<'gc> Value<'gc> {
508508
Value::Bool(_) | Value::Object(_) | Value::MovieClip(_) => None,
509509
}
510510
}
511+
512+
/// Get the underlying XML node for this value, if it exists.
513+
pub fn as_xml_node(self) -> Option<crate::avm1::xml::XmlNode<'gc>> {
514+
match self {
515+
Value::Object(obj) => obj.as_xml_node(),
516+
_ => None,
517+
}
518+
}
511519
}
512520

513521
/// Calculate `value * 10^exp` through repeated multiplication or division.

0 commit comments

Comments
 (0)