avm2: Implement Object()

This commit is contained in:
Adrian Wielgosik 2022-02-02 22:42:30 +01:00 committed by Adrian Wielgosik
parent 0004b9e58e
commit c67579e236
1 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,23 @@ pub fn instance_init<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
fn class_call<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
let this_class = activation.subclass_object().unwrap();
if args.len() == 0 {
return this_class.construct(activation, args).map(|o| o.into());
}
let arg = args.get(0).cloned().unwrap();
if matches!(arg, Value::Undefined) || matches!(arg, Value::Null) {
return this_class.construct(activation, args).map(|o| o.into());
}
Ok(arg)
}
/// Implements `Object`'s class initializer /// Implements `Object`'s class initializer
pub fn class_init<'gc>( pub fn class_init<'gc>(
activation: &mut Activation<'_, 'gc, '_>, activation: &mut Activation<'_, 'gc, '_>,
@ -257,6 +274,7 @@ pub fn create_class<'gc>(gc_context: MutationContext<'gc, '_>) -> GcCell<'gc, Cl
gc_context, gc_context,
); );
let mut write = object_class.write(gc_context); let mut write = object_class.write(gc_context);
write.set_call_handler(Method::from_builtin(class_call, "<Object call handler>", gc_context));
write.define_class_trait(Trait::from_const( write.define_class_trait(Trait::from_const(
QName::new(Namespace::public(), "length"), QName::new(Namespace::public(), "length"),