Repository navigation
fix(typedarray): wire remaining %TypedArray%.prototype methods + instanceof (#3148) - #3538
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3148. Follow-up to PR #2499.
Wires the remaining
%TypedArray%.prototypemethods andinstanceoffor all typed-array kinds.reduce/reduceRight/copyWithin/findIndex/setalready landed on main independently; this fills in the rest by routing typed-array receivers through the genericjs_array_*helpers, which delegate to element-typedjs_typed_array_*impls vialookup_typed_array_kind.What's added
Runtime (
typedarray.rs) —js_typed_array_join/join_value/slice/reverse/fill/subarray.slice/subarrayreturn 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; broadeningis_array_exprroutes TA receivers through it, so the guard is required to avoid reading the element-typed buffer as boxed f64instanceof— reserved per-kind class ids0xFFFF0030..3A(throughBigUint64Array) in codegen, resolved at runtime viaclass_id_for_kind.x instanceof Int32Arrayis now true (and false for the wrong kind / non-TA).Codegen routing —
is_array_exprrecognizes Named TA receivers so their not-already-folded methods reachlower_array_method(+ newset/subarrayarms + extern decls); thelocal_array_methodsslice arm folds TA receivers toArraySlice.indexOf/lastIndexOf/includesalready delegate (pre-existing, #2457).Validation
node --experimental-strip-typesforInt32ArrayandFloat64Arrayacross all the above methods +instanceof(test-files/test_gap_typed_array_proto_methods.ts).map/filter/at/with/sort/findLast) verified unaffected — guards only fire for genuine TA pointers.cargo fmtclean.perry-runtimesuite green (the only failures are pre-existinggc::tests::barrierflakes that pass in isolation; my changes touch no GC code).