Skip to content

fix(runtime): Array-subclass fill honours start and end - #8972

Merged
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:fix/array-subclass-fill-args
Aug 28, 2026
Merged

fix(runtime): Array-subclass fill honours start and end#8972
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:fix/array-subclass-fill-args

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

js_array_subclass_init installs fill as an own method on the instance (node inherits it from Array.prototype; perry has no such prototype object for these classes), and the stub was registered with arity 1 — so start and end never reached js_array_fill_generic:

class A extends Array {}
const b = new A(); b.push(1, 2, 3, 4);
b.fill(9, 1);      // node: [1,9,9,9]   perry: [9,9,9,9]
b.fill(9, 1, 3);   // node: [1,9,9,4]   perry: [9,9,9,9]

The stub now takes (value, start, end); an omitted argument arrives as undefined and selects the spec default (0 / length).

Verified against node on all four forms (value only, start, start+end, negative start) — array_subclass_fill_args.rs, and the compiled output matches node exactly.

Found while probing Array-subclass semantics for the elements-store work (#8966).

https://claude.ai/code/session_019WVcWKmYsUBnnFB7nBgbBJ

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Array.prototype.fill on classes extending Array to respect optional start and end arguments.
    • Calls such as fill(value, start), bounded ranges, and negative indices now produce the expected results while preserving default behavior.
  • Tests

    • Added coverage for supported fill argument combinations on array subclasses.
  • Documentation

    • Added a changelog entry describing the fix.

`js_array_subclass_init` installs `fill` on the instance, and that stub had
arity 1: every `start` / `end` argument was dropped, so `sub.fill(8, 1)`
overwrote the whole array instead of the tail from index 1 (node prints
`7|8|8`, perry printed `8|8|8`). The stub now takes both, treating an
omitted (`undefined`) argument as the spec default.

e2e test covers value-only, a start, a start and end, and a negative start
against node's output.

Claude-Session: https://claude.ai/code/session_019WVcWKmYsUBnnFB7nBgbBJ
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fcb215d1-dc6c-4ebd-b87b-4dd3bcf4c01e

📥 Commits

Reviewing files that changed from the base of the PR and between 978bdb5 and 9c1b956.

📒 Files selected for processing (1)
  • changelog.d/8972-array-subclass-fill-args.md

📝 Walkthrough

Walkthrough

Array subclass initialization now installs a three-argument fill stub. ns_array_fill forwards optional start and end values. Integration tests cover default, positive, bounded, and negative ranges.

Changes

Array subclass fill behavior

Layer / File(s) Summary
Register and forward fill arguments
crates/perry-runtime/src/node_stream_constructors/builders.rs
Array subclass initialization uses arity 3 and cast3 for ns_array_fill. The function forwards optional start and end values to generic array filling.
Validate fill ranges
crates/perry/tests/array_subclass_fill_args.rs, changelog.d/8972-array-subclass-fill-args.md
The integration test covers value-only, start, bounded, and negative-start calls. The changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🟡 Moderate · up to 978bd

This change makes Array-subclass fill honor start and end, but proxy receivers can run user code while reading length before those range objects are coerced. Because the current path does not preserve start and end across that moving-memory boundary, it carries a bounded runtime memory-safety risk; merge should wait for the rooting fix or explicit owner acceptance.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, the fix, and the test coverage, but it omits the required Summary, Changes, Related issue, Test plan, and Checklist sections from the repository template. Rewrite the description using the repository template. Add the required section headings, state the related issue or use "n/a", list concrete changes, provide verification commands or results, and complete the checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main runtime fix: Array-subclass fill now honors start and end arguments.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

xxxxxxxxxxxxx and others added 2 commits August 28, 2026 20:06
Fragment filenames are PR-keyed so in-flight PRs cannot collide; 0000 collides
with every other placeholder.
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Merged. A clean bug and a clean fix — arity 1 meant start/end never reached js_array_fill_generic, so b.fill(9, 1) filled the whole array.

The part worth checking was the omitted-argument path, since an absent arg arrives as NaN-boxed undefined and passing it straight through as an f64 would read as a number. present() tests is_undefined() and passes a 0/1 presence flag, so the generic helper takes its spec default instead. Correct.

The new test also covers the shapes that matter rather than just the reported one: fill(9), fill(9,1), fill(9,1,3) and fill(9,-2) — the negative relative index being the case most likely to go wrong once start actually arrives.

One fix pushed: the fragment was changelog.d/0000-array-subclass-fill-args.md; renamed to 8972-. Filenames are PR-keyed so in-flight PRs cannot collide, and 0000 collides with every other placeholder — there are three such files already on main, which I am cleaning up separately.

Validation — runtime 2779/0 (RUST_TEST_THREADS=1), and I ran the new integration test on the debug profile the harness actually links (cargo build -p perry-runtime-static -p perry-stdlib-static first): 1 passed. scripts/run_lint_gates.sh 57 of 58 with the compile tier green — the exception is the pre-existing \${{ }} artifact (#8929).

@proggeramlug
proggeramlug merged commit 00f4671 into PerryTS:main Aug 28, 2026
18 of 19 checks passed
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.

2 participants