Skip to content

fix(typedarray): wire remaining %TypedArray%.prototype methods + instanceof (#3148) - #3538

Merged
proggeramlug merged 1 commit into
mainfrom
fix/typedarray-proto-methods-3148
May 31, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
fix/typedarray-proto-methods-3148

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Closes #3148. Follow-up to PR #2499.

Wires the remaining %TypedArray%.prototype methods and instanceof for all typed-array kinds. reduce/reduceRight/copyWithin/findIndex/set already landed on main independently; this fills in the rest by routing typed-array receivers through the generic js_array_* helpers, which delegate to element-typed js_typed_array_* impls via lookup_typed_array_kind.

What's added

Runtime (typedarray.rs) — js_typed_array_join / join_value / slice / reverse / fill / subarray. slice/subarray return a same-kind TypedArray.

Delegation guards

  • js_array_reverse / js_array_fill / js_array_fill_range (concat_reverse.rs)
  • js_array_slice (splice_slice.rs)
  • js_array_join (iter_methods.rs)
  • js_array_copy_within (immutable.rs) — this path was previously unguarded; broadening is_array_expr routes TA receivers through it, so the guard is required to avoid reading the element-typed buffer as boxed f64
  • keys/values/entries iterator objects materialize the TA to a plain array first (iter_object.rs) so iteration yields numbers, not raw f64 bytes

instanceof — reserved per-kind class ids 0xFFFF0030..3A (through BigUint64Array) in codegen, resolved at runtime via class_id_for_kind. x instanceof Int32Array is now true (and false for the wrong kind / non-TA).

Codegen routing — is_array_expr recognizes Named TA receivers so their not-already-folded methods reach lower_array_method (+ new set/subarray arms + extern decls); the local_array_methods slice arm folds TA receivers to ArraySlice.

indexOf / lastIndexOf / includes already delegate (pre-existing, #2457).

Validation

  • Byte-matches node --experimental-strip-types for Int32Array and Float64Array across all the above methods + instanceof (test-files/test_gap_typed_array_proto_methods.ts).
  • Plain arrays and already-landed TA methods (map/filter/at/with/sort/findLast) verified unaffected — guards only fire for genuine TA pointers.
  • cargo fmt clean. perry-runtime suite green (the only failures are pre-existing gc::tests::barrier flakes that pass in isolation; my changes touch no GC code).

…anceof (#3148)

Follow-up to PR #2499. Adds the still-missing %TypedArray%.prototype
methods (reduce/reduceRight/copyWithin/findIndex/set were already landed
on main; this fills the rest) by routing them through the generic
js_array_* helpers, which delegate to element-typed js_typed_array_*
impls via lookup_typed_array_kind:

- join (default + custom separator), reverse (in-place), fill / fill(value,start,end)
- slice / subarray — return a same-kind TypedArray
- copyWithin — js_array_copy_within now delegates to js_typed_array_copy_within
  (the existing immutable.rs path was unguarded; the broadened is_array_expr
  routes TA receivers through it, so the guard is required to avoid reading
  the element-typed buffer as boxed f64)
- keys / values / entries — materialize element-typed before building the
  iterator object so iteration yields numbers, not raw f64 bytes
- set(source, offset?) — codegen "set"/"subarray" arms + extern decls

indexOf / lastIndexOf / includes already delegate (pre-existing, #2457).

instanceof: reserved per-kind class ids (0xFFFF0030..3A) for all kinds
through BigUint64Array, resolved at runtime via class_id_for_kind so
`x instanceof Int32Array` is true (false for the wrong kind / non-TA).

Codegen routing: is_array_expr recognizes Named TA receivers so their
not-already-folded methods reach lower_array_method; the local_array_methods
slice arm folds TA receivers to ArraySlice.

Byte-matches `node --experimental-strip-types` for Int32Array and
Float64Array (test-files/test_gap_typed_array_proto_methods.ts). Plain
arrays and the already-landed TA methods (map/filter/at/with/sort) are
unaffected (guards only fire for genuine TA pointers).
@proggeramlug
proggeramlug merged commit a749c45 into main May 31, 2026
11 checks passed
@proggeramlug
proggeramlug deleted the fix/typedarray-proto-methods-3148 branch May 31, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypedArray: remaining prototype methods (fill/copyWithin/reduce/join/indexOf/slice/…) + instanceof

1 participant