avm2: Support Array(...) without new

This commit is contained in:
Adrian Wielgosik 2023-06-13 20:22:39 +02:00 committed by Adrian Wielgosik
parent 40318f905e
commit 128416cccd
4 changed files with 32 additions and 1 deletions

View File

@ -102,6 +102,19 @@ pub fn instance_init<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
pub fn class_call<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
Ok(activation
.avm2()
.classes()
.array
.construct(activation, args)?
.into())
}
/// Implements `Array`'s class initializer. /// Implements `Array`'s class initializer.
pub fn class_init<'gc>( pub fn class_init<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
@ -1272,6 +1285,7 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
let mut write = class.write(mc); let mut write = class.write(mc);
write.set_instance_allocator(array_allocator); write.set_instance_allocator(array_allocator);
write.set_call_handler(Method::from_builtin(class_call, "<Array call handler>", mc));
const PUBLIC_INSTANCE_PROPERTIES: &[( const PUBLIC_INSTANCE_PROPERTIES: &[(
&str, &str,

View File

@ -21,3 +21,12 @@ string
/asdf/gi /asdf/gi
//RegExp(regexp) //RegExp(regexp)
/asdf/gi /asdf/gi
//Array().length
0
//Array(5)
,,,,
//Array("5")
5
//Array("a", "b", "c")
a,b,c

View File

@ -51,4 +51,12 @@ trace("//RegExp(regexp)")
pat = cls(pat); pat = cls(pat);
trace(pat); trace(pat);
trace()
trace("//Array().length")
trace(Array().length)
trace("//Array(5)")
trace(Array(5))
trace("//Array(\"5\")")
trace(Array("5"))
trace("//Array(\"a\", \"b\", \"c\")")
trace(Array("a", "b", "c"))