@@ -8,7 +8,10 @@ use wtf8::Wtf8Buf;
8
8
9
9
use crate :: {
10
10
ecmascript:: {
11
- builtins:: regexp:: { RegExp , reg_exp_create_literal} ,
11
+ builtins:: {
12
+ ordinary:: shape:: ObjectShape ,
13
+ regexp:: { RegExp , reg_exp_create_literal} ,
14
+ } ,
12
15
execution:: Agent ,
13
16
types:: { BigInt , IntoValue , Number , PropertyKey , String , Value } ,
14
17
} ,
@@ -35,6 +38,8 @@ pub(super) struct ExecutableContext<'agent, 'gc, 'scope> {
35
38
instructions : Vec < u8 > ,
36
39
/// Constants being built
37
40
constants : Vec < Value < ' gc > > ,
41
+ /// Object Shapes being built
42
+ shapes : Vec < ObjectShape < ' gc > > ,
38
43
/// Function expressions being built
39
44
function_expressions : Vec < FunctionExpression < ' gc > > ,
40
45
/// Arrow function expressions being built
@@ -50,6 +55,7 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
50
55
current_instruction_pointer_is_unreachable : false ,
51
56
instructions : Vec :: new ( ) ,
52
57
constants : Vec :: new ( ) ,
58
+ shapes : Vec :: new ( ) ,
53
59
function_expressions : Vec :: new ( ) ,
54
60
arrow_function_expressions : Vec :: new ( ) ,
55
61
class_initializer_bytecodes : Vec :: new ( ) ,
@@ -114,6 +120,7 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
114
120
self . agent . heap . create ( ExecutableHeapData {
115
121
instructions : self . instructions . into_boxed_slice ( ) ,
116
122
constants : self . constants . unbind ( ) . into_boxed_slice ( ) ,
123
+ shapes : self . shapes . unbind ( ) . into_boxed_slice ( ) ,
117
124
function_expressions : self . function_expressions . unbind ( ) . into_boxed_slice ( ) ,
118
125
arrow_function_expressions : self . arrow_function_expressions . into_boxed_slice ( ) ,
119
126
class_initializer_bytecodes : self
@@ -189,6 +196,21 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
189
196
} )
190
197
}
191
198
199
+ pub ( super ) fn add_shape ( & mut self , shape : ObjectShape < ' gc > ) -> usize {
200
+ let duplicate = self
201
+ . shapes
202
+ . iter ( )
203
+ . enumerate ( )
204
+ . find ( |item| item. 1 . eq ( & shape) )
205
+ . map ( |( idx, _) | idx) ;
206
+
207
+ duplicate. unwrap_or_else ( || {
208
+ let index = self . shapes . len ( ) ;
209
+ self . shapes . push ( shape) ;
210
+ index
211
+ } )
212
+ }
213
+
192
214
pub ( super ) fn add_instruction_with_immediate (
193
215
& mut self ,
194
216
instruction : Instruction ,
@@ -299,6 +321,18 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
299
321
index as IndexType
300
322
}
301
323
324
+ pub ( super ) fn add_instruction_with_shape (
325
+ & mut self ,
326
+ instruction : Instruction ,
327
+ shape : ObjectShape < ' gc > ,
328
+ ) {
329
+ debug_assert_eq ! ( instruction. argument_count( ) , 1 ) ;
330
+ debug_assert ! ( instruction. has_shape_index( ) ) ;
331
+ self . push_instruction ( instruction) ;
332
+ let shape = self . add_shape ( shape) ;
333
+ self . add_index ( shape) ;
334
+ }
335
+
302
336
pub ( super ) fn add_arrow_function_expression (
303
337
& mut self ,
304
338
arrow_function_expression : ArrowFunctionExpression ,
0 commit comments