diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index d3dd1eb2825a..bdfe8a3f832c 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -977,11 +977,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into> + Clone + Copy .map(|c| c.read().name().local_name()) .unwrap_or_else(|| "Object".into()); - Ok(AvmString::new_utf8( - activation.context.gc_context, - format!("[object {class_name}]"), - ) - .into()) + Ok(AvmString::new_utf8(activation.gc(), format!("[object {class_name}]")).into()) } /// Implement the result of calling `Object.prototype.toLocaleString` on this diff --git a/core/src/avm2/object/vector_object.rs b/core/src/avm2/object/vector_object.rs index a7b143462336..27c3d50c9659 100644 --- a/core/src/avm2/object/vector_object.rs +++ b/core/src/avm2/object/vector_object.rs @@ -3,6 +3,7 @@ use crate::avm2::activation::Activation; use crate::avm2::object::script_object::ScriptObjectData; use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject}; +use crate::avm2::string::AvmString; use crate::avm2::value::Value; use crate::avm2::vector::VectorStorage; use crate::avm2::Error; @@ -250,8 +251,19 @@ impl<'gc> TObject<'gc> for VectorObject<'gc> { } } - fn to_string(&self, _activation: &mut Activation<'_, 'gc>) -> Result, Error<'gc>> { - Ok(Value::Object(Object::from(*self))) + // Implements the special `Object.prototype.toString` behavior for Vector. + fn to_string(&self, activation: &mut Activation<'_, 'gc>) -> Result, Error<'gc>> { + let inner_name = if let Some(class_object) = self.0.read().vector.value_type() { + class_object + .inner_class_definition() + .read() + .name() + .to_qualified_name(activation.gc()) + } else { + AvmString::new_utf8(activation.gc(), "*") + }; + + Ok(AvmString::new_utf8(activation.gc(), format!("[object Vector.<{inner_name}>]")).into()) } fn value_of(&self, _mc: &Mutation<'gc>) -> Result, Error<'gc>> { diff --git a/tests/tests/swfs/avm2/vector_object_toString/Test.as b/tests/tests/swfs/avm2/vector_object_toString/Test.as new file mode 100644 index 000000000000..6199ee14aba0 --- /dev/null +++ b/tests/tests/swfs/avm2/vector_object_toString/Test.as @@ -0,0 +1,21 @@ +package { + import flash.display.Sprite; + public class Test extends Sprite { + public function Test() { + trace("// Object.prototype.toString.call(new Vector.<*>())"); + trace(Object.prototype.toString.call(new Vector.<*>())); + + trace("// Object.prototype.toString.call(new Vector.())"); + trace(Object.prototype.toString.call(new Vector.())); + + trace("// Object.prototype.toString.call(new Vector.())"); + trace(Object.prototype.toString.call(new Vector.())); + + trace("// Object.prototype.toString.call(new Vector.())"); + trace(Object.prototype.toString.call(new Vector.())); + + trace("// Object.prototype.toString.call(new Vector.())"); + trace(Object.prototype.toString.call(new Vector.())); + } + } +} diff --git a/tests/tests/swfs/avm2/vector_object_toString/output.txt b/tests/tests/swfs/avm2/vector_object_toString/output.txt new file mode 100644 index 000000000000..45fe272079f5 --- /dev/null +++ b/tests/tests/swfs/avm2/vector_object_toString/output.txt @@ -0,0 +1,10 @@ +// Object.prototype.toString.call(new Vector.<*>()) +[object Vector.<*>] +// Object.prototype.toString.call(new Vector.()) +[object Vector.] +// Object.prototype.toString.call(new Vector.()) +[object Vector.] +// Object.prototype.toString.call(new Vector.()) +[object Vector.] +// Object.prototype.toString.call(new Vector.()) +[object Vector.] diff --git a/tests/tests/swfs/avm2/vector_object_toString/test.swf b/tests/tests/swfs/avm2/vector_object_toString/test.swf new file mode 100644 index 000000000000..e96173f40cc7 Binary files /dev/null and b/tests/tests/swfs/avm2/vector_object_toString/test.swf differ diff --git a/tests/tests/swfs/avm2/vector_object_toString/test.toml b/tests/tests/swfs/avm2/vector_object_toString/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm2/vector_object_toString/test.toml @@ -0,0 +1 @@ +num_frames = 1