Closed Bug 2036259 Opened 17 days ago Closed 12 days ago

Assertion failure: ISODateTimeWithinLimits(endDateTime), at js/src/builtin/temporal/Duration.cpp:2730

Categories

(Core :: JavaScript: Standard Library, defect, P3)

defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: jandem, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

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));

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."

Severity: -- → S3
Priority: -- → P3
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Pushed by andre.bargull@gmail.com: https://github.com/mozilla-firefox/firefox/commit/537336349779 https://hg.mozilla.org/integration/autoland/rev/d2d8d7dadc05 Check IsValidISODateTime instead of ISODateTimeWithinLimits in BubbleRelativeDuration. r=spidermonkey-reviewers,dminor
Status: ASSIGNED → RESOLVED
Closed: 12 days ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: