avm2+tests: Implement Object.length and Object.init; add test for Object.length

This commit is contained in:
Lord-McSweeney 2023-06-13 22:04:15 -07:00 committed by Nathan Adams
parent 942842c47a
commit f5528aab75
5 changed files with 21 additions and 1 deletions

View File

@ -99,6 +99,7 @@ pub struct Avm2<'gc> {
system_classes: Option<SystemClasses<'gc>>,
pub public_namespace: Namespace<'gc>,
pub internal_namespace: Namespace<'gc>,
pub as3_namespace: Namespace<'gc>,
pub vector_public_namespace: Namespace<'gc>,
pub vector_internal_namespace: Namespace<'gc>,
@ -157,6 +158,7 @@ impl<'gc> Avm2<'gc> {
system_classes: None,
public_namespace: Namespace::package("", context),
internal_namespace: Namespace::internal("", context),
as3_namespace: Namespace::package("http://adobe.com/AS3/2006/builtin", context),
vector_public_namespace: Namespace::package("__AS3__.vec", context),
vector_internal_namespace: Namespace::internal("__AS3__.vec", context),

View File

@ -271,6 +271,15 @@ pub fn set_property_is_enumerable<'gc>(
Ok(Value::Undefined)
}
/// Undocumented `Object.init`, which is a no-op
pub fn init<'gc>(
_activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
Ok(Value::Undefined)
}
/// Construct `Object`'s class.
pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Class<'gc>> {
let gc_context = activation.context.gc_context;
@ -291,7 +300,7 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
write.define_class_trait(Trait::from_const(
QName::new(activation.avm2().public_namespace, "length"),
Multiname::new(activation.avm2().public_namespace, "int"),
None,
Some(1.into()),
));
// Fixed traits (in AS3 namespace)
@ -306,5 +315,12 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
AS3_INSTANCE_METHODS,
);
const INTERNAL_INIT_METHOD: &[(&str, NativeMethodImpl)] = &[("init", init)];
write.define_builtin_class_methods(
gc_context,
activation.avm2().internal_namespace,
INTERNAL_INIT_METHOD,
);
object_class
}

View File

@ -1,3 +1,4 @@
Object.length is: 1
RegExp.length is: 1
String.length is: 1
XMLList.length is: 1

View File

@ -8,6 +8,7 @@ package
trace("Object.length is: " + Object.length);
trace("RegExp.length is: " + RegExp.length);
trace("String.length is: " + String.length);
trace("XMLList.length is: " + XMLList.length);