Fix readonly array descriptors not throwing TypeError in strict mode#2542
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix readonly descriptors not throwing JavaScriptException
Fix readonly array descriptors not throwing TypeError in strict mode
Jun 18, 2026
…#2541) Assigning to a non-writable element of a frozen native array — or a frozen / read-only interop list wrapper — silently failed instead of throwing a TypeError in strict mode (a regression from 4.9.3 where the dense-write fast paths bypassed the writability check). - ArrayInstance.TryWriteExistingDense: bail to the full Set/PutValue path when a materialized _sparse element descriptor is non-writable and the array is non-extensible, so strict-mode assignment throws. Gating on !Extensible keeps the common dense-write fast path free of a dictionary probe (an extensible array's fallback ArrayInstance.Set writes through regardless, so the check would be wasted there) and avoids a per-write probe on arrays previously enumerated via Object.keys / for-in (which materialize _sparse alongside _dense). - ArrayLikeWrapper.Set: refuse in-range element writes to read-only / non-extensible (frozen) wrappers, which base.SetSlow would otherwise silently accept by materializing a throwaway descriptor. Writable writes, growth, and runtime read-only collections (e.g. ReadOnlyCollection<T>) defer to base.Set unchanged. Adds native-array and interop-wrapper regression tests covering strict-mode throw, non-strict silent no-op, non-mutation, and a runtime read-only collection. Closes #2541 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lahma
force-pushed
the
copilot/fix-readonly-descriptors-issue
branch
from
June 23, 2026 13:04
9880420 to
21fafaf
Compare
lahma
marked this pull request as ready for review
June 23, 2026 13:04
lahma
enabled auto-merge (squash)
June 23, 2026 13:07
This was referenced Jun 24, 2026
This was referenced Jul 2, 2026
This was referenced Jul 10, 2026
This was referenced Jul 20, 2026
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
Fix
TryWriteExistingDensebypassing writability checks on frozen/locked array elements.Details
When array elements were made non-writable via
FastSetProperty+PreventExtensions, theSimpleAssignmentExpression.SetValuefast path calledTryWriteExistingDensewhich only checked slot occupancy—never descriptor writability. This silently overwrote (or appeared to overwrite) read-only elements without throwing in strict mode.Fixes:
ArrayInstance.TryWriteExistingDense: bail out when_sparsehas a non-writable descriptor for the index, forcing fallback to the fullPutValuepath that enforces strict-mode TypeError.ArrayLikeWrapper.Set: handle numeric index writes directly withCanWrite/Extensibleguards (consistent with howObjectWrapper.Sethandles string-keyed properties), preventing theSetSlowfallback from incorrectly returningtrue.Repro from the issue:
Linked issue
Closes #2541
Test plan
Jint.Testsdotnet test --configuration ReleaselocallyJint.Tests.Test262and confirmed no regressions (99,260 pass)Jint.Tests/Runtime/InteropJint.BenchmarkBreaking change?
No. Restores pre-4.10.0 behavior where writing to non-writable array elements throws in strict mode.