Repository navigation
fix(runtime): strict arr[i]=v / arr.length=n on a frozen array throws TypeError
#6026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,6 +380,32 @@ pub extern "C" fn js_array_pop_f64(arr: *mut ArrayHeader) -> f64 { | |
| /// JSValue). The JS ArraySetLength path coerces it with `Number(...)`, then | ||
| /// rejects NaN, negative, fractional, infinite, and >uint32 lengths with | ||
| /// `RangeError: Invalid array length`. | ||
| /// `arr.length = v` as the user-visible assignment — `Set(O, "length", v, true)` | ||
| /// (PutValue with `Throw = true`, ECMA-262 §13.15.2). A frozen array's `length` | ||
| /// is a non-writable data property, so the write must throw a **TypeError** | ||
| /// rather than silently no-op — even when `v` equals the current length or is an | ||
| /// invalid length (V8 rejects the non-writable write before coercing the value, | ||
| /// so a frozen `arr.length = -1` is a TypeError, not a RangeError; hence the | ||
| /// guard precedes `array_length_from_property_value_or_throw`). | ||
| /// | ||
| /// This throwing variant is separate from `js_array_set_length` so the *internal* | ||
| /// callers of the latter (`Object.defineProperty(arr, "length", …)`, | ||
| /// array-object length coercion, stream/url bookkeeping) keep their silent, | ||
| /// non-throwing `[[DefineOwnProperty]]`/no-Throw contract. Only the assignment | ||
| /// codegen paths (`field_set_by_name` / `property_set` / proxy `PutValue`) route | ||
| /// here. test262 built-ins/Array length-write-on-frozen. | ||
| #[no_mangle] | ||
| pub extern "C" fn js_array_set_length_strict(arr: *mut ArrayHeader, new_length: f64) { | ||
| let arr = clean_arr_ptr_mut(arr); | ||
| if arr.is_null() { | ||
| return; | ||
| } | ||
| if unsafe { array_object_flags(arr) } & crate::gc::OBJ_FLAG_FROZEN != 0 { | ||
| throw_non_writable_length(); | ||
| } | ||
| js_array_set_length(arr, new_length); | ||
| } | ||
|
Comment on lines
+398
to
+407
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Map the relevant file and locate the array-length setters and callers.
git ls-files crates/perry-runtime/src/array/push_pop.rs \
crates/perry-runtime/src/property_set.rs \
crates/perry-runtime/src/field_set_by_name.rs \
crates/perry-runtime/src/put_value.rs
echo '--- outline: push_pop.rs ---'
ast-grep outline crates/perry-runtime/src/array/push_pop.rs --view expanded || true
echo '--- search for length setter functions and descriptor checks ---'
rg -n "js_array_set_length|OBJ_FLAG_ARRAY_DESCRIPTORS|get_property_attrs\\(|throw_non_writable_length|writable\\(" \
crates/perry-runtime/src/array/push_pop.rs \
crates/perry-runtime/src/property_set.rs \
crates/perry-runtime/src/field_set_by_name.rs \
crates/perry-runtime/src/put_value.rs
echo '--- relevant slices from push_pop.rs ---'
sed -n '300,470p' crates/perry-runtime/src/array/push_pop.rs
echo '--- relevant caller slices ---'
sed -n '1,260p' crates/perry-runtime/src/property_set.rs
sed -n '1,260p' crates/perry-runtime/src/field_set_by_name.rs
sed -n '1,260p' crates/perry-runtime/src/put_value.rsRepository: PerryTS/perry Length of output: 3993 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- relevant slice: push_pop.rs ---'
sed -n '1,80p' crates/perry-runtime/src/array/push_pop.rs
sed -n '380,450p' crates/perry-runtime/src/array/push_pop.rs
echo '--- locate caller files ---'
git ls-files | rg '(^|/)(property_set|field_set_by_name|put_value)\.(rs|ts|js)$|(^|/)put_value\.rs$|(^|/)property_set\.rs$|(^|/)field_set_by_name\.rs$'
echo '--- search for js_array_set_length_strict call sites ---'
rg -n "js_array_set_length_strict|js_array_set_length\\(" crates/perry-runtime/src
echo '--- search for non-writable length guards ---'
rg -n "array_length_is_non_writable|guard_writable_length|throw_non_writable_length|get_property_attrs\\(arr as usize, \"length\"" crates/perry-runtime/srcRepository: PerryTS/perry Length of output: 10889 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- field_set_by_name.rs around strict length writes ---'
sed -n '560,640p' crates/perry-runtime/src/object/field_set_by_name.rs
echo '--- proxy/put_value.rs around strict length writes ---'
sed -n '160,220p' crates/perry-runtime/src/proxy/put_value.rs
echo '--- object/native_call_method/common_methods.rs around length guard usage ---'
sed -n '760,810p' crates/perry-runtime/src/object/native_call_method/common_methods.rs
echo '--- object/native_call_method/handle_methods.rs around length guard usage ---'
sed -n '340,385p' crates/perry-runtime/src/object/native_call_method/handle_methods.rsRepository: PerryTS/perry Length of output: 11923
🤖 Prompt for AI Agents |
||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn js_array_set_length(arr: *mut ArrayHeader, new_length: f64) { | ||
| let arr = clean_arr_ptr_mut(arr); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 5118
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
Handle descriptor-backed non-writable array writes in the strict path
array_strict_index_write_guardonly throws for frozen/sealed/non-extensible arrays, butjs_array_set_f64_extendstill returns silently forOBJ_FLAG_ARRAY_DESCRIPTORSslots with!attrs.writable()and for a non-writablelength. That makes strictarr[i] = vno-op instead ofTypeErroron descriptor-backed arrays.🤖 Prompt for AI Agents