fix(napi): validate status before copying in TypedArray owned ToNapiValue fallback#3080
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-11-25T09:31:23.877ZApplied to files:
📚 Learning: 2025-11-25T09:31:23.877ZApplied to files:
🧬 Code graph analysis (1)crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
🔇 Additional comments (1)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the error handling logic in the ToNapiValue implementation for typed arrays. The changes restructure the control flow for creating array buffers, separating the status checks into explicit branches rather than nesting them within a single check_status! macro call.
- Extracts the zero-length buffer case into its own block with immediate error checking
- Explicitly stores and checks the status from
napi_create_external_arraybufferusing a mutable variable - Separates error handling for the fallback path when external buffers are not allowed
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
13f1fe1 to
512153f
Compare
9eb1cc0 to
4cc80d3
Compare
512153f to
72668eb
Compare
4cc80d3 to
55a51d1
Compare
72668eb to
9945379
Compare
e48088b to
3d92833
Compare
9945379 to
6752c3e
Compare
Merge activity
|
…alue fallback (#3080) <!-- CURSOR_SUMMARY --> > [!NOTE] > Strengthens `TypedArray` owned `ToNapiValue` path by tightening ArrayBuffer creation and fallback handling. > > - Refactors `TypedArray::<T>::to_napi_value` to explicitly handle zero-length buffers via `napi_create_arraybuffer` > - Validates `napi_create_external_arraybuffer` status and only falls back to `napi_create_arraybuffer` with data copy when `napi_no_external_buffers_allowed` > - Ensures `check_status!` occurs before copying and only copies when `length > 0`; improves error messages for failures > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3d92833. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
3d92833 to
6ac1d6b
Compare

Note
Strengthens
TypedArrayownedToNapiValuepath by tightening ArrayBuffer creation and fallback handling.TypedArray::<T>::to_napi_valueto explicitly handle zero-length buffers vianapi_create_arraybuffernapi_create_external_arraybufferstatus and only falls back tonapi_create_arraybufferwith data copy whennapi_no_external_buffers_allowedcheck_status!occurs before copying and only copies whenlength > 0; improves error messages for failuresWritten by Cursor Bugbot for commit 3d92833. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.