From 9e739f8cebb97f8ac57a789a5530a23c7b088af6 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Sat, 13 Feb 2021 22:52:34 -0500 Subject: [PATCH] avm2: Ensure constructed text fields have a DisplayObject side --- core/src/avm2/globals/flash/text/textfield.rs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/avm2/globals/flash/text/textfield.rs b/core/src/avm2/globals/flash/text/textfield.rs index 746f919da..3291c97c3 100644 --- a/core/src/avm2/globals/flash/text/textfield.rs +++ b/core/src/avm2/globals/flash/text/textfield.rs @@ -4,10 +4,14 @@ use crate::avm2::activation::Activation; use crate::avm2::class::Class; use crate::avm2::method::Method; use crate::avm2::names::{Namespace, QName}; -use crate::avm2::object::Object; +use crate::avm2::object::{Object, TObject}; use crate::avm2::value::Value; use crate::avm2::Error; +use crate::display_object::EditText; +use crate::tag_utils::SwfMovie; +use crate::vminterface::AvmType; use gc_arena::{GcCell, MutationContext}; +use std::sync::Arc; /// Implements `flash.text.TextField`'s instance constructor. pub fn instance_init<'gc>( @@ -17,6 +21,23 @@ pub fn instance_init<'gc>( ) -> Result, Error> { if let Some(this) = this { activation.super_init(this, &[])?; + + if this.as_display_object().is_none() { + let movie = Arc::new(SwfMovie::empty(activation.context.swf.version())); + let new_do = EditText::new( + &mut activation.context, + movie.clone(), + 0.0, + 0.0, + 100.0, + 100.0, + ); + + let movie_library = activation.context.library.library_for_movie_mut(movie); + movie_library.check_avm_type(AvmType::Avm2).unwrap(); + + this.init_display_object(activation.context.gc_context, new_do.into()); + } } Ok(Value::Undefined)