@@ -331,13 +331,7 @@ impl BuiltInConstructor for Duration {
331331impl Duration {
332332 // Internal utility function for getting `Duration` field values.
333333 fn get_internal_field ( this : & JsValue , field : & DateTimeValues ) -> JsResult < JsValue > {
334- let object = this. as_object ( ) ;
335- let duration = object
336- . as_ref ( )
337- . and_then ( JsObject :: downcast_ref :: < Self > )
338- . ok_or_else ( || {
339- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
340- } ) ?;
334+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
341335
342336 let inner = & duration. inner ;
343337
@@ -522,13 +516,7 @@ impl Duration {
522516 fn get_sign ( this : & JsValue , _: & [ JsValue ] , _: & mut Context ) -> JsResult < JsValue > {
523517 // 1. Let duration be the this value.
524518 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
525- let object = this. as_object ( ) ;
526- let duration = object
527- . as_ref ( )
528- . and_then ( JsObject :: downcast_ref :: < Self > )
529- . ok_or_else ( || {
530- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
531- } ) ?;
519+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
532520
533521 // 3. Return 𝔽(! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]],
534522 // duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]],
@@ -550,13 +538,7 @@ impl Duration {
550538 fn get_blank ( this : & JsValue , _: & [ JsValue ] , _: & mut Context ) -> JsResult < JsValue > {
551539 // 1. Let duration be the this value.
552540 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
553- let object = this. as_object ( ) ;
554- let duration = object
555- . as_ref ( )
556- . and_then ( JsObject :: downcast_ref :: < Self > )
557- . ok_or_else ( || {
558- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
559- } ) ?;
541+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
560542
561543 // 3. Let sign be ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]],
562544 // duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]],
@@ -642,13 +624,7 @@ impl Duration {
642624 ) -> JsResult < JsValue > {
643625 // 1. Let duration be the this value.
644626 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
645- let object = this. as_object ( ) ;
646- let duration = object
647- . as_ref ( )
648- . and_then ( JsObject :: downcast_ref :: < Self > )
649- . ok_or_else ( || {
650- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
651- } ) ?;
627+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
652628
653629 // 3. Let temporalDurationLike be ? ToTemporalPartialDurationRecord(temporalDurationLike).
654630 let temporal_duration_like =
@@ -767,13 +743,7 @@ impl Duration {
767743 // 1. Let duration be the this value.
768744 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
769745 // 3. Return ! CreateNegatedTemporalDuration(duration).
770- let object = this. as_object ( ) ;
771- let duration = object
772- . as_ref ( )
773- . and_then ( JsObject :: downcast_ref :: < Self > )
774- . ok_or_else ( || {
775- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
776- } ) ?;
746+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
777747
778748 create_temporal_duration ( duration. inner . negated ( ) , None , context) . map ( Into :: into)
779749 }
@@ -795,13 +765,7 @@ impl Duration {
795765 // 3. Return ! CreateTemporalDuration(abs(duration.[[Years]]), abs(duration.[[Months]]),
796766 // abs(duration.[[Weeks]]), abs(duration.[[Days]]), abs(duration.[[Hours]]), abs(duration.[[Minutes]]),
797767 // abs(duration.[[Seconds]]), abs(duration.[[Milliseconds]]), abs(duration.[[Microseconds]]), abs(duration.[[Nanoseconds]])).
798- let object = this. as_object ( ) ;
799- let duration = object
800- . as_ref ( )
801- . and_then ( JsObject :: downcast_ref :: < Self > )
802- . ok_or_else ( || {
803- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
804- } ) ?;
768+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
805769
806770 create_temporal_duration ( duration. inner . abs ( ) , None , context) . map ( Into :: into)
807771 }
@@ -824,13 +788,7 @@ impl Duration {
824788 ) -> JsResult < JsValue > {
825789 // 1.Let duration be the this value.
826790 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
827- let object = this. as_object ( ) ;
828- let duration = object
829- . as_ref ( )
830- . and_then ( JsObject :: downcast_ref :: < Self > )
831- . ok_or_else ( || {
832- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
833- } ) ?;
791+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
834792
835793 // 3. Return ? AddDurations(add, duration, other).
836794 let other = to_temporal_duration_record ( args. get_or_undefined ( 0 ) , context) ?;
@@ -856,13 +814,7 @@ impl Duration {
856814 ) -> JsResult < JsValue > {
857815 // 1.Let duration be the this value.
858816 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
859- let object = this. as_object ( ) ;
860- let duration = object
861- . as_ref ( )
862- . and_then ( JsObject :: downcast_ref :: < Self > )
863- . ok_or_else ( || {
864- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
865- } ) ?;
817+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
866818
867819 let other = to_temporal_duration_record ( args. get_or_undefined ( 0 ) , context) ?;
868820
@@ -888,13 +840,7 @@ impl Duration {
888840 ) -> JsResult < JsValue > {
889841 // 1. Let duration be the this value.
890842 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
891- let object = this. as_object ( ) ;
892- let duration = object
893- . as_ref ( )
894- . and_then ( JsObject :: downcast_ref :: < Self > )
895- . ok_or_else ( || {
896- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
897- } ) ?;
843+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
898844
899845 let round_to = match args. first ( ) . map ( JsValue :: variant) {
900846 // 3. If roundTo is undefined, then
@@ -991,13 +937,7 @@ impl Duration {
991937 ) -> JsResult < JsValue > {
992938 // 1. Let duration be the this value.
993939 // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
994- let object = this. as_object ( ) ;
995- let duration = object
996- . as_ref ( )
997- . and_then ( JsObject :: downcast_ref :: < Self > )
998- . ok_or_else ( || {
999- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
1000- } ) ?;
940+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
1001941
1002942 let total_of = args. get_or_undefined ( 0 ) ;
1003943
@@ -1067,13 +1007,7 @@ impl Duration {
10671007 args : & [ JsValue ] ,
10681008 context : & mut Context ,
10691009 ) -> JsResult < JsValue > {
1070- let object = this. as_object ( ) ;
1071- let duration = object
1072- . as_ref ( )
1073- . and_then ( JsObject :: downcast_ref :: < Self > )
1074- . ok_or_else ( || {
1075- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
1076- } ) ?;
1010+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
10771011
10781012 let options = get_options_object ( args. get_or_undefined ( 0 ) ) ?;
10791013 let precision = get_digits_option ( & options, context) ?;
@@ -1100,13 +1034,7 @@ impl Duration {
11001034 /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.tojson
11011035 /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toJSON
11021036 pub ( crate ) fn to_json ( this : & JsValue , _: & [ JsValue ] , _: & mut Context ) -> JsResult < JsValue > {
1103- let object = this. as_object ( ) ;
1104- let duration = object
1105- . as_ref ( )
1106- . and_then ( JsObject :: downcast_ref :: < Self > )
1107- . ok_or_else ( || {
1108- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
1109- } ) ?;
1037+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
11101038
11111039 let result = duration
11121040 . inner
@@ -1130,13 +1058,7 @@ impl Duration {
11301058 _: & mut Context ,
11311059 ) -> JsResult < JsValue > {
11321060 // TODO: Update for ECMA-402 compliance
1133- let object = this. as_object ( ) ;
1134- let duration = object
1135- . as_ref ( )
1136- . and_then ( JsObject :: downcast_ref :: < Self > )
1137- . ok_or_else ( || {
1138- JsNativeError :: typ ( ) . with_message ( "this value must be a Duration object." )
1139- } ) ?;
1061+ this_temporal_object ! ( duration = this, Self , "Duration" ) ;
11401062
11411063 let result = duration
11421064 . inner
0 commit comments