From 1c2ef3154a24c830100f717f27c187bf5d6ad044 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Fri, 26 Feb 2021 19:07:07 -0500 Subject: [PATCH] avm2: Impl `TextFieldType` --- core/src/avm2/globals.rs | 7 +++ core/src/avm2/globals/flash/text.rs | 1 + .../avm2/globals/flash/text/textfieldtype.rs | 61 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 core/src/avm2/globals/flash/text/textfieldtype.rs diff --git a/core/src/avm2/globals.rs b/core/src/avm2/globals.rs index 96e2b267a..82f90285a 100644 --- a/core/src/avm2/globals.rs +++ b/core/src/avm2/globals.rs @@ -739,6 +739,13 @@ pub fn load_player_globals<'gc>( domain, script, )?; + class( + activation, + flash::text::textfieldtype::create_class(mc), + implicit_deriver, + domain, + script, + )?; Ok(()) } diff --git a/core/src/avm2/globals/flash/text.rs b/core/src/avm2/globals/flash/text.rs index b47184cd4..578d1aceb 100644 --- a/core/src/avm2/globals/flash/text.rs +++ b/core/src/avm2/globals/flash/text.rs @@ -2,5 +2,6 @@ pub mod textfield; pub mod textfieldautosize; +pub mod textfieldtype; pub mod textformat; pub mod textformatalign; diff --git a/core/src/avm2/globals/flash/text/textfieldtype.rs b/core/src/avm2/globals/flash/text/textfieldtype.rs new file mode 100644 index 000000000..a77df1830 --- /dev/null +++ b/core/src/avm2/globals/flash/text/textfieldtype.rs @@ -0,0 +1,61 @@ +//! `flash.text.TextFieldType` builtin/prototype + +use crate::avm2::activation::Activation; +use crate::avm2::class::{Class, ClassAttributes}; +use crate::avm2::method::Method; +use crate::avm2::names::{Namespace, QName}; +use crate::avm2::object::Object; +use crate::avm2::traits::Trait; +use crate::avm2::value::Value; +use crate::avm2::Error; +use gc_arena::{GcCell, MutationContext}; + +/// Implements `flash.text.TextFieldType`'s instance constructor. +pub fn instance_init<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(this) = this { + activation.super_init(this, &[])?; + } + + Ok(Value::Undefined) +} + +/// Implements `flash.text.TextFieldType`'s class constructor. +pub fn class_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Ok(Value::Undefined) +} + +/// Construct `TextFieldType`'s class. +pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { + let class = Class::new( + QName::new(Namespace::package("flash.text"), "TextFieldType"), + Some(QName::new(Namespace::public(), "Object").into()), + Method::from_builtin(instance_init), + Method::from_builtin(class_init), + mc, + ); + + let mut write = class.write(mc); + + write.set_attributes(ClassAttributes::FINAL | ClassAttributes::SEALED); + + write.define_class_trait(Trait::from_const( + QName::new(Namespace::public(), "DYNAMIC"), + QName::new(Namespace::public(), "String").into(), + Some("dynamic".into()), + )); + write.define_class_trait(Trait::from_const( + QName::new(Namespace::public(), "INPUT"), + QName::new(Namespace::public(), "String").into(), + Some("input".into()), + )); + + class +}