Skip to content

Fix off-by-one and macro impls for TypedArray - #7107

Open
LordGoatius wants to merge 2 commits into
mainfrom
cloudflare/jimmyostler/jsg-rs-fixes
Open

Fix off-by-one and macro impls for TypedArray #7107
LordGoatius wants to merge 2 commits into
mainfrom
cloudflare/jimmyostler/jsg-rs-fixes

Conversation

@LordGoatius

Copy link
Copy Markdown
Contributor

Access beyond bounds is just undefined, but for both of the changes correctness is best.

@LordGoatius
LordGoatius requested review from a team as code owners August 24, 2026 21:43
@LordGoatius
LordGoatius force-pushed the cloudflare/jimmyostler/jsg-rs-fixes branch from 3dd6648 to 633583e Compare August 24, 2026 21:43
Comment thread src/rust/jsg/v8.rs

pub fn get(&self, index: usize) -> Local<'a, Value> {
debug_assert!(index <= self.len(), "index out of bounds");
debug_assert!(index < self.len(), "index out of bounds");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FunctionCallbackInfo::operator[] returns undefined for missing arguments, and the generated #[jsg_method] callbacks deliberately call args.get() for every declared parameter so omitted arguments can flow through FromJS. This debug-only assertion therefore panics for normal calls such as a zero-argument invocation of a two-parameter Rust method, while release builds accept the call. Preserve V8’s missing-argument behavior.

Suggested change
debug_assert!(index < self.len(), "index out of bounds");
// V8 returns undefined for missing callback arguments.

@ask-bonk

ask-bonk Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

PR #7107 corrects TypedArray casting and callback argument bounds.

  1. High: src/rust/jsg/v8.rs:3150 breaks missing callback arguments in debug builds. Posted one inline suggestion.

Validation could not run: Bazel lacks libc++ headers (cstring not found).

Time for a pun! That assertion was out of bounds.

github run

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