@@ -8,7 +8,7 @@ use crate::avm1::function::ExecutionReason;
8
8
use crate :: avm1:: object:: { search_prototype, ExecutionName } ;
9
9
use crate :: avm1:: { NativeObject , Object , Value } ;
10
10
use crate :: string:: AvmString ;
11
- use gc_arena:: { Collect , Gc } ;
11
+ use gc_arena:: Collect ;
12
12
use ruffle_macros:: istr;
13
13
14
14
/// Implementation of the `super` object in AS2.
@@ -18,44 +18,47 @@ use ruffle_macros::istr;
18
18
/// with its parent class.
19
19
#[ derive( Copy , Clone , Collect ) ]
20
20
#[ collect( no_drop) ]
21
- pub struct SuperObject < ' gc > ( Gc < ' gc , SuperObjectData < ' gc > > ) ;
21
+ pub struct SuperObject < ' gc > {
22
+ /// The object present as `this` throughout the superchain.
23
+ this : Object < ' gc > ,
24
+
25
+ /// The prototype depth of the currently-executing method.
26
+ depth : u8 ,
27
+
28
+ /// Adds a niche, so that enums contaning this type can use it for their discriminant.
29
+ _niche : crate :: utils:: ZeroU8 ,
30
+ }
22
31
23
32
impl fmt:: Debug for SuperObject < ' _ > {
24
33
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
25
34
f. debug_struct ( "SuperObject" )
26
- . field ( "ptr" , & Gc :: as_ptr ( self . 0 ) )
35
+ . field ( "this" , & self . this )
36
+ . field ( "depth" , & self . depth )
27
37
. finish ( )
28
38
}
29
39
}
30
40
31
- #[ derive( Clone , Collect ) ]
32
- #[ collect( no_drop) ]
33
- pub struct SuperObjectData < ' gc > {
34
- /// The object present as `this` throughout the superchain.
35
- this : Object < ' gc > ,
36
-
37
- /// The prototype depth of the currently-executing method.
38
- depth : u8 ,
39
- }
40
-
41
41
impl < ' gc > SuperObject < ' gc > {
42
42
/// Construct a `super` for an incoming stack frame.
43
- pub fn new ( activation : & mut Activation < ' _ , ' gc > , this : Object < ' gc > , depth : u8 ) -> Self {
44
- Self ( Gc :: new ( activation. gc ( ) , SuperObjectData { this, depth } ) )
43
+ pub fn new ( this : Object < ' gc > , depth : u8 ) -> Self {
44
+ Self {
45
+ this,
46
+ depth,
47
+ _niche : Default :: default ( ) ,
48
+ }
45
49
}
46
50
47
51
pub fn this ( & self ) -> Object < ' gc > {
48
- self . 0 . this
52
+ self . this
49
53
}
50
54
51
55
pub fn depth ( & self ) -> u8 {
52
- self . 0 . depth
56
+ self . depth
53
57
}
54
58
55
59
pub ( super ) fn base_proto ( & self , activation : & mut Activation < ' _ , ' gc > ) -> Object < ' gc > {
56
- let depth = self . 0 . depth ;
57
- let mut proto = self . 0 . this ;
58
- for _ in 0 ..depth {
60
+ let mut proto = self . this ( ) ;
61
+ for _ in 0 ..self . depth ( ) {
59
62
proto = proto. proto ( activation) . coerce_to_object ( activation) ;
60
63
}
61
64
proto
@@ -83,8 +86,8 @@ impl<'gc> SuperObject<'gc> {
83
86
constr. as_constructor ( ) . exec (
84
87
name. into ( ) ,
85
88
activation,
86
- self . 0 . this . into ( ) ,
87
- self . 0 . depth + 1 ,
89
+ self . this ( ) . into ( ) ,
90
+ self . depth ( ) + 1 ,
88
91
args,
89
92
ExecutionReason :: FunctionCall ,
90
93
constructor,
@@ -98,7 +101,7 @@ impl<'gc> SuperObject<'gc> {
98
101
activation : & mut Activation < ' _ , ' gc > ,
99
102
reason : ExecutionReason ,
100
103
) -> Result < Value < ' gc > , Error < ' gc > > {
101
- let this = self . 0 . this ;
104
+ let this = self . this ( ) ;
102
105
let ( method, depth) =
103
106
match search_prototype ( self . proto ( activation) , name, activation, this, false ) ? {
104
107
Some ( ( Value :: Object ( method) , depth) ) => ( method, depth) ,
@@ -110,7 +113,7 @@ impl<'gc> SuperObject<'gc> {
110
113
ExecutionName :: Dynamic ( name) ,
111
114
activation,
112
115
this. into ( ) ,
113
- self . 0 . depth + depth + 1 ,
116
+ self . depth ( ) + depth + 1 ,
114
117
args,
115
118
reason,
116
119
method,
0 commit comments