소스 검색

LibJS: Move string-parsing code into ToTemporalDurationRecord

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/a68b97b
Linus Groh 3 년 전
부모
커밋
0d06f3655f

+ 30 - 46
Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

@@ -113,56 +113,53 @@ ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject&
 // 7.5.8 ToTemporalDuration ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
 // 7.5.8 ToTemporalDuration ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
 ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject& global_object, Value item)
 ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject& global_object, Value item)
 {
 {
-    DurationRecord result;
-
-    // 1. If Type(item) is Object, then
-    if (item.is_object()) {
-        // a. If item has an [[InitializedTemporalDuration]] internal slot, then
-        if (is<Duration>(item.as_object())) {
-            // i. Return item.
-            return &static_cast<Duration&>(item.as_object());
-        }
-        // b. Let result be ? ToTemporalDurationRecord(item).
-        result = TRY(to_temporal_duration_record(global_object, item.as_object()));
+    // 1. If Type(item) is Object and item has an [[InitializedTemporalDuration]] internal slot, then
+    if (item.is_object() && is<Duration>(item.as_object())) {
+        // a. Return item.
+        return &static_cast<Duration&>(item.as_object());
     }
     }
-    // 2. Else,
-    else {
-        // a. Let string be ? ToString(item).
-        auto string = TRY(item.to_string(global_object));
 
 
-        // b. Let result be ? ParseTemporalDurationString(string).
-        result = TRY(parse_temporal_duration_string(global_object, string));
-    }
+    // 2. Let result be ? ToTemporalDurationRecord(item).
+    auto result = TRY(to_temporal_duration_record(global_object, item));
 
 
     // 3. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
     // 3. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
     return MUST(create_temporal_duration(global_object, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
     return MUST(create_temporal_duration(global_object, result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
 }
 }
 
 
 // 7.5.9 ToTemporalDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
 // 7.5.9 ToTemporalDurationRecord ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
-ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& global_object, Object const& temporal_duration_like)
+ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& global_object, Value temporal_duration_like)
 {
 {
     auto& vm = global_object.vm();
     auto& vm = global_object.vm();
 
 
-    // 1. If temporalDurationLike has an [[InitializedTemporalDuration]] internal slot, then
-    if (is<Duration>(temporal_duration_like)) {
-        auto& duration = static_cast<Duration const&>(temporal_duration_like);
+    // 1. If Type(temporalDurationLike) is not Object, then
+    if (!temporal_duration_like.is_object()) {
+        // a. Let string be ? ToString(temporalDurationLike).
+        auto string = TRY(temporal_duration_like.to_string(global_object));
+
+        // b. Return ? ParseTemporalDurationString(string).
+        return parse_temporal_duration_string(global_object, string);
+    }
+
+    // 2. If temporalDurationLike has an [[InitializedTemporalDuration]] internal slot, then
+    if (is<Duration>(temporal_duration_like.as_object())) {
+        auto& duration = static_cast<Duration const&>(temporal_duration_like.as_object());
 
 
         // a. Return ! CreateDurationRecord(temporalDurationLike.[[Years]], temporalDurationLike.[[Months]], temporalDurationLike.[[Weeks]], temporalDurationLike.[[Days]], temporalDurationLike.[[Hours]], temporalDurationLike.[[Minutes]], temporalDurationLike.[[Seconds]], temporalDurationLike.[[Milliseconds]], temporalDurationLike.[[Microseconds]], temporalDurationLike.[[Nanoseconds]]).
         // a. Return ! CreateDurationRecord(temporalDurationLike.[[Years]], temporalDurationLike.[[Months]], temporalDurationLike.[[Weeks]], temporalDurationLike.[[Days]], temporalDurationLike.[[Hours]], temporalDurationLike.[[Minutes]], temporalDurationLike.[[Seconds]], temporalDurationLike.[[Milliseconds]], temporalDurationLike.[[Microseconds]], temporalDurationLike.[[Nanoseconds]]).
         return create_duration_record(duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds());
         return create_duration_record(duration.years(), duration.months(), duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.milliseconds(), duration.microseconds(), duration.nanoseconds());
     }
     }
 
 
-    // 2. Let result be a new Duration Record.
+    // 3. Let result be a new Duration Record.
     auto result = DurationRecord {};
     auto result = DurationRecord {};
 
 
-    // 3. Let any be false.
+    // 4. Let any be false.
     auto any = false;
     auto any = false;
 
 
-    // 4. For each row of Table 7, except the header row, in table order, do
+    // 5. For each row of Table 7, except the header row, in table order, do
     for (auto& [field, property] : temporal_duration_like_properties<DurationRecord, double>(vm)) {
     for (auto& [field, property] : temporal_duration_like_properties<DurationRecord, double>(vm)) {
         // a. Let prop be the Property Name value of the current row.
         // a. Let prop be the Property Name value of the current row.
 
 
         // b. Let val be ? Get(temporalDurationLike, prop).
         // b. Let val be ? Get(temporalDurationLike, prop).
-        auto value = TRY(temporal_duration_like.get(property));
+        auto value = TRY(temporal_duration_like.as_object().get(property));
 
 
         // c. If val is undefined, then
         // c. If val is undefined, then
         if (value.is_undefined()) {
         if (value.is_undefined()) {
@@ -182,19 +179,19 @@ ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject& glob
         }
         }
     }
     }
 
 
-    // 5. If any is false, then
+    // 6. If any is false, then
     if (!any) {
     if (!any) {
         // a. Throw a TypeError exception.
         // a. Throw a TypeError exception.
         return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalInvalidDurationLikeObject);
         return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalInvalidDurationLikeObject);
     }
     }
 
 
-    // 6. If ! IsValidDuration(result.[[Years]], result.[[Months]], result.[[Weeks]] result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]) is false, then
+    // 7. If ! IsValidDuration(result.[[Years]], result.[[Months]], result.[[Weeks]] result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]) is false, then
     if (!is_valid_duration(result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds)) {
     if (!is_valid_duration(result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds)) {
         // a. Throw a RangeError exception.
         // a. Throw a RangeError exception.
         return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDuration);
         return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDuration);
     }
     }
 
 
