Repository navigation
TypedArray: remaining prototype methods (fill/copyWithin/reduce/join/indexOf/slice/…) + instanceof #3148
Copy link
Copy link
Closed
Labels
enhancementNew capability or improvementNew capability or improvementparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystemCompatibility gap with Node.js, ECMAScript, or the supported ecosystem
Description
Summary
Follow-up to PR #2499 (which wired TypedArray.prototype map/filter/every/some/forEach/find/findIndex). The remaining %TypedArray%.prototype methods are still unwired or broken, and x instanceof Int32Array is false for any typed array.
Concrete gaps (Perry vs Node)
const a = new Int32Array([1,2,3,4,5]);
a.fill(7); // Perry: TypeError "(number).fill is not a function" Node: [7,7,7,7,7]
a.copyWithin(0,3); // Perry: "(number).copyWithin is not a function" Node: [4,5,3,4,5]
a.reverse(); // in-place; Node returns same TA reversed
a.reduce((s,x)=>s+x,0); // Node 15
a.join("-"); // Node "1-2-3-4-5"
a.indexOf(3); // Node 2
a.lastIndexOf(3); // Node 2
a.includes(3); // Node true
a.slice(1,3); // Node Int32Array [2,3] (same-kind TA)
a.subarray(1,3); // Node Int32Array view [2,3]
a.set([9,9], 1); // writes 9,9 at offset 1
for (const v of a.keys()) {} // 0..n-1
for (const v of a.values()) {} // elements
for (const [i,v] of a.entries()) {}
new Int32Array([1,2,3]) instanceof Int32Array // Perry: false Node: trueWhere the code lives (pattern is established by PR #2499)
The established pattern: the generic js_array_* helper detects a typed-array receiver via crate::typedarray::lookup_typed_array_kind(arr as usize).is_some() and delegates to a js_typed_array_* impl that reads/writes via load_at/store_at (element-typed).
crates/perry-runtime/src/typedarray.rs— addjs_typed_array_{fill,copy_within,reverse,reduce,reduce_right,join,index_of,last_index_of,includes,slice,subarray,set,keys,values,entries}(mirror themap/filter/find_lastimpls already there).map/filter/slice/subarrayreturn a same-kind TypedArray.crates/perry-runtime/src/array/{concat_reverse.rs (js_array_fill, js_array_reverse), immutable.rs (js_array_copy_within), iter_methods.rs (reduce, join), search.rs (indexOf/lastIndexOf/includes)}— add thelookup_typed_array_kinddelegation guard at the top (mirrorarray/sort.rslines ~25 and PR fix(runtime): TypedArray map/filter/every/some/forEach/find/findIndex read element-typed storage #2499's guards initer_methods.rs).- Lowering routing for
fill/copyWithin/reverse: these currently error"(number).fill is not a function"becausecrates/perry-hir/src/lower/expr_call/local_array_methods.rsdoes NOT route them to the genericExpr::Array*variants for TA receivers — add them to the typed-array-allowed method match there (theis_typed_arrayarm around themap/filterblock). instanceof Int32Array:crates/perry-runtime/src/object/instanceof.rs(js_instanceof/js_instanceof_dynamic) + the codegen class-id map incrates/perry-codegen/src/expr/instance_misc1.rs— add reserved class-ids per TA kind detected vialookup_typed_array_kind.
Acceptance criteria
- All methods above byte-match
node --experimental-strip-typesforInt32ArrayANDFloat64Array(different element kinds). map/filter/slice/subarrayreturn a same-kind TypedArray;x instanceof Int32Arraytrue (and false for the wrong kind / non-TA).- Regular-array versions of these methods unaffected (the guard only fires for genuine TA pointers).
scripts/test262_subset.py --dir built-ins/TypedArray --max 300improves; no regression inbuilt-ins/Array.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew capability or improvementNew capability or improvementparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystemCompatibility gap with Node.js, ECMAScript, or the supported ecosystem
Activity
fix(typedarray): wire remaining %TypedArray%.prototype methods + inst…
fix(array): ask the typed-array question before clean_arr_ptr rejects…
fix(array): ask the typed-array question before clean_arr_ptr rejects it