Subset of #2447.
Array.prototype.lastIndexOf works for plain arrays but returns the wrong result (and crashes in the 2-arg form) for TypedArray receivers, because at the HIR level lastIndexOf on a TypedArray is lowered to the string lastIndexOf path (js_string_last_index_of) instead of the array path (js_array_last_index_of_jsvalue).
Repro
const ta = new Int32Array([1, 2, 3, 2, 1]);
console.log(ta.lastIndexOf(2)); // Perry: -1 node: 3
console.log(ta.lastIndexOf(2, 2)); // Perry: TypeError "(number).lastIndexOf is not a function" node: 1
Evidence
perry compile --trace llvm shows ta.lastIndexOf(2) emitting call i32 @js_string_last_index_of, while ta.indexOf(2) correctly emits call i32 @js_array_indexOf_jsvalue.
Fix direction
Route TypedArray (and array) lastIndexOf to js_array_last_index_of_jsvalue in the HIR method-dispatch (crates/perry-hir/src/lower/array_fold.rs / the expr_call/*_array_methods.rs lowering that currently treats lastIndexOf as string-or-array). The runtime side (js_array_last_index_of_jsvalue) already handles plain arrays with full fromIndex clamping; it just needs a TypedArray branch mirroring the indexOf/includes one added in #2456 (as_typed_array + js_typed_array_get). PR #2456 left an explanatory NB comment at that runtime site.
Subset of #2447.
Array.prototype.lastIndexOfworks for plain arrays but returns the wrong result (and crashes in the 2-arg form) for TypedArray receivers, because at the HIR levellastIndexOfon a TypedArray is lowered to the stringlastIndexOfpath (js_string_last_index_of) instead of the array path (js_array_last_index_of_jsvalue).Repro
Evidence
perry compile --trace llvmshowsta.lastIndexOf(2)emittingcall i32 @js_string_last_index_of, whileta.indexOf(2)correctly emitscall i32 @js_array_indexOf_jsvalue.Fix direction
Route TypedArray (and array)
lastIndexOftojs_array_last_index_of_jsvaluein the HIR method-dispatch (crates/perry-hir/src/lower/array_fold.rs/ theexpr_call/*_array_methods.rslowering that currently treatslastIndexOfas string-or-array). The runtime side (js_array_last_index_of_jsvalue) already handles plain arrays with full fromIndex clamping; it just needs a TypedArray branch mirroring theindexOf/includesone added in #2456 (as_typed_array+js_typed_array_get). PR #2456 left an explanatory NB comment at that runtime site.