Assertion failure: ISODateTimeWithinLimits(endDateTime), at js/src/builtin/temporal/Duration.cpp:2730
Categories
(Core :: JavaScript: Standard Library, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox152 | --- | fixed |
People
(Reporter: jandem, Assigned: anba)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
48 bytes,
text/x-phabricator-request
|
Details |
Summary
BubbleRelativeDuration in Duration.cpp contains a MOZ_ASSERT(ISODateTimeWithinLimits(endDateTime)) that fires when PlainDate.until() (or PlainDateTime.until() at midnight) operates on dates near the minimum ISO date {-271821, 4, 19} with certain rounding options.
Root cause
The non-timezone path constructs isoDateTime with a midnight time component:
auto isoDateTime = ISODateTime{temporalDate.date(), {}};
ISODate::min() = {-271821, 4, 19} passes ISODateWithinLimits, but ISODateTime{ISODate::min(), midnight} fails ISODateTimeWithinLimits — at the minimum date, the time must be past midnight.
Inside the bubbling loop (step 6.b), CalendarDateAdd is called with a candidate endDuration. If it returns exactly ISODate::min(), the resulting endDateTime inherits the midnight time and fails the assertion:
// Duration.cpp:2729–2730
auto endDateTime = ISODateTime{end, isoDateTime.time};
MOZ_ASSERT(ISODateTimeWithinLimits(endDateTime)); // ← fires
The correct check here is ISODateWithinLimits(endDateTime.date), which is what the equivalent assertion in NudgeToCalendarUnit (lines 2203, 2229) already uses.
Test case
let d1 = new Temporal.PlainDate(-271821, 5, 19);
let d2 = new Temporal.PlainDate(-271821, 5, 18);
d1.until(d2, {
largestUnit: "year",
smallestUnit: "day",
roundingIncrement: 2,
roundingMode: "expand",
});
Shell output
Assertion failure: ISODateTimeWithinLimits(endDateTime), at js/src/builtin/temporal/Duration.cpp:2730
#0 BubbleRelativeDuration — Duration.cpp:2730
#1 RoundRelativeDuration — Duration.cpp:2828
#2 DifferenceTemporalPlainDate — PlainDate.cpp:654
#3 PlainDate_until — PlainDate.cpp:1457
Suggested fix
--- a/js/src/builtin/temporal/Duration.cpp
+++ b/js/src/builtin/temporal/Duration.cpp
@@ -2728,7 +2728,8 @@ static bool BubbleRelativeDuration(...)
// Steps 6.b.v.
auto endDateTime = ISODateTime{end, isoDateTime.time};
- MOZ_ASSERT(ISODateTimeWithinLimits(endDateTime));
+ MOZ_ASSERT(IsValidISODateTime(endDateTime));
+ MOZ_ASSERT(ISODateWithinLimits(endDateTime.date));
Comment 1•16 days ago
|
||
Thanks for CCing me.
I've looked at this in regards to the spec and there doesn't seem to be any spec bug. I think the assertion here should just be removed; there's no corresponding assertion in the spec text. The section on "ISO Date-Time Records" says "For any ISO Date-Time Record r, [...] It is not necessary for ISODateTimeWithinLimits(r) to return true."
Updated•13 days ago
|
| Assignee | ||
Comment 2•13 days ago
|
||
Updated•13 days ago
|
Comment 4•12 days ago
|
||
| bugherder | ||
Comment 5•11 days ago
|
||
Description
•