Skip to content

Conversation

@Renegade334
Copy link
Contributor

SharedArrayBuffers are finding more and more use in core, but the flag-dependent exposure of the constructor is a permanent issue. In the common case where the constructor is available, the global is potentially user-mutable depending on when it's accessed, and in the case where the constructor isn't available, this either results in deliberately lost functionality or just straight runtime errors.

The approach here adds a utility binding to construct SABs via the V8 API, which is ubiquitously available independent of the flag state.

An alternative approach would be to use the JS global if present, and only call into C++ if absent. In reality, this method is vanishingly unlikely to ever be needed in a hot path, so the call cost isn't as much of a consideration, and using the API adds the primordial-esque safety factor.

Would supersede #60453. Does not land on v20.x or v22.x, as MaybeNew was added in V8 13.1.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Oct 30, 2025
@Renegade334 Renegade334 force-pushed the bound-sharedarraybuffer-construct branch from 2705b57 to 83074c3 Compare October 30, 2025 16:58
@aduh95 aduh95 added dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. labels Oct 30, 2025
@aduh95 aduh95 requested a review from codebytere October 30, 2025 17:49
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 90.74074% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.57%. Comparing base (bdf03bf) to head (83074c3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/node_util.cc 73.68% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60497      +/-   ##
==========================================
+ Coverage   88.05%   88.57%   +0.51%     
==========================================
  Files         704      704              
  Lines      207857   207872      +15     
  Branches    39964    40048      +84     
==========================================
+ Hits       183030   184123    +1093     
+ Misses      16806    15771    -1035     
+ Partials     8021     7978      -43     
Files with missing lines Coverage Δ
lib/internal/main/worker_thread.js 94.35% <100.00%> (-0.10%) ⬇️
lib/internal/modules/esm/hooks.js 91.85% <100.00%> (-0.04%) ⬇️
lib/internal/streams/fast-utf8-stream.js 74.23% <100.00%> (+0.02%) ⬆️
lib/internal/util.js 96.37% <100.00%> (+0.69%) ⬆️
lib/internal/worker.js 96.52% <100.00%> (+<0.01%) ⬆️
lib/internal/worker/messaging.js 100.00% <100.00%> (ø)
src/node_util.cc 80.00% <73.68%> (-0.38%) ⬇️

... and 95 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.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 30, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 30, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

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. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants