11use core:: ops:: { Index , IndexMut } ;
22
3+ pub ( crate ) mod data;
4+
35use crate :: {
46 ecmascript:: {
57 builders:: { builtin_function_builder:: BuiltinFunctionBuilder , ordinary_object_builder:: OrdinaryObjectBuilder } ,
68 builtins:: {
79 ArgumentsList , Behaviour , Builtin , BuiltinIntrinsicConstructor
810 } ,
9- execution:: { agent:: Agent , JsResult , Realm } ,
11+ execution:: { agent:: Agent , JsResult , ProtoIntrinsics , Realm } ,
1012 types:: {
1113 InternalMethods , InternalSlots , IntoObject , Object , OrdinaryObject , String , Value , BUILTIN_STRING_MEMORY
1214 } ,
1315 } ,
14- engine:: { context:: { bindable_handle, GcScope , NoGcScope } , rootable:: { HeapRootRef , Rootable } } ,
16+ engine:: { context:: { bindable_handle, Bindable , GcScope , NoGcScope } , rootable:: { HeapRootData , HeapRootRef , Rootable } } ,
1517 heap:: { indexes:: BaseIndex , CompactionLists , CreateHeapData , Heap , HeapMarkAndSweep , HeapSweepWeakReference , IntrinsicConstructorIndexes , WorkQueues } ,
1618} ;
1719/// Constructor function object for %Temporal.Instant%.
@@ -58,36 +60,11 @@ impl InstantPrototype {
5860 . build ( ) ;
5961 }
6062}
61- /// HEAP DATA -- Move to internal instant/data.rs
62- #[ derive( Debug , Clone , Copy ) ]
63- pub ( crate ) struct InstantValue ( /*TODO:BigInt*/ ) ;
64-
65- impl InstantValue {
66- // TODO
67- }
68- #[ derive( Debug , Clone , Copy ) ]
69- pub struct InstantHeapData < ' a > {
70- pub ( crate ) object_index : Option < OrdinaryObject < ' a > > ,
71- pub ( crate ) date : InstantValue ,
72- }
73-
74- impl InstantHeapData < ' _ > {
75- // TODO
76- }
7763
78- bindable_handle ! ( InstantHeapData ) ;
7964
80- impl HeapMarkAndSweep for InstantHeapData < ' static > {
81- fn mark_values ( & self , queues : & mut crate :: heap:: WorkQueues ) {
82- todo ! ( )
83- }
84- fn sweep_values ( & mut self , compactions : & crate :: heap:: CompactionLists ) {
85- todo ! ( )
86- }
87- }
88-
89- // HANDLES -- Keep public facing within instant.rs
65+ use self :: data:: InstantHeapData ;
9066#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
67+ #[ repr( transparent) ]
9168pub struct Instant < ' a > ( BaseIndex < ' a , InstantHeapData < ' static > > ) ;
9269impl Instant < ' _ > {
9370 //TODO
@@ -103,20 +80,20 @@ bindable_handle!(Instant);
10380
10481impl < ' a > From < Instant < ' a > > for Value < ' a > {
10582 fn from ( value : Instant < ' a > ) -> Self {
106- Value :: Instant ( value) // todo: add to value.rs
83+ Value :: Instant ( value)
10784 }
10885}
10986impl < ' a > From < Instant < ' a > > for Object < ' a > {
11087 fn from ( value : Instant < ' a > ) -> Self {
111- Object :: Instant ( value) // todo: add to object.rs
88+ Object :: Instant ( value)
11289 }
11390}
11491impl < ' a > TryFrom < Value < ' a > > for Instant < ' a > {
11592 type Error = ( ) ;
11693
11794 fn try_from ( value : Value < ' a > ) -> Result < Self , ( ) > {
11895 match value {
119- Value :: Instant ( idx) => Ok ( idx) , // todo: add to value.rs
96+ Value :: Instant ( idx) => Ok ( idx) ,
12097 _ => Err ( ( ) ) ,
12198 }
12299 }
@@ -125,66 +102,103 @@ impl<'a> TryFrom<Object<'a>> for Instant<'a> {
125102 type Error = ( ) ;
126103 fn try_from ( object : Object < ' a > ) -> Result < Self , ( ) > {
127104 match object {
128- Object :: Instant ( idx) => Ok ( idx) , // todo: add to object.rs
105+ Object :: Instant ( idx) => Ok ( idx) ,
129106 _ => Err ( ( ) ) ,
130107 }
131108 }
132109}
133110
134- // TODO impl trait bounds properly
135111impl < ' a > InternalSlots < ' a > for Instant < ' a > {
136- // TODO: Add TemporalInstant to ProtoIntrinsics
137- //const DEFAULT_PROTOTYPE: ProtoIntrinsics = ProtoIntrinsics::TemporalInstant;
112+ const DEFAULT_PROTOTYPE : ProtoIntrinsics = ProtoIntrinsics :: TemporalInstant ;
138113 fn get_backing_object ( self , agent : & Agent ) -> Option < OrdinaryObject < ' static > > {
139- todo ! ( )
114+ agent [ self ] . object_index // not implemented for `agent::Agent`
140115 }
141116 fn set_backing_object ( self , agent : & mut Agent , backing_object : OrdinaryObject < ' static > ) {
142- todo ! ( )
117+ assert ! ( agent [ self ] . object_index . replace ( backing_object ) . is_none ( ) ) ; // not implemented for `agent::Agent`
143118 }
144119
145120}
146121
147122impl < ' a > InternalMethods < ' a > for Instant < ' a > { }
148123
149- impl HeapMarkAndSweep for Instant < ' static > {
150- fn mark_values ( & self , queues : & mut WorkQueues ) {
151- todo ! ( )
124+ impl Index < Instant < ' _ > > for Agent {
125+ type Output = InstantHeapData < ' static > ;
126+
127+ fn index ( & self , index : Instant < ' _ > ) -> & Self :: Output {
128+ & self . heap . instants [ index]
152129 }
153- fn sweep_values ( & mut self , compactions : & CompactionLists ) {
154- todo ! ( )
130+ }
131+
132+ impl IndexMut < Instant < ' _ > > for Agent {
133+ fn index_mut ( & mut self , index : Instant ) -> & mut Self :: Output {
134+ & mut self . heap . instants [ index]
155135 }
156136}
157137
158- impl HeapSweepWeakReference for Instant < ' static > {
159- fn sweep_weak_reference ( self , compactions : & CompactionLists ) -> Option < Self > {
160- compactions. dates . shift_weak_index ( self . 0 ) . map ( Self )
138+ impl Index < Instant < ' _ > > for Vec < Option < InstantHeapData < ' static > > > {
139+ type Output = InstantHeapData < ' static > ;
140+
141+ fn index ( & self , index : Instant < ' _ > ) -> & Self :: Output {
142+ self . get ( index. get_index ( ) )
143+ . expect ( "heap access out of bounds" )
144+ . as_ref ( )
145+ . expect ( "" )
161146 }
162147}
163148
164- impl < ' a > CreateHeapData < InstantHeapData < ' a > , Instant < ' a > > for Heap {
165- fn create ( & mut self , data : InstantHeapData < ' a > ) -> Instant < ' a > {
166- todo ! ( )
149+ impl IndexMut < Instant < ' _ > > for Vec < Option < InstantHeapData < ' static > > > {
150+ fn index_mut ( & mut self , index : Instant < ' _ > ) -> & mut Self :: Output {
151+ self . get_mut ( index. get_index ( ) )
152+ . expect ( "dasdas" )
153+ . as_mut ( )
154+ . expect ( "" )
167155 }
168156}
169157
170- /* todo - impl keep public facing in temporal/instant.rs
158+
171159impl Rootable for Instant < ' _ > {
172160 type RootRepr = HeapRootRef ;
173161
174162 fn to_root_repr ( value : Self ) -> Result < Self :: RootRepr , crate :: engine:: rootable:: HeapRootData > {
175- todo!( )
163+ Err ( HeapRootData :: Instant ( value . unbind ( ) ) )
176164 }
177165
178166 fn from_root_repr ( value : & Self :: RootRepr ) -> Result < Self , crate :: engine:: rootable:: HeapRootRef > {
179- todo!( )
167+ Err ( * value )
180168 }
181169
182170 fn from_heap_ref ( heap_ref : crate :: engine:: rootable:: HeapRootRef ) -> Self :: RootRepr {
183- todo!()
171+ heap_ref
184172 }
185173
186174 fn from_heap_data ( heap_data : crate :: engine:: rootable:: HeapRootData ) -> Option < Self > {
187- todo!()
175+ match heap_data {
176+ HeapRootData :: Instant ( object) => Some ( object) ,
177+ _ => None ,
178+ }
179+ }
180+ }
181+
182+
183+ impl HeapMarkAndSweep for Instant < ' static > {
184+ fn mark_values ( & self , queues : & mut WorkQueues ) {
185+ queues. instants . push ( * self ) ;
186+ }
187+ fn sweep_values ( & mut self , compactions : & CompactionLists ) {
188+ compactions. instants . shift_index ( & mut self . 0 ) ;
189+ }
190+ }
191+
192+ impl HeapSweepWeakReference for Instant < ' static > {
193+ fn sweep_weak_reference ( self , compactions : & CompactionLists ) -> Option < Self > {
194+ compactions. dates . shift_weak_index ( self . 0 ) . map ( Self )
195+ }
196+ }
197+
198+ impl < ' a > CreateHeapData < InstantHeapData < ' a > , Instant < ' a > > for Heap {
199+ fn create ( & mut self , data : InstantHeapData < ' a > ) -> Instant < ' a > {
200+ self . instants . push ( Some ( data. unbind ( ) ) ) ;
201+ self . alloc_counter += core:: mem:: size_of :: < Option < InstantHeapData < ' static > > > ( ) ;
202+ Instant ( BaseIndex :: last ( & self . instants ) )
188203 }
189204}
190- */
0 commit comments