fix(date): brand-check this on Date.prototype setters + read [[DateValue]] before ToNumber#4412
Merged
Conversation
…lue]] before ToNumber
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
Mirrors the merged getter brand-check fix (#4397) for the
Date.prototypesetters:setDate/setFullYear/setHours/setMinutes/setMonth/setSeconds/setMilliseconds/setTime/setYearand everysetUTC*variant.Two spec gaps are closed:
Brand-check
thison the reflective value path.Date.prototype.setDate.call(nonDate, 1)must throwTypeError(thisTimeValue(this)), but the setters were installed as generic no-op thunks — so a reflective call on a non-Date silently produced garbage and test262 crashed downstream with "Cannot read properties of undefined". New brand-checking variadic thunks inobject/date_proto_thunks.rsread theIMPLICIT_THISreceiver, throw on a non-Date, and otherwise dispatch to the samejs_date_apply_setterthe instance fast path uses (so reflective setter calls now also work).Read
[[DateValue]]beforeToNumber. The spec capturesthisTimeValuebefore coercing any argument; a uservalueOfthat re-enters and mutates the same cell must not be observed by the rebuild (set*/date-value-read-before-tonumber-when-date-is-{valid,invalid}).js_date_apply_setternow snapshots the timestamp first and threads it into the rebuild helpers, which no longer re-read the (possibly mutated) cell. A NaN time value with no year override now returnsNaNwithout writing[[DateValue]], matching the spec's early return.setYear(annexB, local-only, with the0..=99 → 1900+yrebase) gets a dedicated runtime field code (8) so the capture-before-ToNumber ordering holds for it too.Validation
built-ins/Date: 122 → 84 failures. Set-diff vs anorigin/mainbaseline build: 40 real fixes, 0 regressions. Allset*/this-value-non-date,set*/this-value-non-object,set*/this-not-date, andset*/date-value-read-before-tonumber-*cases now pass. (TwoDate.UTC/*entries that the radar flips between runs were confirmed pre-existing — they fail identically on the baseline binary; the radar's run-to-run nondeterminism, not this change.) Remaining setter failures (arg-*-to-number,new-value-time-clip) are pre-existing coercion/TimeClip gaps untouched here.node --experimental-strip-types) in bothPERRY_NO_AUTO_OPTIMIZE=1and default builds for: reflective non-Date throw, reflectivesetFullYear.call(realDate), both read-before-ToNumber cases (valid + invalid), andsetYearreflective.cargo test --release -p perry-runtime --lib -- --test-threads=1→ 979 passed, 0 failed.Scope
Runtime-only:
crates/perry-runtime/src/{date.rs, object/date_proto_thunks.rs, object/global_this.rs}. No codegen changes.Out of scope (follow-up): the instance fast path for the legacy
setYear/getYear(d.setYear(50)) has no codegen lowering and still no-ops — theannexB/built-ins/Date/prototype/setYear/*instance tests need a new HIR setter variant across the codegen backends. The reflectiveDate.prototype.setYear.call(...)path is fixed by this PR.