You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5f4f78a
Browse filesBrowse the repository at this point in the historyBrowse files
Ralph Kuepper
committed
fix(runtime): strict arr[i]=v / arr.length=n on a frozen array throws TypeError
Perry compiles everything strict, so a source-level array element or `length`
assignment is `Set(O, P, V, Throw = true)`. On a *frozen* array these targets
are non-writable, so the write must throw a TypeError -- Perry silently no-oped
instead, leaving a batch of test262 missed-negatives:
"use strict";
const a = Object.freeze([1, 2, 3]);
a[0] = 9; // was: silent; now: TypeError read-only property '0'
a[5] = 9; // was: silent; now: TypeError not extensible
a.length = 1; // was: silent; now: TypeError read-only property 'length'
Adding a NEW index to any non-extensible array (frozen / sealed /
preventExtensions'd) likewise now throws "object is not extensible", matching
V8/Node.
Design -- strict variants beside the silent helpers, so ONLY user assignments
throw and every internal caller keeps its no-Throw contract:
* js_array_set_f64_extend_strict / js_array_set_index_or_string_strict --
element writes; share array_strict_index_write_guard (existing index of a
frozen array -> read-only; new index of a non-extensible array -> not-
extensible; sealed/non-extensible still permit overwriting an existing
index, so only is_frozen gates the in-bounds case).
* js_array_set_length_strict -- frozen `length` write, even for an equal or
invalid new value (V8 rejects the non-writable write before coercing, so a
frozen arr.length = -1 is a TypeError, not a RangeError; the guard precedes
the length parse).
The plain js_array_set_{f64_extend,index_or_string,length} helpers keep their
silent behaviour for their internal callers -- Object.defineProperty (which
uses them as raw [[DefineOwnProperty]] slot-writers), array-object length
coercion, polymorphic_index, and freshly-allocated runtime arrays. The
assignment paths are re-pointed to the strict variants: the arr[i]=v codegen
(js_typed_feedback_array_set_{f64_extend,index_or_string} wrappers, emitted only
for the source assignment, plus the realloc slow path in expr/index.rs), the
arr.length=v codegen (expr/property_set.rs), the generic PutValue helper
js_object_set_field_by_name, and js_put_value_set (strict-flag gated).
Verified on an internal Linux sweep host, matching Node byte-for-byte in both
default (auto-optimize) and PERRY_NO_AUTO_OPTIMIZE builds:
* frozen element (existing/new) + length (shrink/grow/same) all throw;
* sealed / preventExtensions add-new-index throws; existing-index overwrite
still succeeds;
* normal (unfrozen) element / length / string-index / computed / dense-loop
writes are unchanged (no over-throw);
* Object.defineProperty(frozenArr, ...) (same-value ok, changed-value throws
via its own validation), and frozen concat/map/slice/spread read-then-build
ops, all unaffected.
Out of scope (separate, non-frozen subclusters): sealed-array .length shrink,
and defineProperty-installed non-writable index/length descriptors.
0 commit comments