avm2: Some fixes to Vector.concat

- Properly error when passing non-Objects to Vector.concat
- Implement SWFv10 behavior
- Properly error when appending Vector.<A> to Vector.<B> where A and B are both subclasses of Object
This commit is contained in:
Lord-McSweeney 2024-09-02 11:00:48 -07:00 committed by Lord-McSweeney
parent d75d6da39e
commit 8d25be4639
3 changed files with 17 additions and 19 deletions

View File

@ -249,12 +249,16 @@ pub fn concat<'gc>(
return Err("Not a vector-structured object".into());
};
let original_length = new_vector_storage.length();
let use_swf10_behavior = activation
.caller_movie()
.map_or(false, |m| m.version() < 11);
let val_class = new_vector_storage.value_type_for_coercion(activation);
for arg in args {
let arg_obj = arg
.as_object()
.ok_or("Cannot concat Vector with null or undefined")?;
let arg_obj = arg.coerce_to_object_or_typeerror(activation, None)?;
// this is Vector.<int/uint/Number/*>
let my_base_vector_class = activation
@ -284,21 +288,17 @@ pub fn concat<'gc>(
continue;
};
for val in old_vec {
if let Ok(val_obj) = val.coerce_to_object(activation) {
if !val.is_of_type(activation, val_class) {
let other_val_class = val_obj.instance_class();
return Err(format!(
"TypeError: Cannot coerce Vector value of type {:?} to type {:?}",
other_val_class.name(),
val_class.name()
)
.into());
}
}
for (i, val) in old_vec.iter().enumerate() {
let insertion_index = (original_length + i) as i32;
let coerced_val = val.coerce_to_type(activation, val_class)?;
new_vector_storage.push(coerced_val, activation)?;
if use_swf10_behavior {
// See bugzilla 504525: In SWFv10, calling `concat` with multiple
// arguments passed results in concatenating in the wrong order.
new_vector_storage.insert(insertion_index, coerced_val, activation)?;
} else {
new_vector_storage.push(coerced_val, activation)?;
}
}
}

View File

@ -1,2 +1 @@
num_ticks = 1
known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12321

View File

@ -1,2 +1 @@
num_ticks = 1
known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12321