-    // 7. Return result.
+    // 8. Return result.
     return result;
     return result;
 }
 }
 
 
@@ -1608,23 +1605,10 @@ ThrowCompletionOr<DurationRecord> to_limited_temporal_duration(GlobalObject& glo
 {
 {
     auto& vm = global_object.vm();
     auto& vm = global_object.vm();
 
 
-    DurationRecord duration;
-
-    // 1. If Type(temporalDurationLike) is not Object, then
-    if (!temporal_duration_like.is_object()) {
-        // a. Let str be ? ToString(temporalDurationLike).
-        auto str = TRY(temporal_duration_like.to_string(global_object));
-
-        // b. Let duration be ? ParseTemporalDurationString(str).
-        duration = TRY(parse_temporal_duration_string(global_object, str));
-    }
-    // 2. Else,
-    else {
-        // a. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
-        duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like.as_object()));
-    }
+    // 1. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
 
 
-    // 3. For each row of Table 7, except the header row, in table order, do
+    // 2. For each row of Table 7, except the header row, in table order, do
     for (auto& [field, property] : temporal_duration_like_properties<DurationRecord, double>(vm)) {
     for (auto& [field, property] : temporal_duration_like_properties<DurationRecord, double>(vm)) {
         // a. Let prop be the Property Name value of the current row.
         // a. Let prop be the Property Name value of the current row.
 
 
@@ -1638,7 +1622,7 @@ ThrowCompletionOr<DurationRecord> to_limited_temporal_duration(GlobalObject& glo
         }
         }
     }
     }
 
 
-    // 4. Return duration.
+    // 3. Return duration.
     return duration;
     return duration;
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/Duration.h

