boa_engine 0.21.1

Boa is a Javascript lexer, parser and compiler written in Rust. Currently, it has support for some of the language.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
//! Boa's implementation of the ECMAScript `Temporal.PlainTime` built-in object.

use super::{
    PlainDateTime, ZonedDateTime, create_temporal_duration,
    options::{TemporalUnitGroup, get_difference_settings, get_temporal_unit},
    to_temporal_duration_record,
};
use crate::{
    Context, JsArgs, JsData, JsError, JsNativeError, JsObject, JsResult, JsString, JsSymbol,
    JsValue,
    builtins::{
        BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject,
        options::{get_option, get_options_object},
    },
    context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
    js_string,
    object::internal_methods::get_prototype_from_constructor,
    property::Attribute,
    realm::Realm,
    string::StaticJsStrings,
};
use crate::{builtins::temporal::options::get_digits_option, value::JsVariant};
use boa_gc::{Finalize, Trace};
use temporal_rs::{
    PlainTime as PlainTimeInner,
    options::{
        Overflow, RoundingIncrement, RoundingMode, RoundingOptions, ToStringRoundingOptions, Unit,
    },
    partial::PartialTime,
};

/// The `Temporal.PlainTime` built-in implementation.
///
/// More information:
///
/// - [ECMAScript Temporal proposal][spec]
/// - [MDN reference][mdn]
/// - [`temporal_rs` documentation][temporal_rs-docs]
///
/// [spec]: https://tc39.es/proposal-temporal/#sec-temporal-plaintime-objects
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime
/// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html
#[derive(Debug, Clone, Copy, Trace, Finalize, JsData)]
#[boa_gc(unsafe_empty_trace)] // Safety: PlainTimeInner does not contain any traceable types.
pub struct PlainTime {
    inner: PlainTimeInner,
}

impl BuiltInObject for PlainTime {
    const NAME: JsString = StaticJsStrings::PLAIN_TIME_NAME;
}

impl IntrinsicObject for PlainTime {
    fn init(realm: &Realm) {
        let get_hour = BuiltInBuilder::callable(realm, Self::get_hour)
            .name(js_string!("get hour"))
            .build();

        let get_minute = BuiltInBuilder::callable(realm, Self::get_minute)
            .name(js_string!("get minute"))
            .build();

        let get_second = BuiltInBuilder::callable(realm, Self::get_second)
            .name(js_string!("get second"))
            .build();

        let get_millisecond = BuiltInBuilder::callable(realm, Self::get_millisecond)
            .name(js_string!("get millisecond"))
            .build();

        let get_microsecond = BuiltInBuilder::callable(realm, Self::get_microsecond)
            .name(js_string!("get microsecond"))
            .build();

        let get_nanosecond = BuiltInBuilder::callable(realm, Self::get_nanosecond)
            .name(js_string!("get nanosecond"))
            .build();

        BuiltInBuilder::from_standard_constructor::<Self>(realm)
            .property(
                JsSymbol::to_string_tag(),
                StaticJsStrings::PLAIN_TIME_TAG,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("hour"),
                Some(get_hour),
                None,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("minute"),
                Some(get_minute),
                None,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("second"),
                Some(get_second),
                None,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("millisecond"),
                Some(get_millisecond),
                None,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("microsecond"),
                Some(get_microsecond),
                None,
                Attribute::CONFIGURABLE,
            )
            .accessor(
                js_string!("nanosecond"),
                Some(get_nanosecond),
                None,
                Attribute::CONFIGURABLE,
            )
            .static_method(Self::from, js_string!("from"), 1)
            .static_method(Self::compare, js_string!("compare"), 2)
            .method(Self::add, js_string!("add"), 1)
            .method(Self::subtract, js_string!("subtract"), 1)
            .method(Self::with, js_string!("with"), 1)
            .method(Self::until, js_string!("until"), 1)
            .method(Self::since, js_string!("since"), 1)
            .method(Self::round, js_string!("round"), 1)
            .method(Self::equals, js_string!("equals"), 1)
            .method(Self::to_string, js_string!("toString"), 0)
            .method(Self::to_locale_string, js_string!("toLocaleString"), 0)
            .method(Self::to_json, js_string!("toJSON"), 0)
            .method(Self::value_of, js_string!("valueOf"), 0)
            .build();
    }

