From 3cb307bfb096c1d3b4ba8707598095c619c1e5e9 Mon Sep 17 00:00:00 2001 From: Lord-McSweeney <84632019+Lord-McSweeney@users.noreply.github.com> Date: Sun, 5 Mar 2023 21:57:02 -0800 Subject: [PATCH] avm2: Implement String.toString (#9872) Some SWFs use this property --- core/src/avm2/globals/string.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/avm2/globals/string.rs b/core/src/avm2/globals/string.rs index a49dd4130..ac4bb1d7e 100644 --- a/core/src/avm2/globals/string.rs +++ b/core/src/avm2/globals/string.rs @@ -589,6 +589,18 @@ fn to_lower_case<'gc>( Ok(Value::Undefined) } +/// Implements `String.toString` +fn to_string<'gc>( + _activation: &mut Activation<'_, 'gc>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + if let Some(this) = this { + return Ok(Value::from(this)); + } + Ok(Value::Undefined) +} + /// Implements `String.toUpperCase` fn to_upper_case<'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), ("toLocaleUpperCase", to_upper_case), ("toLowerCase", to_lower_case), + ("toString", to_string), ("toUpperCase", to_upper_case), ]; write.define_builtin_instance_methods(