Skip to content

Commit

Permalink
avm2: Allow splice() on a Vector with fixed=true
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 committed Apr 17, 2024
1 parent 5bffc33 commit a69b80b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
7 changes: 2 additions & 5 deletions core/src/avm2/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::avm2::value::Value;
use crate::avm2::Error;
use gc_arena::Collect;
use std::cmp::{max, min};
use std::ops::{Index, RangeBounds};
use std::ops::RangeBounds;
use std::slice::SliceIndex;

/// The vector storage portion of a vector object.
Expand Down Expand Up @@ -401,10 +401,7 @@ impl<'gc> VectorStorage<'gc> {
where
R: Clone + SliceIndex<[Value<'gc>], Output = [Value<'gc>]> + RangeBounds<usize>,
{
if self.is_fixed && self.storage.index(range.clone()).len() != replace_with.len() {
return Err("RangeError: Vector is fixed".into());
}

// NOTE: no fixed check here for bug compatibility
Ok(self.storage.splice(range, replace_with).collect())
}
}
28 changes: 28 additions & 0 deletions tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// compiled with mxmlc

import flash.utils.getQualifiedClassName;
import flash.utils.getTimer;
import flash.utils.ByteArray;

var v = new Vector.<int>(5, true);
trace(v.length);
try {
v.push(123);
} catch(e) {
trace("push exception caught");
}
v.splice(0, 3);
trace("NO exception on splice")
trace(v.length);

package {
import flash.display.MovieClip;
import flash.text.TextField;

public class Test extends MovieClip {
public function Test(){

}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
5
push exception caught
NO exception on splice
2
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 1

0 comments on commit a69b80b

Please sign in to comment.