    fn get(intrinsics: &Intrinsics) -> JsObject {
        Self::STANDARD_CONSTRUCTOR(intrinsics.constructors()).constructor()
    }
}

impl BuiltInConstructor for PlainTime {
    const CONSTRUCTOR_ARGUMENTS: usize = 0;
    const PROTOTYPE_STORAGE_SLOTS: usize = 24;
    const CONSTRUCTOR_STORAGE_SLOTS: usize = 2;

    const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
        StandardConstructors::plain_time;

    fn constructor(
        new_target: &JsValue,
        args: &[JsValue],
        context: &mut Context,
    ) -> JsResult<JsValue> {
        // 1. If NewTarget is undefined, then
        if new_target.is_undefined() {
            // a. Throw a TypeError exception.
            return Err(JsNativeError::typ()
                .with_message("NewTarget cannot be undefined.")
                .into());
        }

        // 2. If hour is undefined, set hour to 0; else set hour to ? ToIntegerWithTruncation(hour).
        let hour = args.get_or_undefined(0).map_or(Ok::<u8, JsError>(0), |v| {
            let finite = v.to_finitef64(context)?;
            let int = finite.as_integer_with_truncation::<i8>();
            if int < 0 {
                return Err(JsNativeError::range()
                    .with_message("invalid time field")
                    .into());
            }
            Ok(int as u8)
        })?;
        // 3. If minute is undefined, set minute to 0; else set minute to ? ToIntegerWithTruncation(minute).
        let minute = args.get_or_undefined(1).map_or(Ok::<u8, JsError>(0), |v| {
            let finite = v.to_finitef64(context)?;
            let int = finite.as_integer_with_truncation::<i8>();
            if int < 0 {
                return Err(JsNativeError::range()
                    .with_message("invalid time field")
                    .into());
            }
            Ok(int as u8)
        })?;
        // 4. If second is undefined, set second to 0; else set second to ? ToIntegerWithTruncation(second).
        let second = args.get_or_undefined(2).map_or(Ok::<u8, JsError>(0), |v| {
            let finite = v.to_finitef64(context)?;
            let int = finite.as_integer_with_truncation::<i8>();
            if int < 0 {
                return Err(JsNativeError::range()
                    .with_message("invalid time field")
                    .into());
            }
            Ok(int as u8)
        })?;

        // 5. If millisecond is undefined, set millisecond to 0; else set millisecond to ? ToIntegerWithTruncation(millisecond).
        let millisecond = args
            .get_or_undefined(3)
            .map_or(Ok::<u16, JsError>(0), |v| {
                let finite = v.to_finitef64(context)?;
                let int = finite.as_integer_with_truncation::<i16>();
                if int < 0 {
                    return Err(JsNativeError::range()
                        .with_message("invalid time field")
                        .into());
                }
                Ok(int as u16)
            })?;

        // 6. If microsecond is undefined, set microsecond to 0; else set microsecond to ? ToIntegerWithTruncation(microsecond).
        let microsecond = args
            .get_or_undefined(4)
            .map_or(Ok::<u16, JsError>(0), |v| {
                let finite = v.to_finitef64(context)?;
                let int = finite.as_integer_with_truncation::<i16>();
                if int < 0 {
                    return Err(JsNativeError::range()
                        .with_message("invalid time field")
                        .into());
                }
                Ok(int as u16)
            })?;

        // 7. If nanosecond is undefined, set nanosecond to 0; else set nanosecond to ? ToIntegerWithTruncation(nanosecond).
        let nanosecond = args
            .get_or_undefined(5)
            .map_or(Ok::<u16, JsError>(0), |v| {
                let finite = v.to_finitef64(context)?;
                let int = finite.as_integer_with_truncation::<i16>();
                if int < 0 {
                    return Err(JsNativeError::range()
                        .with_message("invalid time field")
                        .into());
                }
                Ok(int as u16)
            })?;

        let inner =
            PlainTimeInner::try_new(hour, minute, second, millisecond, microsecond, nanosecond)?;

        // 8. Return ? CreateTemporalTime(hour, minute, second, millisecond, microsecond, nanosecond, NewTarget).
        create_temporal_time(inner, Some(new_target), context).map(Into::into)
    }
}

