← All issues

[JSC][Temporal] Implement Temporal.ZonedDateTime

27ac373

// JSTests/stress/temporal-boundary-values.js
{
    const maxNs = 8640000000000000000000n;
    const zdt = new Temporal.ZonedDateTime(maxNs, "UTC");
    shouldBe(zdt.epochNanoseconds, maxNs, "max epoch ns");
}
shouldThrow(() => new Temporal.ZonedDateTime(8640000000000000000001n, "UTC"));
shouldThrow(() => new Temporal.ZonedDateTime(-8640000000000000000001n, "UTC"));

// intl-canonical-iana-time-zone.js — FIXMEs removed:
for (const [legacy, primary] of pairs) {
    shouldBeTrue(new Temporal.ZonedDateTime(0n, legacy).equals(new Temporal.ZonedDateTime(0n, primary)));
}

Temporal is TC39's date/time replacement for the legacy Date object; ZonedDateTime is its most complex type, storing an absolute instant as a BigInt epoch-nanosecond value (range ±8.64×10²¹ ns) paired with a named IANA time zone and an optional non-ISO calendar. JSC integrates ICU for non-Gregorian calendars like Japanese (which carries era/eraYear semantics on top of year) and uses dedicated time-zone infrastructure for DST gap/fold disambiguation.

This commit implements the constructor, prototype with all getters and methods, Temporal.Now.zonedDateTimeISO, and Duration.round/total/compare with ZonedDateTime as relativeTo. Bundled correctness fixes are revealing: several static_cast<int32_t>(double) conversions become clampTo<int32_t> (a double outside [INT32_MIN, INT32_MAX] cast to int32_t is C++ UB and on optimizing compilers can produce adversary-influenced bit patterns), a JSC heap object owning a String member is migrated from cellHeapCellType to destructibleCellHeapCellType (fixing a StringImpl leak from a silently-skipped destructor), and DurationArithmetic::computeNudgeWindow corrects a wrong spec shortcut that checked r1 == 0 instead of DateDurationSign(startDuration) == 0.

The bundled UB fixes and a pre-existing GC destructor omission are signals that the prior Temporal codebase had latent defects; where several instances were found, more likely remain. The commit introduces the most complex type in the TC39 Temporal proposal — BigInt epoch arithmetic, DST-aware time zone resolution, and ICU calendar integration — creating substantial new attack surface in JSC reachable from any page.

🔒

New BigInt epoch coercion, DST fold arithmetic, ICU calendar field paths, and GC destructor patterns all contain edge cases worth security investigation.

Subscribe to read more