@@ -140,7 +140,7 @@ ThrowCompletionOr<DateDurationRecord> create_date_duration_record(GlobalObject&,
 TimeDurationRecord create_time_duration_record(double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 TimeDurationRecord create_time_duration_record(double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(GlobalObject&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject&, Value item);
 ThrowCompletionOr<Duration*> to_temporal_duration(GlobalObject&, Value item);
-ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject&, Object const& temporal_duration_like);
+ThrowCompletionOr<DurationRecord> to_temporal_duration_record(GlobalObject&, Value temporal_duration_like);
 i8 duration_sign(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 i8 duration_sign(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 bool is_valid_duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 bool is_valid_duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
 StringView default_temporal_largest_unit(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds);
 StringView default_temporal_largest_unit(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds);

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp

@@ -298,8 +298,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::add)
     // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
     // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
     auto* duration = TRY(typed_this_object(global_object));
     auto* duration = TRY(typed_this_object(global_object));
 
 
-    // 3. Set other to ? ToLimitedTemporalDuration(other, « »).
-    auto other = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Set other to ? ToTemporalDurationRecord(other).
+    auto other = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
@@ -321,8 +321,8 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract)
     // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
     // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
     auto* duration = TRY(typed_this_object(global_object));
     auto* duration = TRY(typed_this_object(global_object));
 
 
-    // 3. Set other to ? ToLimitedTemporalDuration(other, « »).
-    auto other = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Set other to ? ToTemporalDurationRecord(other).
+    auto other = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp

@@ -465,8 +465,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::add)
     // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
     // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
     auto* date_time = TRY(typed_this_object(global_object));
     auto* date_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
@@ -491,8 +491,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::subtract)
     // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
     // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
     auto* date_time = TRY(typed_this_object(global_object));
     auto* date_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp

@@ -145,8 +145,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::add)
     // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
     // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
     auto* temporal_time = TRY(typed_this_object(global_object));
     auto* temporal_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, temporal_duration_like, {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
 
 
     // 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
     // 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
     auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, duration.nanoseconds);
     auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, duration.nanoseconds);
@@ -167,8 +167,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::subtract)
     // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
     // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
     auto* temporal_time = TRY(typed_this_object(global_object));
     auto* temporal_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, temporal_duration_like, {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
 
 
     // 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], −duration.[[Hours]], −duration.[[Minutes]], −duration.[[Seconds]], −duration.[[Milliseconds]], −duration.[[Microseconds]], −duration.[[Nanoseconds]]).
     // 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], −duration.[[Hours]], −duration.[[Minutes]], −duration.[[Seconds]], −duration.[[Milliseconds]], −duration.[[Microseconds]], −duration.[[Nanoseconds]]).
     auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds);
     auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds);

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp

@@ -243,8 +243,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::add)
     // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
     // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
     auto* year_month = TRY(typed_this_object(global_object));
     auto* year_month = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
     // 4. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
     auto balance_result = TRY(balance_duration(global_object, duration.days, duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, *js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)duration.nanoseconds)), "day"sv));
     auto balance_result = TRY(balance_duration(global_object, duration.days, duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, *js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)duration.nanoseconds)), "day"sv));
@@ -315,8 +315,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::subtract)
     // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
     // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
     auto* year_month = TRY(typed_this_object(global_object));
     auto* year_month = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
     // 4. Let balanceResult be ? BalanceDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").
     auto balance_result = TRY(balance_duration(global_object, duration.days, duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, *js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)duration.nanoseconds)), "day"sv));
     auto balance_result = TRY(balance_duration(global_object, duration.days, duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, *js_bigint(vm, Crypto::SignedBigInteger::create_from((i64)duration.nanoseconds)), "day"sv));

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp

@@ -899,8 +899,8 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::add)
     // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
     // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
     auto* zoned_date_time = TRY(typed_this_object(global_object));
     auto* zoned_date_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
@@ -925,8 +925,8 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::subtract)
     // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
     // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
     auto* zoned_date_time = TRY(typed_this_object(global_object));
     auto* zoned_date_time = TRY(typed_this_object(global_object));
 
 
-    // 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « »).
-    auto duration = TRY(to_limited_temporal_duration(global_object, vm.argument(0), {}));
+    // 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
+    auto duration = TRY(to_temporal_duration_record(global_object, vm.argument(0)));
 
 
     // 4. Set options to ? GetOptionsObject(options).
     // 4. Set options to ? GetOptionsObject(options).
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));
     auto* options = TRY(get_options_object(global_object, vm.argument(1)));