Skip to content

Commit 2e83baa

Browse files
committed
[JSC][Temporal] Remove one-line TemporalCore delegate wrappers
https://bugs.webkit.org/show_bug.cgi?id=316456 rdar://178853392 Reviewed by Yusuke Suzuki. Remove thin wrapper functions that did nothing but forward to TemporalCore:: or ISO8601:: functions with no added logic: - TemporalDuration::toInternalDuration and temporalDurationFromInternal were static class methods that just called the identically-named TemporalCore:: free functions. Remove both and update all callers (10 sites across TemporalDuration, TemporalCalendar, TemporalInstant, TemporalPlainDate, and TemporalPlainTime) to call TemporalCore:: directly. - The file-scope getUTCEpochNanoseconds(tuple<PlainDate, PlainTime>) in TemporalDuration.cpp unwrapped the tuple and forwarded to TemporalCore::getUTCEpochNanoseconds(PlainDate, PlainTime). Remove it and pass the two arguments directly at call sites, eliminating the combineISODateAndTimeRecord + tuple-unpack roundtrip. - monthCode, dayOfWeek, dayOfYear, weekOfYear, and yearOfWeek on TemporalPlainDate, TemporalPlainDateTime, TemporalPlainYearMonth, and TemporalPlainMonthDay were single-line ISO8601:: delegates defined in .cpp files. Move them inline into the class definitions in the headers. No behavioral changes. Canonical link: https://commits.webkit.org/314683@main
1 parent a633a8a commit 2e83baa

14 files changed

Lines changed: 32 additions & 117 deletions

