1- use std:: str:: FromStr ;
2-
31use temporal_rs:: options:: { RoundingMode , RoundingOptions , Unit } ;
42
53use crate :: {
@@ -18,7 +16,7 @@ use crate::{
1816 require_internal_slot_temporal_instant, to_temporal_instant,
1917 } ,
2018 options:: {
21- OptionType , get_option, get_options_object, get_rounding_increment_option,
19+ get_option, get_options_object, get_rounding_increment_option,
2220 get_rounding_mode_option,
2321 } ,
2422 } ,
@@ -30,7 +28,7 @@ use crate::{
3028 types:: { BUILTIN_STRING_MEMORY , BigInt , IntoValue , Object , PropertyKey , String , Value } ,
3129 } ,
3230 engine:: {
33- context:: { Bindable , GcScope , NoGcScope , trivially_bindable } ,
31+ context:: { Bindable , GcScope , NoGcScope } ,
3432 rootable:: Scopable ,
3533 } ,
3634 heap:: WellKnownSymbolIndexes ,
@@ -298,7 +296,7 @@ impl TemporalInstantPrototype {
298296 }
299297
300298 // 4. If roundTo is a String, then
301- let round_to = if let Value :: String ( round_to) = round_to . unbind ( ) {
299+ let round_to = if round_to. unbind ( ) . is_string ( ) {
302300 // a. Let paramString be roundTo.
303301 let param_string = round_to;
304302 // b. Set roundTo to OrdinaryObjectCreate(null).
@@ -319,17 +317,21 @@ impl TemporalInstantPrototype {
319317 . unbind ( ) ?
320318 . bind ( gc. nogc ( ) )
321319 } ;
320+
322321 let round_to = round_to. scope ( agent, gc. nogc ( ) ) ;
322+
323323 // 6. NOTE: The following steps read options and perform independent validation in
324324 // alphabetical order (GetRoundingIncrementOption reads "roundingIncrement" and
325325 // GetRoundingModeOption reads "roundingMode").
326326 let mut options = RoundingOptions :: default ( ) ;
327+
327328 // 7. Let roundingIncrement be ? GetRoundingIncrementOption(roundTo).
328329 let rounding_increment =
329330 get_rounding_increment_option ( agent, round_to. get ( agent) , gc. reborrow ( ) )
330331 . unbind ( ) ?
331332 . bind ( gc. nogc ( ) ) ;
332333 options. increment = Some ( rounding_increment) ;
334+
333335 // 8. Let roundingMode be ? GetRoundingModeOption(roundTo, half-expand).
334336 let rounding_mode = get_rounding_mode_option (
335337 agent,
@@ -340,17 +342,18 @@ impl TemporalInstantPrototype {
340342 . unbind ( ) ?
341343 . bind ( gc. nogc ( ) ) ;
342344 options. rounding_mode = Some ( rounding_mode) ;
345+
343346 // 9. Let smallestUnit be ? GetTemporalUnitValuedOption(roundTo, "smallestUnit", required).
344347 let smallest_unit = get_temporal_unit_valued_option (
345348 agent,
346349 round_to. get ( agent) ,
347350 BUILTIN_STRING_MEMORY . smallestUnit . into ( ) ,
348- DefaultOption :: Required ,
349351 gc. reborrow ( ) ,
350352 )
351353 . unbind ( ) ?
352354 . bind ( gc. nogc ( ) ) ;
353- options. smallest_unit = Some ( smallest_unit) ;
355+ options. smallest_unit = smallest_unit;
356+
354357 // 10. Perform ? ValidateTemporalUnitValue(smallestUnit, time).
355358 // 11. If smallestUnit is hour, then
356359 // a. Let maximum be HoursPerDay.
@@ -521,7 +524,7 @@ pub(crate) fn to_integer_with_truncation<'gc>(
521524 // 2. If number is NaN, +∞𝔽 or -∞𝔽, throw a RangeError exception.
522525 if number. is_nan ( agent) || number. is_pos_infinity ( agent) || number. is_neg_infinity ( agent) {
523526 return Err ( agent. throw_exception_with_static_message (
524- ExceptionType :: TypeError ,
527+ ExceptionType :: RangeError ,
525528 "Number cannot be NaN, positive infinity, or negative infinity" ,
526529 gc. into_nogc ( ) ,
527530 ) ) ;
@@ -541,74 +544,12 @@ pub(crate) fn get_temporal_unit_valued_option<'gc>(
541544 agent : & mut Agent ,
542545 options : Object ,
543546 key : PropertyKey ,
544- default : DefaultOption ,
545- mut gc : GcScope < ' gc , ' _ > ,
546- ) -> JsResult < ' gc , Unit > {
547+ gc : GcScope < ' gc , ' _ > ,
548+ ) -> JsResult < ' gc , Option < Unit > > {
547549 let options = options. bind ( gc. nogc ( ) ) ;
548- let default = default. bind ( gc. nogc ( ) ) ;
549550 let key = key. bind ( gc. nogc ( ) ) ;
550- // 1. Let allowedStrings be a List containing all values in the "Singular property name" and
551- // "Plural property name" columns of Table 21, except the header row.
552- const ALLOWED : & [ & str ] = & [
553- "year" ,
554- "years" ,
555- "month" ,
556- "months" ,
557- "week" ,
558- "weeks" ,
559- "day" ,
560- "days," ,
561- "hour" ,
562- "hours" ,
563- "minute" ,
564- "minutes" ,
565- "second" ,
566- "seconds" ,
567- "millisecond" ,
568- "milliseconds" ,
569- "microsecond" ,
570- "microseconds" ,
571- "nanosecond" ,
572- "nanoseconds" ,
573- "auto" ,
574- ] ;
575- // 2. Append "auto" to allowedStrings.
576- // 3. NOTE: For each singular Temporal unit name that is contained within allowedStrings, the
577- // corresponding plural name is also contained within it.
578- // 4. If default is unset, then
579- // a. Let defaultValue be undefined.
580- // 5. Else,
581- // a. Let defaultValue be default.
582- // 6. Let value be ? GetOption(options, key, string, allowedStrings, defaultValue).
583- let string_value = get_option (
584- agent,
585- options. unbind ( ) ,
586- key. unbind ( ) ,
587- OptionType :: String ,
588- ALLOWED ,
589- gc. reborrow ( ) ,
590- )
591- . unbind ( ) ?
592- . bind ( gc. nogc ( ) ) ;
593-
594- let js_str = string_value
595- . unbind ( )
596- . to_string ( agent, gc. reborrow ( ) )
597- . unbind ( ) ?
598- . bind ( gc. nogc ( ) ) ;
599551
600- let rust_str = js_str. as_str ( agent) . expect ( "aaa" ) ;
601- // 7. If value is undefined, return unset.
602- // 8. If value is "auto", return auto.
603- // 9. Return the value in the "Value" column of Table 21 corresponding to the row with value in
604- // its "Singular property name" or "Plural property name" column.
605- Ok ( Unit :: from_str ( rust_str) . unwrap ( ) )
606- }
552+ let opt = get_option :: < Unit > ( agent, options. unbind ( ) , key. unbind ( ) , gc) ?;
607553
608- #[ allow( dead_code) ]
609- pub ( crate ) enum DefaultOption {
610- Required ,
611- Unset ,
554+ Ok ( opt)
612555}
613-
614- trivially_bindable ! ( DefaultOption ) ;
0 commit comments