@@ -35,20 +35,61 @@ use crate::{
3535 IntrinsicConstructorIndexes , WorkQueues , indexes:: BaseIndex ,
3636 } ,
3737} ;
38+
3839/// Constructor function object for %Temporal.Instant%.
3940pub ( crate ) struct TemporalInstantConstructor ;
41+
4042impl Builtin for TemporalInstantConstructor {
4143 const NAME : String < ' static > = BUILTIN_STRING_MEMORY . Instant ;
4244 const LENGTH : u8 = 1 ;
43- const BEHAVIOUR : Behaviour = Behaviour :: Constructor ( TemporalInstantConstructor :: construct ) ;
45+ const BEHAVIOUR : Behaviour = Behaviour :: Constructor ( TemporalInstantConstructor :: constructor ) ;
4446}
47+
4548impl BuiltinIntrinsicConstructor for TemporalInstantConstructor {
4649 const INDEX : IntrinsicConstructorIndexes = IntrinsicConstructorIndexes :: TemporalInstant ;
4750}
4851
52+ struct TemporalInstantFrom ;
53+ impl Builtin for TemporalInstantFrom {
54+ const NAME : String < ' static > = BUILTIN_STRING_MEMORY . from ;
55+
56+ const LENGTH : u8 = 1 ;
57+
58+ const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalInstantConstructor :: from) ;
59+ }
60+
61+ struct TemporalInstantFromEpochMilliseconds ;
62+ impl Builtin for TemporalInstantFromEpochMilliseconds {
63+ const NAME : String < ' static > = BUILTIN_STRING_MEMORY . fromEpochMilliseconds ;
64+
65+ const LENGTH : u8 = 1 ;
66+
67+ const BEHAVIOUR : Behaviour =
68+ Behaviour :: Regular ( TemporalInstantConstructor :: from_epoch_milliseconds) ;
69+ }
70+
71+ struct TemporalInstantFromEpochNanoseconds ;
72+ impl Builtin for TemporalInstantFromEpochNanoseconds {
73+ const NAME : String < ' static > = BUILTIN_STRING_MEMORY . fromEpochNanoseconds ;
74+
75+ const LENGTH : u8 = 1 ;
76+
77+ const BEHAVIOUR : Behaviour =
78+ Behaviour :: Regular ( TemporalInstantConstructor :: from_epoch_nanoseconds) ;
79+ }
80+
81+ struct TemporalInstantCompare ;
82+ impl Builtin for TemporalInstantCompare {
83+ const NAME : String < ' static > = BUILTIN_STRING_MEMORY . compare ;
84+
85+ const LENGTH : u8 = 2 ;
86+
87+ const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalInstantConstructor :: compare) ;
88+ }
89+
4990impl TemporalInstantConstructor {
5091 /// ### [8.1.1 Temporal.Instant ( epochNanoseconds )](https://tc39.es/proposal-temporal/#sec-temporal.instant)
51- fn construct < ' gc > (
92+ fn constructor < ' gc > (
5293 agent : & mut Agent ,
5394 _: Value ,
5495 args : ArgumentsList ,
@@ -101,10 +142,10 @@ impl TemporalInstantConstructor {
101142 fn from < ' gc > (
102143 agent : & mut Agent ,
103144 _this_value : Value ,
104- arguments : ArgumentsList ,
145+ args : ArgumentsList ,
105146 gc : GcScope < ' gc , ' _ > ,
106147 ) -> JsResult < ' gc , Value < ' gc > > {
107- let item = arguments . get ( 0 ) . bind ( gc. nogc ( ) ) ;
148+ let item = args . get ( 0 ) . bind ( gc. nogc ( ) ) ;
108149 // 1. Return ? ToTemporalInstant(item).
109150 let instant = to_temporal_instant ( agent, item. unbind ( ) , gc) ?;
110151 let instant = agent. heap . create ( InstantRecord {
@@ -118,10 +159,10 @@ impl TemporalInstantConstructor {
118159 fn from_epoch_milliseconds < ' gc > (
119160 agent : & mut Agent ,
120161 _this_value : Value ,
121- arguments : ArgumentsList ,
162+ args : ArgumentsList ,
122163 mut gc : GcScope < ' gc , ' _ > ,
123164 ) -> JsResult < ' gc , Value < ' gc > > {
124- let epoch_ms = arguments . get ( 0 ) . bind ( gc. nogc ( ) ) ;
165+ let epoch_ms = args . get ( 0 ) . bind ( gc. nogc ( ) ) ;
125166 // 1. Set epochMilliseconds to ? ToNumber(epochMilliseconds).
126167 let epoch_ms_number = epoch_ms
127168 . unbind ( )
@@ -190,19 +231,23 @@ impl TemporalInstantConstructor {
190231 Ok ( value)
191232 }
192233
193- /// [8.2.5 Temporal.Instant.compare ( one, two )](https://tc39.es/proposal-temporal/#sec-temporal.instant.compare)
234+ /// ### [8.2.5 Temporal.Instant.compare ( one, two )](https://tc39.es/proposal-temporal/#sec-temporal.instant.compare)
194235 fn compare < ' gc > (
195236 agent : & mut Agent ,
196237 _this_value : Value ,
197- arguments : ArgumentsList ,
238+ args : ArgumentsList ,
198239 mut gc : GcScope < ' gc , ' _ > ,
199240 ) -> JsResult < ' gc , Value < ' gc > > {
241+ let one = args. get ( 0 ) . bind ( gc. nogc ( ) ) ;
242+ let two = args. get ( 0 ) . bind ( gc. nogc ( ) ) ;
243+ let two = two. scope ( agent, gc. nogc ( ) ) ;
200244 // 1. Set one to ? ToTemporalInstant(one).
201- let one = arguments . get ( 0 ) . bind ( gc. nogc ( ) ) ;
245+ let one_instant = to_temporal_instant ( agent , one . unbind ( ) , gc. reborrow ( ) ) . unbind ( ) ? ;
202246 // 2. Set two to ? ToTemporalInstant(two).
203- let two = arguments. get ( 1 ) . bind ( gc. nogc ( ) ) ;
247+ let two_value = two. get ( agent) . bind ( gc. nogc ( ) ) ;
248+ let two_instant = to_temporal_instant ( agent, two_value. unbind ( ) , gc. reborrow ( ) ) . unbind ( ) ?;
204249 // 3. Return 𝔽(CompareEpochNanoseconds(one.[[EpochNanoseconds]], two.[[EpochNanoseconds]])).
205- todo ! ( )
250+ Ok ( ( one_instant . cmp ( & two_instant ) as i8 ) . into ( ) )
206251 }
207252
208253 pub ( crate ) fn create_intrinsic ( agent : & mut Agent , realm : Realm < ' static > , _gc : NoGcScope ) {
@@ -308,44 +353,6 @@ fn to_temporal_instant<'gc>(
308353/// %Temporal.Instant.Prototype%
309354pub ( crate ) struct TemporalInstantPrototype ;
310355
311- struct TemporalInstantFrom ;
312- impl Builtin for TemporalInstantFrom {
313- const NAME : String < ' static > = BUILTIN_STRING_MEMORY . from ;
314-
315- const LENGTH : u8 = 1 ;
316-
317- const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalInstantConstructor :: from) ;
318- }
319-
320- struct TemporalInstantFromEpochMilliseconds ;
321- impl Builtin for TemporalInstantFromEpochMilliseconds {
322- const NAME : String < ' static > = BUILTIN_STRING_MEMORY . fromEpochMilliseconds ;
323-
324- const LENGTH : u8 = 1 ;
325-
326- const BEHAVIOUR : Behaviour =
327- Behaviour :: Regular ( TemporalInstantConstructor :: from_epoch_milliseconds) ;
328- }
329-
330- struct TemporalInstantFromEpochNanoseconds ;
331- impl Builtin for TemporalInstantFromEpochNanoseconds {
332- const NAME : String < ' static > = BUILTIN_STRING_MEMORY . fromEpochNanoseconds ;
333-
334- const LENGTH : u8 = 1 ;
335-
336- const BEHAVIOUR : Behaviour =
337- Behaviour :: Regular ( TemporalInstantConstructor :: from_epoch_nanoseconds) ;
338- }
339-
340- struct TemporalInstantCompare ;
341- impl Builtin for TemporalInstantCompare {
342- const NAME : String < ' static > = BUILTIN_STRING_MEMORY . compare ;
343-
344- const LENGTH : u8 = 2 ;
345-
346- const BEHAVIOUR : Behaviour = Behaviour :: Regular ( TemporalInstantConstructor :: compare) ;
347- }
348-
349356impl TemporalInstantPrototype {
350357 pub fn create_intrinsic ( agent : & mut Agent , realm : Realm < ' static > , _: NoGcScope ) {
351358 let intrinsics = agent. get_realm_record_by_id ( realm) . intrinsics ( ) ;
0 commit comments