Source/JavaScriptCore/runtime/TemporalCalendar.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,15 @@ ISO8601::Duration differenceTemporalPlainYearMonth(JSGlobalObject* globalObject,
603603
auto duration = ISO8601::InternalDuration::combineDateAndTimeDuration(ISO8601::Duration { dateDifference.years(), dateDifference.months(), 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, Int128(0), Int128(0) }, 0);
604604

605605
if (smallestUnit != TemporalUnit::Month || increment != 1) {
606-
auto originEpochNs = getUTCEpochNanoseconds(TemporalDuration::combineISODateAndTimeRecord(thisDate, ISO8601::PlainTime()));
607-
auto isoDateTimeOther = TemporalDuration::combineISODateAndTimeRecord(otherDate, ISO8601::PlainTime());
608-
auto destEpochNs = getUTCEpochNanoseconds(isoDateTimeOther);
606+
auto originEpochNs = TemporalCore::getUTCEpochNanoseconds(thisDate, ISO8601::PlainTime());
607+
auto destEpochNs = TemporalCore::getUTCEpochNanoseconds(otherDate, ISO8601::PlainTime());
609608
auto roundResult = TemporalCore::roundRelativeDuration(duration, originEpochNs, destEpochNs, thisDate, ISO8601::PlainTime(), largestUnit, increment, smallestUnit, roundingMode, nullptr, calendarId);
610609
if (!roundResult) [[unlikely]] {
611610
throwTemporalError(globalObject, scope, roundResult.error());
612611
return { };
613612
}
614613
}
615-
auto durResult = TemporalDuration::temporalDurationFromInternal(duration, TemporalUnit::Day);
614+
auto durResult = TemporalCore::temporalDurationFromInternal(duration, TemporalUnit::Day);
616615
if (!durResult) [[unlikely]] {
617616
throwTemporalError(globalObject, scope, durResult.error());
618617
return { };

Source/JavaScriptCore/runtime/TemporalDuration.cpp

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ JSValue TemporalDuration::compare(JSGlobalObject* globalObject, JSValue valueOne
662662
// Fast path: no ZDT addZonedDateTime needed — pure 24h-day time comparison.
663663
bool hasCalendarUnits = one->years() || two->years() || one->months() || two->months() || one->weeks() || two->weeks();
664664
if (!hasCalendarUnits) {
665-
auto timeDuration1 = add24HourDaysToTimeDuration(globalObject, toInternalDuration(one->m_duration).time(), one->days());
665+
auto timeDuration1 = add24HourDaysToTimeDuration(globalObject, TemporalCore::toInternalDuration(one->m_duration).time(), one->days());
666666
RETURN_IF_EXCEPTION(scope, { });
667-
auto timeDuration2 = add24HourDaysToTimeDuration(globalObject, toInternalDuration(two->m_duration).time(), two->days());
667+
auto timeDuration2 = add24HourDaysToTimeDuration(globalObject, TemporalCore::toInternalDuration(two->m_duration).time(), two->days());
668668
RETURN_IF_EXCEPTION(scope, { });
669669
return jsNumber(timeDuration1 > timeDuration2 ? 1 : timeDuration1 < timeDuration2 ? -1 : 0);
670670
}
@@ -681,14 +681,14 @@ JSValue TemporalDuration::compare(JSGlobalObject* globalObject, JSValue valueOne
681681
auto endDate1 = calendarAwareDateAdd(globalObject, relativeTo.calendarId, plainDate, dateDuration1, TemporalOverflow::Constrain);
682682
RETURN_IF_EXCEPTION(scope, { });
683683
auto daysDiff1 = TemporalCore::diffISODate(plainDate, endDate1, TemporalUnit::Day);
684-
auto timeDuration1 = add24HourDaysToTimeDuration(globalObject, toInternalDuration(one->m_duration).time(), daysDiff1.days());
684+
auto timeDuration1 = add24HourDaysToTimeDuration(globalObject, TemporalCore::toInternalDuration(one->m_duration).time(), daysDiff1.days());
685685
RETURN_IF_EXCEPTION(scope, { });
686686

687687
ISO8601::Duration dateDuration2(two->years(), two->months(), two->weeks(), two->days(), 0LL, 0LL, 0LL, 0LL, Int128(0), Int128(0));
688688
auto endDate2 = calendarAwareDateAdd(globalObject, relativeTo.calendarId, plainDate, dateDuration2, TemporalOverflow::Constrain);
689689
RETURN_IF_EXCEPTION(scope, { });
690690
auto daysDiff2 = TemporalCore::diffISODate(plainDate, endDate2, TemporalUnit::Day);
691-
auto timeDuration2 = add24HourDaysToTimeDuration(globalObject, toInternalDuration(two->m_duration).time(), daysDiff2.days());
691+
auto timeDuration2 = add24HourDaysToTimeDuration(globalObject, TemporalCore::toInternalDuration(two->m_duration).time(), daysDiff2.days());
692692
RETURN_IF_EXCEPTION(scope, { });
693693

694694
return jsNumber(timeDuration1 > timeDuration2 ? 1 : timeDuration1 < timeDuration2 ? -1 : 0);
@@ -805,26 +805,14 @@ ISO8601::Duration TemporalDuration::add(JSGlobalObject* globalObject, JSValue ot
805805
}
806806

807807
auto result = ISO8601::InternalDuration::combineDateAndTimeDuration(ISO8601::Duration(), timeResult);
808-
auto durResult = temporalDurationFromInternal(result, largestUnit);
808+
auto durResult = TemporalCore::temporalDurationFromInternal(result, largestUnit);
809809
if (!durResult) [[unlikely]] {
810810
throwTemporalError(globalObject, scope, durResult.error());
811811
return { };
812812
}
813813
return *durResult;
814814
}
815815

816-
// https://tc39.es/proposal-temporal/#sec-temporal-tointernaldurationrecord
817-
ISO8601::InternalDuration TemporalDuration::toInternalDuration(ISO8601::Duration d)
818-
{
819-
return TemporalCore::toInternalDuration(d);
820-
}
821-
822-
// https://tc39.es/proposal-temporal/#sec-temporal-temporaldurationfrominternal
823-
TemporalResult<ISO8601::Duration> TemporalDuration::temporalDurationFromInternal(ISO8601::InternalDuration internalDuration, TemporalUnit largestUnit)
824-
{
825-
return TemporalCore::temporalDurationFromInternal(internalDuration, largestUnit);
826-
}
827-
828816
// https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.subtract
829817
// Spec: Duration.prototype.subtract(other) — no relativeTo; throws RangeError if calendar units present.
830818
ISO8601::Duration TemporalDuration::subtract(JSGlobalObject* globalObject, JSValue otherValue) const
@@ -845,12 +833,6 @@ std::tuple<ISO8601::PlainDate, ISO8601::PlainTime> TemporalDuration::combineISOD
845833
return { isoDate, isoTime };
846834
}
847835

848-
// Local wrapper: tuple-form getUTCEpochNanoseconds delegates to TemporalCore two-arg form.
849-
// https://tc39.es/proposal-temporal/#sec-temporal-getutcepochnanoseconds
850-
Int128 getUTCEpochNanoseconds(std::tuple<ISO8601::PlainDate, ISO8601::PlainTime> isoDateTime)
851-
{
852-
return TemporalCore::getUTCEpochNanoseconds(std::get<0>(isoDateTime), std::get<1>(isoDateTime));
853-
}
854836

855837
// RoundDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, increment, unit, roundingMode [ , relativeTo ] )
856838
// https://tc39.es/proposal-temporal/#sec-temporal-roundduration
@@ -1015,7 +997,7 @@ ISO8601::Duration TemporalDuration::round(JSGlobalObject* globalObject, JSValue
1015997
RETURN_IF_EXCEPTION(scope, { });
1016998
zdtInternal = round(globalObject, zdtInternal, roundingIncrement, smallestUnit, roundingMode);
1017999
RETURN_IF_EXCEPTION(scope, { });
1018-
auto durResult = temporalDurationFromInternal(zdtInternal, largestUnit);
1000+
auto durResult = TemporalCore::temporalDurationFromInternal(zdtInternal, largestUnit);
10191001
if (!durResult) [[unlikely]] {
10201002
throwTemporalError(globalObject, scope, durResult.error());
10211003
return { };
@@ -1030,7 +1012,7 @@ ISO8601::Duration TemporalDuration::round(JSGlobalObject* globalObject, JSValue
10301012
}
10311013
// Step 27 sub-step: If TemporalUnitCategory(largestUnit) is ~date~, set largestUnit to ~hour~.
10321014
TemporalUnit effectiveLargestUnit = (largestUnit <= TemporalUnit::Day) ? TemporalUnit::Hour : largestUnit;
1033-
auto durResult = temporalDurationFromInternal(*zdtDiffResult, effectiveLargestUnit);
1015+
auto durResult = TemporalCore::temporalDurationFromInternal(*zdtDiffResult, effectiveLargestUnit);
10341016
if (!durResult) [[unlikely]] {
10351017
throwTemporalError(globalObject, scope, durResult.error());
10361018
return { };
@@ -1066,7 +1048,7 @@ ISO8601::Duration TemporalDuration::round(JSGlobalObject* globalObject, JSValue
10661048
}
10671049

10681050
// Step 28i: Return ? TemporalDurationFromInternal(internalDuration, largestUnit).
1069-
auto durResult = temporalDurationFromInternal(*diffResult, largestUnit);
1051+
auto durResult = TemporalCore::temporalDurationFromInternal(*diffResult, largestUnit);
10701052
if (!durResult) [[unlikely]] {
10711053
throwTemporalError(globalObject, scope, durResult.error());
10721054
return { };
@@ -1090,7 +1072,7 @@ ISO8601::Duration TemporalDuration::round(JSGlobalObject* globalObject, JSValue
10901072
RETURN_IF_EXCEPTION(scope, { });
10911073
auto result = round(globalObject, internalDuration, roundingIncrement, smallestUnit, roundingMode);
10921074
RETURN_IF_EXCEPTION(scope, { });
1093-
auto durResult2 = temporalDurationFromInternal(result, largestUnit);
1075+
auto durResult2 = TemporalCore::temporalDurationFromInternal(result, largestUnit);
10941076
if (!durResult2) [[unlikely]] {
10951077
throwTemporalError(globalObject, scope, durResult2.error());
10961078
return { };
@@ -1205,8 +1187,8 @@ double TemporalDuration::total(JSGlobalObject* globalObject, JSValue optionsValu
12051187
RETURN_IF_EXCEPTION(scope, 0);
12061188
ISO8601::PlainTime targetTime = TemporalCore::plainTimeFromSubdayNs(subdayNs);
12071189

1208-
Int128 originEpochNs = getUTCEpochNanoseconds(combineISODateAndTimeRecord(plainDate, midnight));
1209-
Int128 destEpochNs = getUTCEpochNanoseconds(combineISODateAndTimeRecord(targetDate, targetTime));
1190+
Int128 originEpochNs = TemporalCore::getUTCEpochNanoseconds(plainDate, midnight);
1191+
Int128 destEpochNs = TemporalCore::getUTCEpochNanoseconds(targetDate, targetTime);
12101192

12111193
// Spec: DifferencePlainDateTimeWithTotal early-return for zero duration,
12121194
// then ISODateTimeWithinLimits check on both endpoints.
@@ -1298,7 +1280,7 @@ String TemporalDuration::toString(JSGlobalObject* globalObject, JSValue optionsV
12981280
// Step 17: Let roundedDuration be ? TemporalDurationFromInternal(internalDuration, roundedLargestUnit).
12991281
// TemporalDurationFromInternal calls CreateTemporalDuration which calls IsValidDuration.
13001282
// When days+time together exceed 2^53 seconds after decomposition, IsValidDuration fails → RangeError.
1301-
auto roundedDurationResult = temporalDurationFromInternal(internalDuration, roundedLargestUnit);
1283+
auto roundedDurationResult = TemporalCore::temporalDurationFromInternal(internalDuration, roundedLargestUnit);
13021284
if (!roundedDurationResult) [[unlikely]] {
13031285
throwTemporalError(globalObject, scope, roundedDurationResult.error());
13041286
return { };

Source/JavaScriptCore/runtime/TemporalDuration.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ class TemporalDuration final : public JSNonFinalObject {
7272
String toString(JSGlobalObject*, JSValue options) const;
7373
String toString(JSGlobalObject* globalObject, std::tuple<Precision, unsigned> precision = { Precision::Auto, 0 }) const { return toString(globalObject, m_duration, precision); }
7474

75-
static ISO8601::InternalDuration toInternalDuration(ISO8601::Duration);
7675
static ISO8601::InternalDuration toInternalDurationRecordWith24HourDays(JSGlobalObject*, ISO8601::Duration);
7776
ISO8601::Duration addDurations(JSGlobalObject*, AddOrSubtract, ISO8601::Duration, TemporalUnit) const;
78-
static TemporalResult<ISO8601::Duration> temporalDurationFromInternal(ISO8601::InternalDuration, TemporalUnit);
7977

8078
static ISO8601::Duration fromDurationLike(JSGlobalObject*, JSObject*);
8179
static ISO8601::Duration toISO8601Duration(JSGlobalObject*, JSValue);
@@ -96,6 +94,4 @@ class TemporalDuration final : public JSNonFinalObject {
9694
ISO8601::Duration m_duration;
9795
};
9896

99-
Int128 getUTCEpochNanoseconds(std::tuple<ISO8601::PlainDate, ISO8601::PlainTime>);
100-
10197
} // namespace JSC

Source/JavaScriptCore/runtime/TemporalInstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ ISO8601::Duration TemporalInstant::difference(JSGlobalObject* globalObject, Temp
267267
RETURN_IF_EXCEPTION(scope, { });
268268

269269
// Step 5: Return CreateTemporalDuration from the balanced result.
270-
auto durResult = TemporalDuration::temporalDurationFromInternal(internalDuration, largestUnit);
270+
auto durResult = TemporalCore::temporalDurationFromInternal(internalDuration, largestUnit);
271271
if (!durResult) [[unlikely]] {
272272
throwTemporalError(globalObject, scope, durResult.error());
273273
return { };

Source/JavaScriptCore/runtime/TemporalPlainDate.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,7 @@ ISO8601::PlainDate TemporalPlainDate::with(JSGlobalObject* globalObject, JSObjec
695695
// https://tc39.es/proposal-temporal/#sec-getutcepochnanoseconds
696696
static Int128 getUTCEpochNanoseconds(ISO8601::PlainDate isoDate)
697697
{
698-
return getUTCEpochNanoseconds(
699-
std::tuple<ISO8601::PlainDate, ISO8601::PlainTime>(
700-
isoDate, ISO8601::PlainTime()));
698+
return TemporalCore::getUTCEpochNanoseconds(isoDate, ISO8601::PlainTime());
701699
}
702700

703701
ISO8601::Duration TemporalPlainDate::differenceTemporalPlainDate(JSGlobalObject* globalObject, DifferenceOperation op, TemporalPlainDate* other, TemporalUnit smallestUnit, TemporalUnit largestUnit, RoundingMode roundingMode, double increment)
@@ -733,7 +731,7 @@ ISO8601::Duration TemporalPlainDate::differenceTemporalPlainDate(JSGlobalObject*
733731
return { };
734732
}
735733
}
736-
auto durResult = TemporalDuration::temporalDurationFromInternal(duration, TemporalUnit::Day);
734+
auto durResult = TemporalCore::temporalDurationFromInternal(duration, TemporalUnit::Day);
737735
if (!durResult) [[unlikely]] {
738736
throwTemporalError(globalObject, scope, durResult.error());
739737
return { };
@@ -774,29 +772,4 @@ ISO8601::Duration TemporalPlainDate::since(JSGlobalObject* globalObject, Tempora
774772
DifferenceOperation::Since, other, smallestUnit, largestUnit, roundingMode, increment));
775773
}
776774

777-
String TemporalPlainDate::monthCode() const
778-
{
779-
return ISO8601::monthCode(m_plainDate.month());
780-
}
781-
782-
uint8_t TemporalPlainDate::dayOfWeek() const
783-
{
784-
return ISO8601::dayOfWeek(m_plainDate);
785-
}
786-
787-
uint16_t TemporalPlainDate::dayOfYear() const
788-
{
789-
return ISO8601::dayOfYear(m_plainDate);
790-
}
791-
792-
uint8_t TemporalPlainDate::weekOfYear() const
793-
{
794-
return ISO8601::weekOfYear(m_plainDate);
795-
}
796-
797-
int32_t TemporalPlainDate::yearOfWeek() const
798-
{
799-
return ISO8601::yearOfWeek(m_plainDate);
800-
}
801-
802775
} // namespace JSC

Source/JavaScriptCore/runtime/TemporalPlainDate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ class TemporalPlainDate final : public JSNonFinalObject {
7373

7474
ISO8601::PlainDate with(JSGlobalObject*, JSObject* temporalDateLike, JSValue options);
7575

76-
String monthCode() const;
77-
uint8_t dayOfWeek() const;
78-
uint16_t dayOfYear() const;
79-
uint8_t weekOfYear() const;
80-
int32_t yearOfWeek() const;
76+
String monthCode() const { return ISO8601::monthCode(m_plainDate.month()); }
77+
uint8_t dayOfWeek() const { return ISO8601::dayOfWeek(m_plainDate); }
78+
uint16_t dayOfYear() const { return ISO8601::dayOfYear(m_plainDate); }
79+
uint8_t weekOfYear() const { return ISO8601::weekOfYear(m_plainDate); }
80+
int32_t yearOfWeek() const { return ISO8601::yearOfWeek(m_plainDate); }
8181

8282
String toString(JSGlobalObject*, JSValue options) const;
8383
String toString() const;

Source/JavaScriptCore/runtime/TemporalPlainDateTime.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -574,31 +574,6 @@ String TemporalPlainDateTime::toString(JSGlobalObject* globalObject, JSValue opt
574574
return base;
575575
}
576576

577-
String TemporalPlainDateTime::monthCode() const
578-
{
579-
return ISO8601::monthCode(m_plainDate.month());
580-
}
581-
582-
uint8_t TemporalPlainDateTime::dayOfWeek() const
583-
{
584-
return ISO8601::dayOfWeek(m_plainDate);
585-
}
586-
587-
uint16_t TemporalPlainDateTime::dayOfYear() const
588-
{
589-
return ISO8601::dayOfYear(m_plainDate);
590-
}
591-
592-
uint8_t TemporalPlainDateTime::weekOfYear() const
593-
{
594-
return ISO8601::weekOfYear(m_plainDate);
595-
}
596-
597-
int32_t TemporalPlainDateTime::yearOfWeek() const
598-
{
599-
return ISO8601::yearOfWeek(m_plainDate);
600-
}
601-
602577
// https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaindatetime
603578
ISO8601::Duration TemporalPlainDateTime::differenceTemporalPlainDateTime(
604579
JSGlobalObject* globalObject, DifferenceOperation op,

Source/JavaScriptCore/runtime/TemporalPlainDateTime.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class TemporalPlainDateTime final : public JSNonFinalObject {
7171
TemporalPlainDateTime* with(JSGlobalObject*, JSObject* temporalDateLike, JSValue options);
7272
TemporalPlainDateTime* round(JSGlobalObject*, JSValue options);
7373

74-
String monthCode() const;
75-
uint8_t dayOfWeek() const;
76-
uint16_t dayOfYear() const;
77-
uint8_t weekOfYear() const;
78-
int32_t yearOfWeek() const;
74+
String monthCode() const { return ISO8601::monthCode(m_plainDate.month()); }
75+
uint8_t dayOfWeek() const { return ISO8601::dayOfWeek(m_plainDate); }
76+
uint16_t dayOfYear() const { return ISO8601::dayOfYear(m_plainDate); }
77+
uint8_t weekOfYear() const { return ISO8601::weekOfYear(m_plainDate); }
78+
int32_t yearOfWeek() const { return ISO8601::yearOfWeek(m_plainDate); }
7979

8080
ISO8601::Duration differenceTemporalPlainDateTime(JSGlobalObject*, DifferenceOperation, TemporalPlainDateTime*, TemporalUnit, TemporalUnit, RoundingMode, double);
8181

Source/JavaScriptCore/runtime/TemporalPlainMonthDay.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,4 @@ ISO8601::PlainDate TemporalPlainMonthDay::with(JSGlobalObject* globalObject, JSO
359359
return resolved->isoDate;
360360
}
361361

362-
String TemporalPlainMonthDay::monthCode() const
363-
{
364-
return ISO8601::monthCode(m_plainMonthDay.month());
365-
}
366-
367362
} // namespace JSC

Source/JavaScriptCore/runtime/TemporalPlainMonthDay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TemporalPlainMonthDay final : public JSNonFinalObject {
6161

6262
ISO8601::PlainDate with(JSGlobalObject*, JSObject*, JSValue);
6363

64-
String monthCode() const;
64+
String monthCode() const { return ISO8601::monthCode(m_plainMonthDay.month()); }
6565

6666
String toString(JSGlobalObject*, JSValue options) const;
6767
String toString() const

0 commit comments

Comments
 (0)