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
Follow-up to PR #2499 (which wired TypedArray.prototypemap/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)
consta=newInt32Array([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 reverseda.reduce((s,x)=>s+x,0);// Node 15a.join("-");// Node "1-2-3-4-5"a.indexOf(3);// Node 2a.lastIndexOf(3);// Node 2a.includes(3);// Node truea.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 1for(constvofa.keys()){}// 0..n-1for(constvofa.values()){}// elementsfor(const[i,v]ofa.entries()){}newInt32Array([1,2,3])instanceofInt32Array// Perry: false Node: true
Where 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 — add js_typed_array_{fill,copy_within,reverse,reduce,reduce_right,join,index_of,last_index_of,includes,slice,subarray,set,keys,values,entries} (mirror the map/filter/find_last impls already there). map/filter/slice/subarray return 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 the lookup_typed_array_kind delegation guard at the top (mirror array/sort.rs lines ~25 and PR fix(runtime): TypedArray map/filter/every/some/forEach/find/findIndex read element-typed storage #2499's guards in iter_methods.rs).
Lowering routing for fill/copyWithin/reverse: these currently error "(number).fill is not a function" because crates/perry-hir/src/lower/expr_call/local_array_methods.rs does NOT route them to the generic Expr::Array* variants for TA receivers — add them to the typed-array-allowed method match there (the is_typed_array arm around the map/filter block).
instanceof Int32Array: crates/perry-runtime/src/object/instanceof.rs (js_instanceof / js_instanceof_dynamic) + the codegen class-id map in crates/perry-codegen/src/expr/instance_misc1.rs — add reserved class-ids per TA kind detected via lookup_typed_array_kind.
Acceptance criteria
All methods above byte-match node --experimental-strip-types for Int32Array AND Float64Array (different element kinds).
map/filter/slice/subarray return a same-kind TypedArray; x instanceof Int32Array true (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 300 improves; no regression in built-ins/Array.
Refs: PR #2499 (the pattern to copy), Test262 radar #799.
Summary
Follow-up to PR #2499 (which wired
TypedArray.prototypemap/filter/every/some/forEach/find/findIndex). The remaining%TypedArray%.prototypemethods are still unwired or broken, andx instanceof Int32Arrayis false for any typed array.Concrete gaps (Perry vs Node)
Where the code lives (pattern is established by PR #2499)
The established pattern: the generic
js_array_*helper detects a typed-array receiver viacrate::typedarray::lookup_typed_array_kind(arr as usize).is_some()and delegates to ajs_typed_array_*impl that reads/writes viaload_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).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
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).scripts/test262_subset.py --dir built-ins/TypedArray --max 300improves; no regression inbuilt-ins/Array.Refs: PR #2499 (the pattern to copy), Test262 radar #799.