Skip to content

Commit

Permalink
avm2: Small set_property_local fixup
Browse files Browse the repository at this point in the history
Fixes a borrow panic and logic error.
  • Loading branch information
sleepycatcoding committed Oct 9, 2023
1 parent 3945e0d commit cbc816c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions core/src/avm2/object/xml_list_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,30 +637,38 @@ impl<'gc> TObject<'gc> for XmlListObject<'gc> {
if !matches!(*y.kind(), E4XNodeKind::Attribute(_)) {
// 2.c.viii.1. If r is not null
if let Some(r) = r {
if let E4XNodeKind::Element { children, .. } = &*r.kind() {
let j = if let E4XNodeKind::Element { children, .. } = &*r.kind() {
// 2.c.viii.1.a. If (i > 0)
let j = if index > 0 {
// 2.c.viii.1.a.i. Let j = 0
let mut j = 0;

// 2.c.viii.1.a.ii. While (j < r.[[Length]]-1) and (r[j] is not the same object as x[i-1])
while j < children.len()
&& E4XNode::ptr_eq(
while j < children.len() - 1
&& !E4XNode::ptr_eq(
children[j],
*self.children()[index].node(),
*self.children()[index - 1].node(),
)
{
// 2.c.viii.1.a.ii.1. Let j = j + 1
j += 1;
}

j
// NOTE: Not listed in spec, but avmplus does this, so we do the same.
j + 1
// 2.c.viii.1.b. Else
} else {
// 2.c.viii.1.b.i. Let j = r.[[Length]]-1
children.len()
};

Some(j)
} else {
None
};

// NOTE: This is to bypass borrow errors.
if let Some(j) = j {
// 2.c.viii.1.c. Call the [[Insert]] method of r with arguments ToString(j+1) and y
r.insert(j, XmlObject::new(y, activation).into(), activation)?;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
num_ticks = 1
known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12351

0 comments on commit cbc816c

Please sign in to comment.