Skip to content

Conversation

@KevinEady
Copy link
Contributor

The previous implementation does not support calling napi_create_dataview with a SharedArrayBuffer, as the check for value->IsArrayBuffer() returns false, causing the Node-API call to return an napi_invalid_arg.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/node-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. labels Oct 28, 2025
@KevinEady KevinEady force-pushed the node-api-add-sharedarraybuffer-to-dataview branch from f2b1f83 to 68ea53e Compare October 28, 2025 23:35
@KevinEady KevinEady marked this pull request as ready for review October 28, 2025 23:36
@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.56%. Comparing base (4e9e5a1) to head (7b1f34e).
⚠️ Report is 148 commits behind head on main.

Files with missing lines Patch % Lines
src/js_native_api_v8.cc 70.58% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #60473   +/-   ##
=======================================
  Coverage   88.56%   88.56%           
=======================================
  Files         704      704           
  Lines      207826   207864   +38     
  Branches    40035    40052   +17     
=======================================
+ Hits       184059   184094   +35     
- Misses      15802    15806    +4     
+ Partials     7965     7964    -1     
Files with missing lines Coverage Δ
src/js_native_api_v8.cc 76.56% <70.58%> (+0.06%) ⬆️

... and 33 files with indirect coverage changes

🚀 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.

Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@KevinEady
Copy link
Contributor Author

I do not think we add macro definitions for changes in behavior (eg. no NODE_API_DATAVIEW_SUPPORTS_SHAREDARRAYBUFFER) ? If this is the case, node-addon-api will not know at compile-time whether the Node.js version used to build the addon supports SharedArrayBuffer with napi_create_dataview.

I see three paths to introduce this to node-addon-api:

  1. Catch the invalid_arg status, and do the c++ equivalent of new DataView( buffer, byteOffset, byteLength ).
  2. Return any non-ok status and do not do anything special.
  3. Introduce a macro definition in this PR that node-addon-api can recognize.

Thoughts? Or any other ideas?

@legendecas
Copy link
Member

We can use NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER to indicate if shared array buffer support is complete. #59071 updated napi_get_arraybuffer_info to allow shared array buffer as well. So when NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER is available, we can also say napi_get_arraybuffer_info supports shared array buffers.

As for the API changed in this PR, given that the support is still experimental, and #59071 was just released one (or two) minor versions ago, I think it is fine to reuse NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER, unless we want to track experiments more precisely.

@legendecas legendecas moved this from Need Triage to In Progress in Node-API Team Project Nov 7, 2025
@legendecas legendecas added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Nov 11, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 11, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 13, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 13, 2025
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/60473
✔  Done loading data for nodejs/node/pull/60473
----------------------------------- PR info ------------------------------------
Title      node-api: support SharedArrayBuffer in napi_create_dataview (#60473)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     KevinEady:node-api-add-sharedarraybuffer-to-dataview -> nodejs:main
Labels     c++, node-api, author ready, needs-ci
Commits    2
 - node-api: support SharedArrayBuffer in napi_create_dataview
 - fixup! do not use Reflect in tests
Committers 2
 - Kevin Eady <8634912+KevinEady@users.noreply.github.com>
 - GitHub <noreply@github.com>
PR-URL: https://github.com/nodejs/node/pull/60473
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/60473
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 28 Oct 2025 23:27:04 GMT
   ✔  Approvals: 3
   ✔  - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/60473#pullrequestreview-3393828075
   ✔  - Chengzhong Wu (@legendecas) (TSC): https://github.com/nodejs/node/pull/60473#pullrequestreview-3450380435
   ✔  - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/60473#pullrequestreview-3461701322
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2025-11-12T10:21:00Z: https://ci.nodejs.org/job/node-test-pull-request/70148/
- Querying data for job/node-test-pull-request/70148/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 60473
From https://github.com/nodejs/node
 * branch                  refs/pull/60473/merge -> FETCH_HEAD
✔  Fetched commits as da71ab689518..7b1f34e2f929
--------------------------------------------------------------------------------
Auto-merging doc/api/n-api.md
Auto-merging src/js_native_api_v8.cc
[main 526901a334] node-api: support SharedArrayBuffer in napi_create_dataview
 Author: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
 Date: Wed Oct 29 00:18:58 2025 +0100
 5 files changed, 70 insertions(+), 23 deletions(-)
[main bf57822ea5] fixup! do not use Reflect in tests
 Author: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
 Date: Fri Oct 31 10:46:26 2025 +0100
 1 file changed, 1 insertion(+), 1 deletion(-)
   ✔  Patches applied
There are 2 commits in the PR. Attempting autorebase.
(node:2200) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
node-api: support SharedArrayBuffer in napi_create_dataview

PR-URL: #60473
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>

[detached HEAD 575b8a783a] node-api: support SharedArrayBuffer in napi_create_dataview
Author: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
Date: Wed Oct 29 00:18:58 2025 +0100
5 files changed, 70 insertions(+), 23 deletions(-)
Rebasing (3/4)
Rebasing (4/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! do not use Reflect in tests

Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: #60473
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>

[detached HEAD 2b5c74b4ff] fixup! do not use Reflect in tests
Author: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
Date: Fri Oct 31 10:46:26 2025 +0100
1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/19346144521

@addaleax addaleax added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Nov 13, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 13, 2025
@nodejs-github-bot nodejs-github-bot merged commit 9cbf4c9 into nodejs:main Nov 13, 2025
82 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 9cbf4c9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API.

Projects

Development

Successfully merging this pull request may close these issues.

5 participants