Skip to content

fix(console): preserve native callable arity - #6817

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6788-console-parity
Jul 24, 2026
Merged

fix(console): preserve native callable arity#6817
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6788-console-parity

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prefer declared native/builtin callable arity over internal wrapper arity for closure .length reflection
  • keep optimized and generic property paths consistent
  • add a regression covering Console.length through the native-module lookup and IC miss paths

Validation

  • cargo test -p perry-runtime named_native_callable_length_paths_use_declared_arity
  • ./run_parity_tests.sh --suite node-suite --module console --filter without-new (1/1 passed)
  • ./run_parity_tests.sh --suite node-suite --module console (119/119 passed)
  • cargo fmt --all -- --check
  • git diff --check

Closes #6788

Summary by CodeRabbit

  • Bug Fixes
    • Corrected .length reflection for native and optimized callable functions.
    • Callables now report their declared number of parameters instead of an internal wrapper’s value.
    • Fixed Console.length to return 1, matching its declared arity.
  • Documentation
    • Added a changelog note describing the improved console parity and callable length behavior.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Runtime closure .length resolution now prefers declared native-callable arity and built-in closure metadata. Tests verify that Console.length reports 1 through generic and optimized lookup paths, with a corresponding changelog entry.

Changes

Native callable length parity

Layer / File(s) Summary
Declared arity resolution and validation
crates/perry-runtime/src/closure/dynamic_props.rs, crates/perry-runtime/src/value/dynamic_object.rs, changelog.d/6788-named-callable-length.md
Closure length lookup uses native-callable or built-in closure metadata before the existing fallback. Tests verify Console.length returns 1.0 through direct, closure, and object field lookup paths.

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

Possibly related PRs

  • PerryTS/perry#6813: Updates native-callable .length resolution and adds related arity coverage.

Suggested reviewers: andrewtdiz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely matches the main change: preserving native callable arity for console length reflection.
Description check ✅ Passed It includes a clear summary, validation steps, and the linked issue, with only non-critical template sections omitted.
Linked Issues check ✅ Passed The change fixes the reported Console.length parity mismatch and adds coverage for the failing console-class/without-new path.
Out of Scope Changes check ✅ Passed The changelog note and runtime/test updates are directly related to the console arity fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/perry-runtime/src/value/dynamic_object.rs (1)

142-160: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Keep optimized .length lookup aligned with own-property overrides.

closure_get_dynamic_prop checks the closure property table and deleted keys before applying metadata, but js_value_length_f64 applies native/builtin arity unconditionally. If length is redefined or deleted, generic and optimized reads can disagree. Apply the same override/deletion contract here, and add regression coverage for both cases.

🤖 Prompt for 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.

In `@crates/perry-runtime/src/value/dynamic_object.rs` around lines 142 - 160,
Update js_value_length_f64 to consult the closure property table and deleted-key
state for “length” before applying native or builtin metadata, matching
closure_get_dynamic_prop; honor redefined values and deleted properties so
optimized reads match generic reads. Add regression coverage for both an own
length override and a deleted length property.
🤖 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.

Outside diff comments:
In `@crates/perry-runtime/src/value/dynamic_object.rs`:
- Around line 142-160: Update js_value_length_f64 to consult the closure
property table and deleted-key state for “length” before applying native or
builtin metadata, matching closure_get_dynamic_prop; honor redefined values and
deleted properties so optimized reads match generic reads. Add regression
coverage for both an own length override and a deleted length property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c3554517-be60-46fa-8793-c934de461d66

📥 Commits

Reviewing files that changed from the base of the PR and between 20f1975 and 70e7b79.

📒 Files selected for processing (3)
  • changelog.d/6788-named-callable-length.md
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/value/dynamic_object.rs

@proggeramlug
proggeramlug merged commit 4ae96ec into PerryTS:main Jul 24, 2026
30 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.

[parity] node:console — 1 failing node-suite test (2026-07-22 baseline)

1 participant