fix(array): exotic index propagation for Object.prototype + join/slice#5764
Conversation
#5589) Three runtime fixes for test262 built-ins/Array failures: 1. `array_iteration_is_exotic` (indexing.rs): add `OBJECT_PROTO_HAS_INDEX` check alongside the existing `ARRAY_PROTO_HAS_INDEX` one. Without it, any method that delegates to the exotic slow-path (reduce, reduceRight, forEach, map, filter, find, findIndex, every, some, indexOf, lastIndexOf, flat, flatMap, sort) would not notice a numeric property added to Object.prototype, causing a missed inherited read and a wrong result. 2. `js_array_join` (iter_methods.rs): add the exotic fast/slow-path split that every other iteration method already uses. Previously join always read directly from the dense element store, so a numeric property on Array.prototype or Object.prototype was invisible to join/toString. 3. `js_array_slice` (splice_slice.rs): same fix — when the source array is exotic, use array_spec_has_index/array_spec_get per element so inherited indices appear in the slice result (ECMA-262 §23.1.3.25 step 8b). All three cases are covered by a passing Perry verification test.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesExotic Array Handling in join/slice
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/perry-runtime/src/array/splice_slice.rs`:
- Around line 287-295: The splice_slice slice path is incorrectly materializing
absent dense slots as TAG_HOLE into custom-species results. Update the logic
around `src_exotic`, `array_spec_has_index`, `array_spec_get`, and
`species_result_set` in `splice_slice` so that non-exotic sources still skip
missing indices before writing into the result. Ensure absent slots are treated
as holes and never passed to `species_result_set` for custom species, matching
slice behavior for exotic sources.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 24b06148-63b5-48cb-9c9f-9abd1cedd645
📒 Files selected for processing (3)
crates/perry-runtime/src/array/indexing.rscrates/perry-runtime/src/array/iter_methods.rscrates/perry-runtime/src/array/splice_slice.rs
In js_array_slice's custom-species branch, the non-exotic else path was forwarding raw TAG_HOLE values to species_result_set, creating a property on the result for absent dense slots. The spec (§23.1.3.25 step 8b) only calls CreateDataPropertyOrThrow when HasProperty(O, from) is true, so holes must be skipped regardless of whether the source is exotic.
Summary
Three focused runtime fixes that extend Perry's "exotic array" slow-path to cover
Object.prototypenumeric indices and two previously unguarded methods (join,slice), reducing test262built-ins/Arrayfailures tracked in #5589.Changes
crates/perry-runtime/src/array/indexing.rs—array_iteration_is_exotic: addOBJECT_PROTO_HAS_INDEXcheck alongside the existingARRAY_PROTO_HAS_INDEXone. Every iteration method (reduce,reduceRight,forEach,map,filter,find,findIndex,every,some,indexOf,lastIndexOf,flat,flatMap,sort) already delegates to this predicate; without the extra check, a numeric property onObject.prototypewas invisible to all of them.crates/perry-runtime/src/array/iter_methods.rs—js_array_join: add the exotic fast/slow-path split that every other iteration method already uses. Previouslyjoin(and thusArray.prototype.toString) always read directly from the dense element store, so inherited numeric properties onArray.prototypeorObject.prototypewere silently skipped.crates/perry-runtime/src/array/splice_slice.rs—js_array_slice: same exotic-path split for both the plain-array and species-container branches. Per ECMA-262 §23.1.3.25 step 8b,slicemust use[[HasProperty]]/[[Get]]per element, so an inherited index should appear in the result.Related issue
Refs #5589
Test plan
Before/after comparison against the test262
built-ins/Arraysubset is not directly runnable (network policy blocks thetc39/test262clone in this environment), but each fix was verified with a hand-written Perry script covering the three cases:Output:
all tests passed(Perry exit 0).cargo build --releaseclean (perry, perry-runtime, perry-stdlib — all warnings, zero errors)cargo fmt --all -- --checkpassesbash scripts/check_file_size.shpassesScreenshots / output
Checklist
feat:/fix:/docs:/chore:prefix convention used in the logGenerated by Claude Code
Summary by CodeRabbit
join, andsliceto correctly account for indexed properties inherited fromObject.prototype, avoiding incorrect dense-element reads.joinbehavior for special/exotic array forms by skipping missing indices and preserving correct element presence.sliceso absent entries are kept as holes and missing indices aren’t turned into result properties, including for custom/spec species behavior.