Skip to content

Conversation

@catamorphism
Copy link
Contributor

@catamorphism catamorphism commented Oct 6, 2025

f1cf8d2

[Temporal] Remove isoDateDifference() and use calendarDateUntil() instead
https://bugs.webkit.org/show_bug.cgi?id=298564

Reviewed by Yusuke Suzuki.

This affects the implementations of TemporalPlainDate::since() and
TemporalPlainDate::until(), and enables some of the previously-failing tests
for those methods.

Also adds roundRelativeDuration() and its auxiliary functions
(nudgeToCalendarUnit(), nudgeToDayOrTime(), bubbleRelativeDuration()),
as this is required by calendarDateUntil().

Also fixes a bug where an out-of-range year could be passed
in to the PlainDate constructor, resulting in integer overflow.

* JSTests/stress/temporal-plaindate.js:
(shouldBe):
* JSTests/test262/config.yaml:
* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/ISO8601.cpp:
(JSC::ISO8601::parseDate):
(JSC::ISO8601::weekOfYear):
(JSC::ISO8601::createISODateRecord):
* Source/JavaScriptCore/runtime/ISO8601.h:
* Source/JavaScriptCore/runtime/TemporalCalendar.cpp:
(JSC::TemporalCalendar::balanceISODate):
(JSC::TemporalCalendar::isoDateAdd):
(JSC::TemporalCalendar::balanceISOYearMonth):
(JSC::dateDuration):
(JSC::isoDateSurpasses):
(JSC::TemporalCalendar::calendarDateUntil):
(JSC::TemporalCalendar::isoDateDifference): Deleted.
* Source/JavaScriptCore/runtime/TemporalCalendar.h:
* Source/JavaScriptCore/runtime/TemporalCalendarPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalDuration.cpp:
(JSC::adjustDateDurationRecord):
(JSC::combineISODateAndTimeRecord):
(JSC::getUTCEpochNanoseconds):
(JSC::getEpochNanosecondsFor):
(JSC::nudgeToCalendarUnit):
(JSC::nudgeToDayOrTime):
(JSC::unitIndexInTable):
(JSC::unitInTable):
(JSC::bubbleRelativeDuration):
(JSC::TemporalDuration::roundRelativeDuration):
* Source/JavaScriptCore/runtime/TemporalDuration.h:
* Source/JavaScriptCore/runtime/TemporalObject.h:
* Source/JavaScriptCore/runtime/TemporalPlainDate.cpp:
(JSC::TemporalPlainDate::toPlainDate):
(JSC::getUTCEpochNanoseconds):
(JSC::TemporalPlainDate::differenceTemporalPlainDate):
(JSC::TemporalPlainDate::until):
(JSC::TemporalPlainDate::since):
* Source/JavaScriptCore/runtime/TemporalPlainDate.h:

Canonical link: https://commits.webkit.org/301096@main

f7ea52d

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@catamorphism catamorphism requested a review from a team as a code owner October 6, 2025 20:05
@catamorphism catamorphism self-assigned this Oct 6, 2025
@catamorphism catamorphism added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Oct 6, 2025
@catamorphism
Copy link
Contributor Author

Note: this PR changes the representation of ISO8601::PlainDate to use an int32_t for the year field rather than constraining the size of the year to 21 bits. This was motivated by Temporal/PlainDate/prototype/until/throws-if-rounded-date-outside-valid-iso-range.js. In the previous version of this PR, I had a workaround for this where (unlike in the spec) balanceISODate did the checking for a valid year eagerly, and returned a std::optional<ISO8601::PlainDate>. This works for that case, but when the PR was reverted, it was because calling parseDate results in dates with years outside the ECMAScript range was failing. I think parsing should be separate from validation, so that's what motivates this change. It's also closer to the spec this way.

tl;dr PlainDate has to be able to represent dates with years outside the valid ECMAScript range.

@catamorphism catamorphism added the request-merge-queue Request a pull request to be added to merge-queue once ready label Oct 6, 2025
@Constellation Constellation added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed request-merge-queue Request a pull request to be added to merge-queue once ready labels Oct 6, 2025
…tead

https://bugs.webkit.org/show_bug.cgi?id=298564

Reviewed by Yusuke Suzuki.

This affects the implementations of TemporalPlainDate::since() and
TemporalPlainDate::until(), and enables some of the previously-failing tests
for those methods.

Also adds roundRelativeDuration() and its auxiliary functions
(nudgeToCalendarUnit(), nudgeToDayOrTime(), bubbleRelativeDuration()),
as this is required by calendarDateUntil().

Also fixes a bug where an out-of-range year could be passed
in to the PlainDate constructor, resulting in integer overflow.

* JSTests/stress/temporal-plaindate.js:
(shouldBe):
* JSTests/test262/config.yaml:
* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/ISO8601.cpp:
(JSC::ISO8601::parseDate):
(JSC::ISO8601::weekOfYear):
(JSC::ISO8601::createISODateRecord):
* Source/JavaScriptCore/runtime/ISO8601.h:
* Source/JavaScriptCore/runtime/TemporalCalendar.cpp:
(JSC::TemporalCalendar::balanceISODate):
(JSC::TemporalCalendar::isoDateAdd):
(JSC::TemporalCalendar::balanceISOYearMonth):
(JSC::dateDuration):
(JSC::isoDateSurpasses):
(JSC::TemporalCalendar::calendarDateUntil):
(JSC::TemporalCalendar::isoDateDifference): Deleted.
* Source/JavaScriptCore/runtime/TemporalCalendar.h:
* Source/JavaScriptCore/runtime/TemporalCalendarPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalDuration.cpp:
(JSC::adjustDateDurationRecord):
(JSC::combineISODateAndTimeRecord):
(JSC::getUTCEpochNanoseconds):
(JSC::getEpochNanosecondsFor):
(JSC::nudgeToCalendarUnit):
(JSC::nudgeToDayOrTime):
(JSC::unitIndexInTable):
(JSC::unitInTable):
(JSC::bubbleRelativeDuration):
(JSC::TemporalDuration::roundRelativeDuration):
* Source/JavaScriptCore/runtime/TemporalDuration.h:
* Source/JavaScriptCore/runtime/TemporalObject.h:
* Source/JavaScriptCore/runtime/TemporalPlainDate.cpp:
(JSC::TemporalPlainDate::toPlainDate):
(JSC::getUTCEpochNanoseconds):
(JSC::TemporalPlainDate::differenceTemporalPlainDate):
(JSC::TemporalPlainDate::until):
(JSC::TemporalPlainDate::since):
* Source/JavaScriptCore/runtime/TemporalPlainDate.h:

Canonical link: https://commits.webkit.org/301096@main
@webkit-commit-queue webkit-commit-queue force-pushed the balance-precision-part-10 branch from f7ea52d to f1cf8d2 Compare October 6, 2025 23:01
@webkit-commit-queue
Copy link
Collaborator

Committed 301096@main (f1cf8d2): https://commits.webkit.org/301096@main

Reviewed commits have been landed. Closing PR #51889 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit f1cf8d2 into WebKit:main Oct 6, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants