Skip to content

Add jsg::Arguments<T> rest parameters to Rust JSG - #8213

Merged
bartlomieju merged 3 commits into
mainfrom
biwanczuk/rust-jsg-arguments
Nov 5, 2026
Merged

bartlomieju merged 3 commits into
mainfrom
biwanczuk/rust-jsg-arguments

Conversation

@bartlomieju

Copy link
Copy Markdown
Collaborator

C++ JSG's jsg::Arguments lets a method take a variable number of
trailing arguments; SQL exec(), timers' extra arguments, setImmediate and
unsafe-eval's newFunction use it. Rust JSG had no equivalent, so none of
these could move to Rust.

  • Add jsg::Arguments, a Vec newtype that derefs to [T], iterates,
    and converts from a Vec with into_inner()/From.
  • #[jsg_method] and #[jsg_constructor] turn a last jsg::Arguments
    parameter into the remaining arguments, each unwrapped as T. A
    mismatch is the usual "parameter N is not of type 'T'" TypeError,
    naming the rest parameter's position as C++ does.
  • A jsg::Arguments parameter that is not last is a compile error.
  • The rest parameter is not counted in .length.
  • RTTI describes it as JSG_VARARGS, as C++ does, so TypeScript declares
    it as ...name: any[].

C++ JSG's jsg::Arguments<T> lets a method take a variable number of
trailing arguments; SQL exec(), timers' extra arguments, setImmediate and
unsafe-eval's newFunction use it. Rust JSG had no equivalent, so none of
these could move to Rust.

* Add jsg::Arguments<T>, a Vec<T> newtype that derefs to [T], iterates,
  and converts from a Vec with into_inner()/From.
* #[jsg_method] and #[jsg_constructor] turn a last jsg::Arguments<T>
  parameter into the remaining arguments, each unwrapped as T. A
  mismatch is the usual "parameter N is not of type 'T'" TypeError,
  naming the rest parameter's position as C++ does.
* A jsg::Arguments parameter that is not last is a compile error.
* The rest parameter is not counted in .length.
* RTTI describes it as JSG_VARARGS, as C++ does, so TypeScript declares
  it as ...name: any[].
@bartlomieju
bartlomieju requested review from a team as code owners November 4, 2026 11:45

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of a686f87c.

This review, of 4f97224b

✅ Approved — No findings. The rest-parameter support matches C++ JSG's behaviour and is well tested.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

The AGENTS.md update is consistent with the change.


📋 Code Quality: ✅ LGTM

The macro changes match C++ JSG.

  • Error messages: each rest element is unwrapped at the rest parameter's own position, so a TypeError names that position.
  • .length: required_argument_count stops at the rest parameter.
  • Fast API: a jsg::Arguments<T> parameter is not a Fast API type, so these methods stay on the slow path.
  • Placement: a rest parameter that is not last is rejected with a single clear compile error.

⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The README and doc comment updates are accurate.


Reviewed commit: 4f97224b

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 9501def2.

This review, of a686f87c

✅ Approved — No findings. The rest-parameter support matches C++ JSG's behaviour and is well tested.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

The AGENTS.md update is consistent with the change.


📋 Code Quality: ✅ LGTM

The macro changes match C++ JSG.

  • Error messages: each rest element is unwrapped at the rest parameter's own position, so a TypeError names that position.
  • .length: required_argument_count stops at the rest parameter.
  • Fast API: a jsg::Arguments<T> parameter is not a Fast API type, so these methods stay on the slow path.
  • Placement: a rest parameter that is not last is rejected with a single clear compile error.

⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The README and doc comment updates are accurate.


Reviewed commit: a686f87c — same changes as 4f97224b, so this is that commit's review (no new review was run; line numbers are as of 4f97224b)

@codecov-commenter

codecov-commenter commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.87%. Comparing base (b9b44d8) to head (9501def).

Files with missing lines Patch % Lines
src/rust/jsg/arguments.rs 0.00% 24 Missing ⚠️
src/rust/jsg/rtti.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8213      +/-   ##
==========================================
- Coverage   68.88%   68.87%   -0.02%     
==========================================
  Files         745      746       +1     
  Lines      195047   195074      +27     
  Branches    30288    30288              
==========================================
- Hits       134350   134348       -2     
- Misses      42925    42952      +27     
- Partials    17772    17774       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — No findings. Rest-parameter support matches C++ JSG's behaviour and is well tested; the changes since the last review are consistent with it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

The src/rust/AGENTS.md update, including the merge-conflict resolution, is consistent with the change.


📋 Code Quality: ✅ LGTM

The macro changes match C++ JSG. Rest elements are unwrapped at the rest parameter's position, .length leaves the rest parameter out, and a rest parameter that is not last is rejected at compile time. jsg::Arguments<T> implements Traced and HoldsNoGcReferences by forwarding to its elements.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The README and doc comment updates are accurate.


Reviewed commit: 9501def2

@bartlomieju
bartlomieju merged commit 8c82573 into main Nov 5, 2026
33 of 38 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/rust-jsg-arguments branch November 5, 2026 10:40
bartlomieju added a commit that referenced this pull request Nov 5, 2026
…spose

Conflicts with #[jsg_callable] (#8201) were parallel additions, resolved
by keeping both: the Member, descriptor and RTTI variants, the macros'
registrations and docs.

Two fixes the merge needs to compile:

- #8213 added an early return to generate_callbacks() written for the
  TokenStream it returned before; it returns a Result here.
- #8201 made member attributes re-emit the function with its other
  attributes, so that a later #[jsg_callable] expands. The disposer
  relied on the first attribute dropping them, and a #[jsg_dispose] after
  a #[jsg_method] (or after an invalid #[jsg_property] or
  #[jsg_inspect_property]) generated a second <name>_callback. Those
  attributes now drop just the disposer attributes, and a disposer
  attribute generates no callback when another member attribute, or the
  other disposer attribute, is on the function.
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.

4 participants