avm2: Implement String.toString (#9872)

Some SWFs use this property
This commit is contained in:
Lord-McSweeney 2023-03-05 21:57:02 -08:00 committed by GitHub
parent 730115b1a0
commit 3cb307bfb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -589,6 +589,18 @@ fn to_lower_case<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements `String.toString`
fn to_string<'gc>(
_activation: &mut Activation<'_, 'gc>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(this) = this {
return Ok(Value::from(this));
}
Ok(Value::Undefined)
}
/// Implements `String.toUpperCase` /// Implements `String.toUpperCase`
fn to_upper_case<'gc>( fn to_upper_case<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
@ -652,6 +664,7 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
("toLocaleLowerCase", to_lower_case), ("toLocaleLowerCase", to_lower_case),
("toLocaleUpperCase", to_upper_case), ("toLocaleUpperCase", to_upper_case),
("toLowerCase", to_lower_case), ("toLowerCase", to_lower_case),
("toString", to_string),
("toUpperCase", to_upper_case), ("toUpperCase", to_upper_case),
]; ];
write.define_builtin_instance_methods( write.define_builtin_instance_methods(