From 467fd9db80e957a82e827a887f6842772af0f84f Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 18 May 2020 23:15:14 -0400 Subject: [PATCH] Implement `TextField.length` in AVM1. --- core/src/avm1/globals/text_field.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/src/avm1/globals/text_field.rs b/core/src/avm1/globals/text_field.rs index ff3998421..47a0e2363 100644 --- a/core/src/avm1/globals/text_field.rs +++ b/core/src/avm1/globals/text_field.rs @@ -48,6 +48,20 @@ pub fn set_text<'gc>( Ok(Value::Undefined.into()) } +pub fn get_length<'gc>( + _avm: &mut Avm1<'gc>, + _context: &mut UpdateContext<'_, 'gc, '_>, + this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(display_object) = this.as_display_object() { + if let Some(text_field) = display_object.as_edit_text() { + return Ok((text_field.text_length() as f64).into()); + } + } + Ok(Value::Undefined.into()) +} + macro_rules! with_text_field { ( $gc_context: ident, $object:ident, $fn_proto: expr, $($name:expr => $fn:expr),* ) => {{ $( @@ -263,6 +277,13 @@ pub fn attach_virtual_properties<'gc>(gc_context: MutationContext<'gc, '_>, obje Some(Executable::Native(set_text)), DontDelete | ReadOnly | DontEnum, ); + object.add_property( + gc_context, + "length", + Executable::Native(get_length), + None, + DontDelete | ReadOnly | DontEnum, + ); object.add_property( gc_context, "textWidth",