@@ -8,7 +8,10 @@ pub mod instant;
88pub mod options;
99pub mod plain_time;
1010
11- use temporal_rs:: options:: { DifferenceSettings , RoundingIncrement , RoundingMode , Unit , UnitGroup } ;
11+ use temporal_rs:: {
12+ options:: { DifferenceSettings , RoundingIncrement , RoundingMode , Unit , UnitGroup } ,
13+ parsers:: Precision ,
14+ } ;
1215
1316use crate :: {
1417 ecmascript:: {
@@ -41,7 +44,7 @@ impl Temporal {
4144 let plain_time_constructor = intrinsics. temporal_plain_time ( ) ;
4245
4346 OrdinaryObjectBuilder :: new_intrinsic_object ( agent, realm, this)
44- . with_property_capacity ( 3 )
47+ . with_property_capacity ( 4 )
4548 . with_prototype ( object_prototype)
4649 // 1.2.1 Temporal.Instant ( . . . )
4750 . with_property ( |builder| {
@@ -93,6 +96,7 @@ trivially_bindable!(UnitGroup);
9396trivially_bindable ! ( Unit ) ;
9497trivially_bindable ! ( RoundingMode ) ;
9598trivially_bindable ! ( RoundingIncrement ) ;
99+ trivially_bindable ! ( Precision ) ;
96100
97101/// [13.15 GetTemporalFractionalSecondDigitsOption ( options )](https://tc39.es/proposal-temporal/#sec-temporal-gettemporalfractionalseconddigitsoption)
98102/// The abstract operation GetTemporalFractionalSecondDigitsOption takes argument
@@ -104,10 +108,10 @@ pub(crate) fn get_temporal_fractional_second_digits_option<'gc>(
104108 agent : & mut Agent ,
105109 options : Object < ' gc > ,
106110 mut gc : GcScope < ' gc , ' _ > ,
107- ) -> JsResult < ' gc , Value < ' gc > > {
111+ ) -> JsResult < ' gc , temporal_rs :: parsers :: Precision > {
108112 let options = options. bind ( gc. nogc ( ) ) ;
109113 // 1. Let digitsValue be ? Get(options, "fractionalSecondDigits").
110- let digits_value = get (
114+ let mut digits_value = get (
111115 agent,
112116 options. unbind ( ) ,
113117 BUILTIN_STRING_MEMORY
@@ -118,26 +122,35 @@ pub(crate) fn get_temporal_fractional_second_digits_option<'gc>(
118122 . unbind ( ) ?
119123 . bind ( gc. nogc ( ) ) ;
120124 // 2. If digitsValue is undefined, return auto.
121- if digits_value. unbind ( ) . is_undefined ( ) . bind ( gc. nogc ( ) ) {
122- return Ok ( BUILTIN_STRING_MEMORY . auto . into_value ( ) ) ;
125+ if digits_value. is_undefined ( ) {
126+ return Ok ( temporal_rs:: parsers:: Precision :: Auto ) ;
127+ }
128+ if let Value :: Integer ( digits_value) = digits_value
129+ && ( 0 ..=9 ) . contains ( & digits_value. into_i64 ( ) )
130+ {
131+ return Ok ( temporal_rs:: parsers:: Precision :: Digit (
132+ digits_value. into_i64 ( ) as u8 ,
133+ ) ) ;
123134 }
124- let digits_value = digits_value. unbind ( ) ;
125135 // 3. If digitsValue is not a Number, then
126136 if !digits_value. is_number ( ) {
137+ let scoped_digits_value = digits_value. scope ( agent, gc. nogc ( ) ) ;
127138 // a. If ? ToString(digitsValue) is not "auto", throw a RangeError exception.
128139 if digits_value
140+ . unbind ( )
129141 . to_string ( agent, gc. reborrow ( ) )
130142 . unbind ( ) ?
131143 . as_bytes ( agent)
132144 != b"auto"
133145 {
134146 // b. Return auto.
135- return Ok ( BUILTIN_STRING_MEMORY . auto . into_value ( ) ) ;
147+ return Ok ( temporal_rs :: parsers :: Precision :: Auto ) ;
136148 }
149+ // SAFETY: not shared.
150+ digits_value = unsafe { scoped_digits_value. take ( agent) } . bind ( gc. nogc ( ) ) ;
137151 }
138- let digits_value = digits_value. bind ( gc. nogc ( ) ) ;
139152 // 4. If digitsValue is NaN, +∞𝔽, or -∞𝔽, throw a RangeError exception.
140- if digits_value. unbind ( ) . is_nan ( agent)
153+ if digits_value. is_nan ( agent)
141154 || digits_value. is_pos_infinity ( agent)
142155 || digits_value. is_neg_infinity ( agent)
143156 {
@@ -153,17 +166,17 @@ pub(crate) fn get_temporal_fractional_second_digits_option<'gc>(
153166 . to_number ( agent, gc. reborrow ( ) )
154167 . unbind ( ) ?
155168 . bind ( gc. nogc ( ) ) ;
156- let digit_count = digit_count. into_f64 ( agent) . floor ( ) as i32 ;
169+ let digit_count = digit_count. into_f64 ( agent) . floor ( ) ;
157170 // 6. If digitCount < 0 or digitCount > 9, throw a RangeError exception.
158- if digit_count < 0 || digit_count > 9 {
171+ if digit_count < 0.0 || digit_count > 9.0 {
159172 return Err ( agent. throw_exception_with_static_message (
160173 ExceptionType :: RangeError ,
161174 "fractionalSecondDigits must be between 0 and 9" ,
162175 gc. into_nogc ( ) ,
163176 ) ) ;
164177 }
165178 // 7. Return digitCount.
166- Ok ( Number :: from_i64 ( agent , digit_count. into ( ) , gc . into_nogc ( ) ) . into_value ( ) )
179+ Ok ( temporal_rs :: parsers :: Precision :: Digit ( digit_count as u8 ) )
167180}
168181
169182/// [13.42 GetDifferenceSettings ( operation, options, unitGroup, disallowedUnits, fallbackSmallestUnit, smallestLargestDefaultUnit )](https://tc39.es/proposal-temporal/#sec-temporal-getdifferencesettings)
0 commit comments