// ==== PlainTime accessor methods implementation ====

impl PlainTime {
    /// 4.3.3 get `Temporal.PlainTime.prototype.hour`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.hour
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/hour
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.hour
    fn get_hour(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISOHour]]).
        Ok(time.inner.hour().into())
    }

    /// 4.3.4 get `Temporal.PlainTime.prototype.minute`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.minute
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/minute
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.minute
    fn get_minute(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISOMinute]]).
        Ok(time.inner.minute().into())
    }

    /// 4.3.5 get `Temporal.PlainTime.prototype.second`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.second
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/second
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.second
    fn get_second(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISOSecond]]).
        Ok(time.inner.second().into())
    }

    /// 4.3.6 get `Temporal.PlainTime.prototype.millisecond`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.millisecond
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/millisecond
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.millisecond
    fn get_millisecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISOMillisecond]]).
        Ok(time.inner.millisecond().into())
    }

    /// 4.3.7 get `Temporal.PlainTime.prototype.microsecond`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.microsecond
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/microsecond
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.microsecond
    fn get_microsecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISOMicrosecond]]).
        Ok(time.inner.microsecond().into())
    }

    /// 4.3.8 get `Temporal.PlainTime.prototype.nanosecond`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.nanosecond
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/nanosecond
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.nanosecond
    fn get_nanosecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Return 𝔽(temporalTime.[[ISONanosecond]]).
        Ok(time.inner.nanosecond().into())
    }
}

// ==== PlainTime static methods implementation ====

impl PlainTime {
    /// 4.2.2 `Temporal.PlainTime.from ( item [ , options ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.from
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/from
    fn from(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Return ? ToTemporalTime(item, options).
        let plain_time = to_temporal_time(args.get_or_undefined(0), args.get(1), context)?;
        create_temporal_time(plain_time, None, context).map(Into::into)
    }

    /// 4.2.3 `Temporal.PlainTime.compare ( one, two )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.compare
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/compare
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#impl-Ord-for-PlainTime
    fn compare(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Set one to ? ToTemporalTime(one).
        let one = to_temporal_time(args.get_or_undefined(0), None, context)?;
        // 2. Set two to ? ToTemporalTime(two).
        let two = to_temporal_time(args.get_or_undefined(1), None, context)?;
        // 3. Return 𝔽(CompareTemporalTime(one.[[ISOHour]], one.[[ISOMinute]], one.[[ISOSecond]],
        // one.[[ISOMillisecond]], one.[[ISOMicrosecond]], one.[[ISONanosecond]], two.[[ISOHour]],
        // two.[[ISOMinute]], two.[[ISOSecond]], two.[[ISOMillisecond]], two.[[ISOMicrosecond]],
        // two.[[ISONanosecond]])).
        Ok((one.cmp(&two) as i8).into())
    }
}

// ==== PlainTime.prototype method implementations ====

impl PlainTime {
    /// 4.3.9 `Temporal.PlainTime.prototype.add ( temporalDurationLike )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.add
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/add
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.add
    fn add(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let temporal_duration_like = args.get_or_undefined(0);
        let duration = to_temporal_duration_record(temporal_duration_like, context)?;

        // 3. Return ? AddDurationToOrSubtractDurationFromPlainTime(add, temporalTime, temporalDurationLike).
        create_temporal_time(time.inner.add(&duration)?, None, context).map(Into::into)
    }

    /// 4.3.10 `Temporal.PlainTime.prototype.subtract ( temporalDurationLike )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.subtract
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/subtract
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.subtract
    fn subtract(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let temporal_duration_like = args.get_or_undefined(0);
        let duration = to_temporal_duration_record(temporal_duration_like, context)?;

        // 3. Return ? AddDurationToOrSubtractDurationFromPlainTime(subtract, temporalTime, temporalDurationLike).
        create_temporal_time(time.inner.subtract(&duration)?, None, context).map(Into::into)
    }

