From 3b8f8083730973c00a9b1a76674bb117c6623467 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 7 Apr 2026 11:11:15 +0200 Subject: [PATCH 1/5] node-api: add napi_create_external_sharedarraybuffer Creates a SharedArrayBuffer from externally managed memory. Fixes: https://github.com/nodejs/node/issues/62259 --- doc/api/n-api.md | 37 +++++++++++++++++++ src/js_native_api.h | 9 +++++ src/js_native_api_v8.cc | 49 +++++++++++++++++++++++++ test/node-api/test_buffer/test.js | 10 +++++ test/node-api/test_buffer/test_buffer.c | 25 +++++++++++++ 5 files changed, 130 insertions(+) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 269492b480fd20..9d5be3a69d554d 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2575,6 +2575,43 @@ object just created has been garbage collected. JavaScript `ArrayBuffer`s are described in [Section ArrayBuffer objects][] of the ECMAScript Language Specification. +#### `napi_create_external_sharedarraybuffer` + + + +```c +napi_status +napi_create_external_sharedarraybuffer(napi_env env, + void* external_data, + size_t byte_length, + void (*finalize_cb)( + void* external_data, + void* finalize_hint), + void* finalize_hint, + napi_value* result) +``` + +* `[in] env`: The environment that the API is invoked under. +* `[in] external_data`: Pointer to the underlying byte buffer of the + `SharedArrayBuffer`. +* `[in] byte_length`: The length in bytes of the underlying buffer. +* `[in] finalize_cb`: Optional callback to call when the `SharedArrayBuffer` is + being collected. Because a `SharedArrayBuffer` can outlive the environment + it was created in, the callback does not get receive a reference to `env`. +* `[in] finalize_hint`: Optional hint to pass to the finalize callback during + collection. +* `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`. + +Returns `napi_ok` if the API succeeded. + +Create a `SharedArrayBuffer` with externally managed memory. + +See the entry on [`napi_create_external_arraybuffer`][] for runtime +compatibility. + #### `napi_create_external_buffer` From 5d2dd37cdbde4dff1135bfb08ddc0a2644b34922 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 7 Apr 2026 12:13:31 +0200 Subject: [PATCH 5/5] squash! more more lint --- doc/api/n-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 6062749e6fbf58..dcf426884b7d71 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2599,8 +2599,8 @@ napi_create_external_sharedarraybuffer(napi_env env, `SharedArrayBuffer`. * `[in] byte_length`: The length in bytes of the underlying buffer. * `[in] finalize_cb`: Optional callback to call when the `SharedArrayBuffer` is - being collected. Because a `SharedArrayBuffer` can outlive the environment - it was created in, the callback does not get receive a reference to `env`. + being collected. Because a `SharedArrayBuffer` can outlive the environment + it was created in, the callback does not get receive a reference to `env`. * `[in] finalize_hint`: Optional hint to pass to the finalize callback during collection. * `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`.