Repository navigation
Add jsg::Arguments<T> rest parameters to Rust JSG - #8213
Conversation
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[].
There was a problem hiding this comment.
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_countstops 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
There was a problem hiding this comment.
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_countstops 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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
…guments # Conflicts: # src/rust/AGENTS.md
There was a problem hiding this comment.
✅ 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
…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.
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.
and converts from a Vec with into_inner()/From.
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.
it as ...name: any[].