avm2: Fix Object.prototype.toString applied to Vector

This commit is contained in:
Tom Schuster 2024-03-13 11:13:05 +01:00
parent 8ec203a227
commit 09a7bd61b5
2 changed files with 15 additions and 7 deletions

View File

@ -977,11 +977,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
.map(|c| c.read().name().local_name()) .map(|c| c.read().name().local_name())
.unwrap_or_else(|| "Object".into()); .unwrap_or_else(|| "Object".into());
Ok(AvmString::new_utf8( Ok(AvmString::new_utf8(activation.gc(), format!("[object {class_name}]")).into())
activation.context.gc_context,
format!("[object {class_name}]"),
)
.into())
} }
/// Implement the result of calling `Object.prototype.toLocaleString` on this /// Implement the result of calling `Object.prototype.toLocaleString` on this

View File

@ -3,6 +3,7 @@
use crate::avm2::activation::Activation; use crate::avm2::activation::Activation;
use crate::avm2::object::script_object::ScriptObjectData; use crate::avm2::object::script_object::ScriptObjectData;
use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject}; use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject};
use crate::avm2::string::AvmString;
use crate::avm2::value::Value; use crate::avm2::value::Value;
use crate::avm2::vector::VectorStorage; use crate::avm2::vector::VectorStorage;
use crate::avm2::Error; use crate::avm2::Error;
@ -250,8 +251,19 @@ impl<'gc> TObject<'gc> for VectorObject<'gc> {
} }
} }
fn to_string(&self, _activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, Error<'gc>> { // Implements the special `Object.prototype.toString` behavior for Vector.
Ok(Value::Object(Object::from(*self))) fn to_string(&self, activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, 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<Value<'gc>, Error<'gc>> { fn value_of(&self, _mc: &Mutation<'gc>) -> Result<Value<'gc>, Error<'gc>> {