fix(date): brand-check this on Date.prototype getters (reflective dispatch)#4397
Merged
Conversation
added 2 commits
June 4, 2026 15:09
…patch) Date.prototype getters (getDate/getDay/getFullYear/getHours/.../getUTC*, getTimezoneOffset, getTime, valueOf, legacy getYear) were installed as generic no-op thunks, so the reflective value path mis-behaved: Date.prototype.getDate.call(realDate) returned [object Object], and .call(nonDate) silently produced garbage instead of throwing. Per spec each getter runs thisTimeValue(this), which throws a TypeError when this is not an Object with a [[DateValue]] slot. Adds object/date_proto_thunks.rs (mirrors collection_/dataview_proto_thunks): each thunk reads IMPLICIT_THIS, brand-checks via is_date_value (TypeError on mismatch), and dispatches to the same js_date_get_* helper the instance fast path uses. Installed after the OBJECT_PROTO_METHODS no-op block so the generic Object valueOf does not re-clobber Date.prototype.valueOf. The instance fast path (d.getDate()) is lowered directly by codegen and is unchanged. test262 built-ins/Date: -36 (158->122 on top of the ToNumber fix; no regressions). Node-identical in both build modes.
The WebCrypto algo additions on main left jwk.rs unformatted, which fails `cargo fmt --all --check` on every PR's lint job. Pure formatting; no behavior change.
290c908 to
03aa904
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Date.prototypegetters were installed as generic no-op thunks, so the reflective value path was broken:Per spec every
Date.prototypegetter performsthisTimeValue(this), which throws aTypeErrorwhenthisis not an Object with a[[DateValue]]slot.Fix
Adds
object/date_proto_thunks.rs(mirrorscollection_proto_thunks/dataview_proto_thunks). Each getter thunk reads theIMPLICIT_THISreceiver, brand-checks it viais_date_value(throwingTypeErroron mismatch), and otherwise dispatches to the samejs_date_get_*helper the instance fast path uses — so reflective Date getter calls now both throw correctly and work correctly.Covers
getTime,valueOf,getFullYear/getMonth/getDate/getDay/getHours/getMinutes/getSeconds/getMilliseconds, allgetUTC*,getTimezoneOffset, and legacygetYear. Installed after theOBJECT_PROTO_METHODSno-op block so the generic ObjectvalueOfdoesn't re-clobberDate.prototype.valueOf.The instance fast path (
d.getDate()) is lowered directly by codegen and is unchanged.Results
test262 built-ins/Date: −36 (158 → 122 on top of the Date
ToNumberfix #4393; no regressions). Verified Node-identical in bothPERRY_NO_AUTO_OPTIMIZE=1and default builds.cargo test -p perry-runtime --lib: 979 passed.Independent of #4393 (disjoint files: this touches
date_proto_thunks.rs/mod.rs/global_this.rs, #4393 touchesdate.rs). Setters /toXformatters keep the no-op path for now (follow-up).