    /// 4.3.11 `Temporal.PlainTime.prototype.with ( temporalTimeLike [ , options ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.with
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/with
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.with
    fn with(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1.Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. If ? IsPartialTemporalObject(temporalTimeLike) is false, throw a TypeError exception.
        // 4. Set options to ? GetOptionsObject(options).
        let Some(partial_object) =
            super::is_partial_temporal_object(args.get_or_undefined(0), context)?
        else {
            return Err(JsNativeError::typ()
                .with_message("with object was not a PartialTemporalObject.")
                .into());
        };

        // Steps 5-16 equate to the below
        let partial = to_partial_time_record(&partial_object, context)?;
        // 17. Let resolvedOptions be ? GetOptionsObject(options).
        // 18. Let overflow be ? GetTemporalOverflowOption(resolvedOptions).
        let options = get_options_object(args.get_or_undefined(1))?;
        let overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;

        create_temporal_time(time.inner.with(partial, overflow)?, None, context).map(Into::into)
    }

    /// 4.3.12 `Temporal.PlainTime.prototype.until ( other [ , options ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.until
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/until
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.until
    fn until(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let other = to_temporal_time(args.get_or_undefined(0), None, context)?;

        let settings =
            get_difference_settings(&get_options_object(args.get_or_undefined(1))?, context)?;

        let result = time.inner.until(&other, settings)?;

        create_temporal_duration(result, None, context).map(Into::into)
    }

    /// 4.3.13 `Temporal.PlainTime.prototype.since ( other [ , options ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.since
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/since
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.since
    fn since(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let other = to_temporal_time(args.get_or_undefined(0), None, context)?;

        let settings =
            get_difference_settings(&get_options_object(args.get_or_undefined(1))?, context)?;

        let result = time.inner.since(&other, settings)?;

        create_temporal_duration(result, None, context).map(Into::into)
    }

    /// 4.3.14 Temporal.PlainTime.prototype.round ( roundTo )
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/round
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.round
    fn round(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let round_to = match args.first().map(JsValue::variant) {
            // 3. If roundTo is undefined, then
            None | Some(JsVariant::Undefined) => {
                return Err(JsNativeError::typ()
                    .with_message("roundTo cannot be undefined.")
                    .into());
            }
            // 4. If Type(roundTo) is String, then
            Some(JsVariant::String(rt)) => {
                // a. Let paramString be roundTo.
                let param_string = rt.clone();
                // b. Set roundTo to OrdinaryObjectCreate(null).
                let new_round_to = JsObject::with_null_proto();
                // c. Perform ! CreateDataPropertyOrThrow(roundTo, "smallestUnit", paramString).
                new_round_to.create_data_property_or_throw(
                    js_string!("smallestUnit"),
                    param_string,
                    context,
                )?;
                new_round_to
            }
            // 5. Else,
            Some(round_to) => {
                // a. Set roundTo to ? GetOptionsObject(roundTo).
                get_options_object(&JsValue::from(round_to))?
            }
        };

        let mut options = RoundingOptions::default();
        // 6. NOTE: The following steps read options and perform independent validation in alphabetical order (ToTemporalRoundingIncrement reads "roundingIncrement" and ToTemporalRoundingMode reads "roundingMode").
        // 7. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo).
        options.increment =
            get_option::<RoundingIncrement>(&round_to, js_string!("roundingIncrement"), context)?;

        // 8. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
        options.rounding_mode =
            get_option::<RoundingMode>(&round_to, js_string!("roundingMode"), context)?;

        // 9. Let smallestUnit be ? GetTemporalUnit(roundTo, "smallestUnit", time, required).
        options.smallest_unit = get_temporal_unit(
            &round_to,
            js_string!("smallestUnit"),
            TemporalUnitGroup::Time,
            None,
            context,
        )?;

        // 10. Let maximum be MaximumTemporalDurationRoundingIncrement(smallestUnit).
        // 11. Assert: maximum is not undefined.
        // 12. Perform ? ValidateTemporalRoundingIncrement(roundingIncrement, maximum, false).
        // 13. Let result be RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode).
        let result = time.inner.round(options)?;

        // 14. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
        create_temporal_time(result, None, context).map(Into::into)
    }

    /// 4.3.15 Temporal.PlainTime.prototype.equals ( other )
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.equals
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/equals
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#impl-Eq-for-PlainTime
    fn equals(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        // 1. Let temporalTime be the this value.
        // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        // 3. Set other to ? ToTemporalTime(other).
        let other = to_temporal_time(args.get_or_undefined(0), None, context)?;
        // 4. If temporalTime.[[ISOHour]] ≠ other.[[ISOHour]], return false.
        // 5. If temporalTime.[[ISOMinute]] ≠ other.[[ISOMinute]], return false.
        // 6. If temporalTime.[[ISOSecond]] ≠ other.[[ISOSecond]], return false.
        // 7. If temporalTime.[[ISOMillisecond]] ≠ other.[[ISOMillisecond]], return false.
        // 8. If temporalTime.[[ISOMicrosecond]] ≠ other.[[ISOMicrosecond]], return false.
        // 9. If temporalTime.[[ISONanosecond]] ≠ other.[[ISONanosecond]], return false.
        // 10. Return true.
        Ok((time.inner == other).into())
    }

    /// 4.3.16 `Temporal.PlainTime.prototype.toString ( [ options ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    /// - [`temporal_rs` documentation][temporal_rs-docs]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.tostring
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/toString
    /// [temporal_rs-docs]: https://docs.rs/temporal_rs/latest/temporal_rs/struct.PlainTime.html#method.to_ixdtf_string
    fn to_string(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let options = get_options_object(args.get_or_undefined(0))?;

        let precision = get_digits_option(&options, context)?;
        let rounding_mode =
            get_option::<RoundingMode>(&options, js_string!("roundingMode"), context)?;
        let smallest_unit = get_option::<Unit>(&options, js_string!("smallestUnit"), context)?;

        let options = ToStringRoundingOptions {
            precision,
            rounding_mode,
            smallest_unit,
        };

        let ixdtf = time.inner.to_ixdtf_string(options)?;

        Ok(JsString::from(ixdtf).into())
    }

    /// 4.3.17 `Temporal.PlainTime.prototype.toLocaleString ( [ locales [ , options ] ] )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.tolocalestring
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/toLocaleString
    fn to_locale_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // TODO: Update for ECMA-402 compliance
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let ixdtf = time
            .inner
            .to_ixdtf_string(ToStringRoundingOptions::default())?;
        Ok(JsString::from(ixdtf).into())
    }

    /// 4.3.18 `Temporal.PlainTime.prototype.toJSON ( )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.tojson
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/toJSON
    fn to_json(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        let object = this.as_object();
        let time = object
            .as_ref()
            .and_then(JsObject::downcast_ref::<Self>)
            .ok_or_else(|| {
                JsNativeError::typ().with_message("the this object must be a PlainTime object.")
            })?;

        let ixdtf = time
            .inner
            .to_ixdtf_string(ToStringRoundingOptions::default())?;
        Ok(JsString::from(ixdtf).into())
    }

    /// 4.3.19 `Temporal.PlainTime.prototype.valueOf ( )`
    ///
    /// More information:
    ///
    /// - [ECMAScript Temporal proposal][spec]
    /// - [MDN reference][mdn]
    ///
    /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
    /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/valueOf
    fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
        // 1. Throw a TypeError exception.
        Err(JsNativeError::typ()
            .with_message("`valueOf` not supported by Temporal built-ins. See 'compare', 'equals', or `toString`")
            .into())
    }
}

// ==== PlainTime Abstract Operations ====

pub(crate) fn create_temporal_time(
    inner: PlainTimeInner,
    new_target: Option<&JsValue>,
    context: &mut Context,
) -> JsResult<JsObject> {
    // Note: IsValidTime is enforced by Time.
    // 1. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.

    // 2. If newTarget is not present, set newTarget to %Temporal.PlainTime%.
    let new_target = if let Some(new_target) = new_target {
        new_target.clone()
    } else {
        context
            .realm()
            .intrinsics()
            .constructors()
            .plain_time()
            .constructor()
            .into()
    };

    // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]] »).
    let prototype =
        get_prototype_from_constructor(&new_target, StandardConstructors::plain_time, context)?;

    // 4. Set object.[[ISOHour]] to hour.
    // 5. Set object.[[ISOMinute]] to minute.
    // 6. Set object.[[ISOSecond]] to second.
    // 7. Set object.[[ISOMillisecond]] to millisecond.
    // 8. Set object.[[ISOMicrosecond]] to microsecond.
    // 9. Set object.[[ISONanosecond]] to nanosecond.
    let obj = JsObject::from_proto_and_data(prototype, PlainTime { inner });

    // 10. Return object.
    Ok(obj)
}

