Skip to content

[JSC] Expose TemporalZonedDateTime::toString and a temporalType(JSValue) classifier - #393

Merged
dylan-conway merged 1 commit into
mainfrom
claude/temporal-tostring-classifier
Aug 7, 2026
Merged

[JSC] Expose TemporalZonedDateTime::toString and a temporalType(JSValue) classifier#393
dylan-conway merged 1 commit into
mainfrom
claude/temporal-tostring-classifier

Conversation

@dylan-conway

Copy link
Copy Markdown
Member

Two small additions so embedders can format and classify Temporal values without copying engine internals.

TemporalZonedDateTime::toStringTemporalZonedDateTimeToString was file-static in TemporalZonedDateTimePrototype.cpp, which made ZonedDateTime the only Temporal class without a toString() reachable from outside the prototype. It is now a member:

String toString(JSGlobalObject*, const PrecisionData&, RoundingMode, StringView showOffset, StringView showTimeZone, StringView showCalendar) const;
String toString(JSGlobalObject*) const; // every option ~auto~

toString/toJSON on the prototype call the member; the body is moved verbatim (only zdt->x() → member access and the redundant calendarID parameter dropped, since every caller passed zdt->calendarID()).

JSC::TemporalType / temporalType(JSValue) in TemporalObject.h — a uint8_t enum over the eight classes (None, Instant, PlainDateTime, PlainDate, PlainTime, ZonedDateTime, PlainYearMonth, PlainMonthDay, Duration) and a classifier that short-circuits on non-ObjectType cells then does the inherits<> chain once. Discriminants are explicit because Bun mirrors them across its FFI boundary.

No behavior change for JS. Consumer: oven-sh/bun#37043 (Temporal formatting in console.log / util.inspect / test snapshots), which currently replicates the ZonedDateTime recipe and the classifier on the Bun side.

…ue) classifier

TemporalZonedDateTimeToString was file-static in the prototype file, so
ZonedDateTime was the only Temporal class without a toString() an
embedder could call; move it onto TemporalZonedDateTime as
toString(globalObject, precision, roundingMode, showOffset, showTimeZone,
showCalendar) plus an all-~auto~ toString(globalObject) overload, and
have toString/toJSON call the member.

Add JSC::TemporalType and temporalType(JSValue) in TemporalObject.h so
callers that need to discriminate the eight Temporal classes share one
classifier instead of each writing an inherits<> chain.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 209d3c90-db55-44cf-96de-dfdc125fabc9

📥 Commits

Reviewing files that changed from the base of the PR and between 171babe and 19c8f3b.

📒 Files selected for processing (5)
  • Source/JavaScriptCore/runtime/TemporalObject.cpp
  • Source/JavaScriptCore/runtime/TemporalObject.h
  • Source/JavaScriptCore/runtime/TemporalZonedDateTime.cpp
  • Source/JavaScriptCore/runtime/TemporalZonedDateTime.h
  • Source/JavaScriptCore/runtime/TemporalZonedDateTimePrototype.cpp

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical refactor plus a new embedder-only classifier, no JS-observable change.

Verified the toString body is a verbatim move from the file-static in TemporalZonedDateTimePrototype.cpp (only zdt->x() → member/m_* access; the dropped calendarID param was always zdt->calendarID() at both call sites).
Confirmed the one-arg toString overload's defaults match what toJSON previously passed inline.
Checked that all eight Temporal classes use ObjectType structures, so the type() != ObjectType short-circuit in temporalType() is sound.
Checked the new TemporalObject.h include in TemporalZonedDateTime.h — no header cycle; PrecisionData/RoundingMode resolve from existing includes.

Extended reasoning...

Overview

Two additions for embedder (Bun) consumption:

  1. TemporalZonedDateTime::toString — the file-static temporalZonedDateTimeToString in TemporalZonedDateTimePrototype.cpp is relocated to a public member on TemporalZonedDateTime. The function body is moved verbatim; the only edits are zdt->exactTime()m_exactTime, zdt->timeZone()m_timeZone, zdt->timeZoneId()/calendarId() → member calls, and the calendarID parameter is dropped in favor of m_calendarID (both callers passed zdt->calendarID(), so this is behavior-preserving). A convenience one-arg overload supplies the same all-~auto~ defaults that toJSON used inline. toString/toJSON on the prototype now delegate to the member.
  2. TemporalType enum + temporalType(JSValue) — a new JS_EXPORT_PRIVATE classifier that short-circuits on non-ObjectType cells and then walks an inherits<> chain over the eight Temporal classes. Not wired into any existing JS path; purely additive for FFI consumers.

Supporting changes: two new includes in TemporalObject.cpp (TemporalDuration.h, TemporalInstant.h) for the classifier, and TemporalZonedDateTime.h now includes TemporalObject.h (for PrecisionData) plus Rounding.h/StringBuilder.h in the .cpp.

Security risks

None. No parsing, no untrusted input handling, no allocation-pattern change, no auth/permissions surface. The classifier reads only the JSCell type/classInfo chain; the toString body is byte-for-byte the pre-existing spec algorithm.

Level of scrutiny

Low. This is a code-motion refactor plus an additive, unreferenced-in-JSC helper. The prototype's toString/toJSON are already covered by test262 Temporal tests, so a regression in the move would surface there. I diffed the removed and added function bodies line-by-line and found no semantic drift.

Other factors

  • Confirmed via grep that every Temporal instance class (TemporalInstant, TemporalPlainDate, TemporalPlainDateTime, TemporalPlainTime, TemporalPlainYearMonth, TemporalPlainMonthDay, TemporalZonedDateTime, TemporalDuration) creates its structure with TypeInfo(ObjectType, ...), so the fast-reject on type() != ObjectType in temporalType() cannot produce a false negative.
  • Verified no circular header include is introduced: TemporalObject.h does not include TemporalZonedDateTime.h.
  • RoundingMode (from TemporalEnums.h) and PrecisionData (from TemporalObject.h) are both reachable from the updated TemporalZonedDateTime.h.
  • No outstanding reviewer comments; the only timeline entry is a coderabbit rate-limit notice.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Preview Builds

Commit Release Date
19c8f3b4 autobuild-preview-pr-393-19c8f3b4 2026-08-07 23:31:43 UTC

@dylan-conway
dylan-conway merged commit 78d45d3 into main Aug 7, 2026
43 checks passed
dylan-conway added a commit to oven-sh/bun that referenced this pull request Aug 8, 2026
…String

Bump WebKit to 78d45d318434 (oven-sh/WebKit#393), which exposes
TemporalZonedDateTime::toString(JSGlobalObject*) and a
JSC::TemporalType / temporalType(JSValue) classifier. Drop Bun's copies:
the ZonedDateTime toString recipe, Bun::TemporalType, and
Bun::temporalObjectType. cppbind maps JSC::TemporalType to
bun_jsc::TemporalType.

Also picks up oven-sh/WebKit#391 (module loader: propagate
TerminationException from resolve()).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant