@@ -4,21 +4,37 @@ use crate::avm2::activation::Activation;
4
4
use crate :: avm2:: class:: { Class , ClassAttributes } ;
5
5
use crate :: avm2:: error;
6
6
use crate :: avm2:: method:: { Method , NativeMethodImpl , ParamConfig } ;
7
- use crate :: avm2:: object:: { FunctionObject , Object , TObject } ;
7
+ use crate :: avm2:: object:: { FunctionObject , Object , ScriptObject , TObject } ;
8
8
use crate :: avm2:: traits:: Trait ;
9
9
use crate :: avm2:: value:: Value ;
10
10
use crate :: avm2:: { Error , Multiname , QName } ;
11
11
use crate :: string:: AvmString ;
12
12
13
- /// Implements `Object`'s instance initializer.
14
- pub fn instance_init < ' gc > (
13
+ /// Implements `Object`'s instance initializer. This method is unreachable because
14
+ /// `Object` has a custom constructor (`object_constructor`).
15
+ fn instance_init < ' gc > (
15
16
_activation : & mut Activation < ' _ , ' gc > ,
16
17
_this : Value < ' gc > ,
17
18
_args : & [ Value < ' gc > ] ,
18
19
) -> Result < Value < ' gc > , Error < ' gc > > {
19
20
Ok ( Value :: Undefined )
20
21
}
21
22
23
+ /// Implements `Object`'s custom constructor.
24
+ fn object_constructor < ' gc > (
25
+ activation : & mut Activation < ' _ , ' gc > ,
26
+ args : & [ Value < ' gc > ] ,
27
+ ) -> Result < Value < ' gc > , Error < ' gc > > {
28
+ if let Some ( arg) = args. get ( 0 ) {
29
+ if !matches ! ( arg, Value :: Undefined | Value :: Null ) {
30
+ return Ok ( * arg) ;
31
+ }
32
+ }
33
+
34
+ let constructed_object = ScriptObject :: new_object ( activation) ;
35
+ Ok ( constructed_object. into ( ) )
36
+ }
37
+
22
38
fn class_call < ' gc > (
23
39
activation : & mut Activation < ' _ , ' gc > ,
24
40
_this : Value < ' gc > ,
@@ -299,6 +315,8 @@ pub fn create_i_class<'gc>(activation: &mut Activation<'_, 'gc>) -> Class<'gc> {
299
315
Method :: from_builtin ( class_call, "<Object call handler>" , gc_context) ,
300
316
) ;
301
317
318
+ object_i_class. set_custom_constructor ( gc_context, object_constructor) ;
319
+
302
320
// Fixed traits (in AS3 namespace)
303
321
let as3_instance_methods: Vec < ( & str , NativeMethodImpl , _ , _ ) > = vec ! [
304
322
// These signatures are weird, but they match the describeTypeJSON output
0 commit comments