Skip to content

Commit 09a7bd6

Browse files
committed
avm2: Fix Object.prototype.toString applied to Vector
1 parent 8ec203a commit 09a7bd6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

core/src/avm2/object.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,11 +977,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
977977
.map(|c| c.read().name().local_name())
978978
.unwrap_or_else(|| "Object".into());
979979

980-
Ok(AvmString::new_utf8(
981-
activation.context.gc_context,
982-
format!("[object {class_name}]"),
983-
)
984-
.into())
980+
Ok(AvmString::new_utf8(activation.gc(), format!("[object {class_name}]")).into())
985981
}
986982

987983
/// Implement the result of calling `Object.prototype.toLocaleString` on this

core/src/avm2/object/vector_object.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::avm2::activation::Activation;
44
use crate::avm2::object::script_object::ScriptObjectData;
55
use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject};
6+
use crate::avm2::string::AvmString;
67
use crate::avm2::value::Value;
78
use crate::avm2::vector::VectorStorage;
89
use crate::avm2::Error;
@@ -250,8 +251,19 @@ impl<'gc> TObject<'gc> for VectorObject<'gc> {
250251
}
251252
}
252253

253-
fn to_string(&self, _activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, Error<'gc>> {
254-
Ok(Value::Object(Object::from(*self)))
254+
// Implements the special `Object.prototype.toString` behavior for Vector.
255+
fn to_string(&self, activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, Error<'gc>> {
256+
let inner_name = if let Some(class_object) = self.0.read().vector.value_type() {
257+
class_object
258+
.inner_class_definition()
259+
.read()
260+
.name()
261+
.to_qualified_name(activation.gc())
262+
} else {
263+
AvmString::new_utf8(activation.gc(), "*")
264+
};
265+
266+
Ok(AvmString::new_utf8(activation.gc(), format!("[object Vector.<{inner_name}>]")).into())
255267
}
256268

257269
fn value_of(&self, _mc: &Mutation<'gc>) -> Result<Value<'gc>, Error<'gc>> {

0 commit comments

Comments
 (0)