/// 4.5.3 `ToTemporalTime ( item [ , overflow ] )`
pub(crate) fn to_temporal_time(
    value: &JsValue,
    options: Option<&JsValue>,
    context: &mut Context,
) -> JsResult<PlainTimeInner> {
    // 1.If overflow is not present, set overflow to "constrain".
    let binding = JsValue::undefined();
    let options = options.unwrap_or(&binding);
    // 2. If item is an Object, then
    match value.variant() {
        JsVariant::Object(object) => {
            // a. If item has an [[InitializedTemporalTime]] internal slot, then
            if let Some(time) = object.downcast_ref::<PlainTime>() {
                // i. Return item.
                let options = get_options_object(options)?;
                let _overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;
                return Ok(time.inner);
            // b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then
            } else if let Some(zdt) = object.downcast_ref::<ZonedDateTime>() {
                // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
                // ii. Let timeZoneRec be ? CreateTimeZoneMethodsRecord(item.[[TimeZone]], « get-offset-nanoseconds-for »).
                // iii. Let plainDateTime be ? GetPlainDateTimeFor(timeZoneRec, instant, item.[[Calendar]]).
                // iv. Return ! CreateTemporalTime(plainDateTime.[[ISOHour]], plainDateTime.[[ISOMinute]],
                // plainDateTime.[[ISOSecond]], plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]],
                // plainDateTime.[[ISONanosecond]]).
                let options = get_options_object(options)?;
                let _overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;
                return Ok(zdt.inner.to_plain_time());
            // c. If item has an [[InitializedTemporalDateTime]] internal slot, then
            } else if let Some(dt) = object.downcast_ref::<PlainDateTime>() {
                // i. Return ! CreateTemporalTime(item.[[ISOHour]], item.[[ISOMinute]],
                // item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]],
                // item.[[ISONanosecond]]).
                let options = get_options_object(options)?;
                let _overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;
                return Ok(PlainTimeInner::from(dt.inner.clone()));
            }
            // d. Let result be ? ToTemporalTimeRecord(item).
            // e. Set result to ? RegulateTime(result.[[Hour]], result.[[Minute]],
            // result.[[Second]], result.[[Millisecond]], result.[[Microsecond]],
            // result.[[Nanosecond]], overflow).
            let partial = to_partial_time_record(&object, context)?;

            let options = get_options_object(options)?;
            let overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;

            PlainTimeInner::from_partial(partial, overflow).map_err(Into::into)
        }
        // 3. Else,
        JsVariant::String(str) => {
            // b. Let result be ? ParseTemporalTimeString(item).
            // c. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
            let result = str.to_std_string_escaped().parse::<PlainTimeInner>()?;

            let options = get_options_object(options)?;
            let _overflow = get_option::<Overflow>(&options, js_string!("overflow"), context)?;

            Ok(result)
        }
        // a. If item is not a String, throw a TypeError exception.
        _ => Err(JsNativeError::typ()
            .with_message("Invalid value for converting to PlainTime.")
            .into()),
    }

    // 4. Return ! CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
}

pub(crate) fn to_partial_time_record(
    partial_object: &JsObject,
    context: &mut Context,
) -> JsResult<PartialTime> {
    let hour = partial_object
        .get(js_string!("hour"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
        })
        .transpose()?;

    let microsecond = partial_object
        .get(js_string!("microsecond"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
        })
        .transpose()?;

    let millisecond = partial_object
        .get(js_string!("millisecond"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
        })
        .transpose()?;

    let minute = partial_object
        .get(js_string!("minute"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
        })
        .transpose()?;

    let nanosecond = partial_object
        .get(js_string!("nanosecond"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
        })
        .transpose()?;

    let second = partial_object
        .get(js_string!("second"), context)?
        .map(|v| {
            let finite = v.to_finitef64(context)?;
            Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
        })
        .transpose()?;

    Ok(PartialTime {
        hour,
        minute,
        second,
        millisecond,
        microsecond,
        nanosecond,
    })
}