avm2: Impl `TextFieldType`

This commit is contained in:
David Wendt 2021-02-26 19:07:07 -05:00 committed by Mike Welsh
parent da563266d5
commit 1c2ef3154a
3 changed files with 69 additions and 0 deletions

View File

@ -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(())
}

View File

@ -2,5 +2,6 @@
pub mod textfield;
pub mod textfieldautosize;
pub mod textfieldtype;
pub mod textformat;
pub mod textformatalign;

View File

@ -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<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, 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<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, 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
}