@@ -3299,6 +3299,10 @@ Specification.
32993299<!-- YAML
33003300added: v8.0.0
33013301napiVersion: 1
3302+ changes:
3303+ - version: REPLACEME
3304+ pr-url: https://github.com/nodejs/node/pull/59071
3305+ description: Added support for `SharedArrayBuffer`.
33023306-->
33033307
33043308```c
@@ -3309,21 +3313,20 @@ napi_status napi_get_arraybuffer_info(napi_env env,
33093313```
33103314
33113315* `[in] env`: The environment that the API is invoked under.
3312- * `[in] arraybuffer`: `napi_value` representing the `ArrayBuffer` being queried.
3313- * `[out] data`: The underlying data buffer of the `ArrayBuffer`. If byte\_length
3316+ * `[in] arraybuffer`: `napi_value` representing the `ArrayBuffer` or `SharedArrayBuffer` being queried.
3317+ * `[out] data`: The underlying data buffer of the `ArrayBuffer` or `SharedArrayBuffer`
33143318 is `0`, this may be `NULL` or any other pointer value.
33153319* `[out] byte_length`: Length in bytes of the underlying data buffer.
33163320
33173321Returns `napi_ok` if the API succeeded.
33183322
3319- This API is used to retrieve the underlying data buffer of an `ArrayBuffer` and
3320- its length.
3323+ This API is used to retrieve the underlying data buffer of an `ArrayBuffer` or `SharedArrayBuffer` and its length.
33213324
33223325_WARNING_: Use caution while using this API. The lifetime of the underlying data
3323- buffer is managed by the `ArrayBuffer` even after it's returned. A
3326+ buffer is managed by the `ArrayBuffer` or `SharedArrayBuffer` even after it's returned. A
33243327possible safe way to use this API is in conjunction with
33253328[`napi_create_reference`][], which can be used to guarantee control over the
3326- lifetime of the `ArrayBuffer`. It's also safe to use the returned data buffer
3329+ lifetime of the `ArrayBuffer` or `SharedArrayBuffer` . It's also safe to use the returned data buffer
33273330within the same callback as long as there are no calls to other APIs that might
33283331trigger a GC.
33293332
@@ -4278,6 +4281,63 @@ This API represents the invocation of the `ArrayBuffer` `IsDetachedBuffer`
42784281operation as defined in [Section isDetachedBuffer][] of the ECMAScript Language
42794282Specification.
42804283
4284+ ### `node_api_is_sharedarraybuffer`
4285+
4286+ <!-- YAML
4287+ added: REPLACEME
4288+ -->
4289+
4290+ > Stability: 1 - Experimental
4291+
4292+ ```c
4293+ napi_status node_api_is_sharedarraybuffer(napi_env env, napi_value value, bool* result)
4294+ ```
4295+
4296+ * `[in] env`: The environment that the API is invoked under.
4297+ * `[in] value`: The JavaScript value to check.
4298+ * `[out] result`: Whether the given `napi_value` represents a `SharedArrayBuffer`.
4299+
4300+ Returns `napi_ok` if the API succeeded.
4301+
4302+ This API checks if the Object passed in is a `SharedArrayBuffer`.
4303+
4304+ ### `node_api_create_sharedarraybuffer`
4305+
4306+ <!-- YAML
4307+ added: REPLACEME
4308+ -->
4309+
4310+ > Stability: 1 - Experimental
4311+
4312+ ```c
4313+ napi_status node_api_create_sharedarraybuffer(napi_env env,
4314+ size_t byte_length,
4315+ void** data,
4316+ napi_value* result)
4317+ ```
4318+
4319+ * `[in] env`: The environment that the API is invoked under.
4320+ * `[in] byte_length`: The length in bytes of the shared array buffer to create.
4321+ * `[out] data`: Pointer to the underlying byte buffer of the `SharedArrayBuffer`.
4322+ `data` can optionally be ignored by passing `NULL`.
4323+ * `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`.
4324+
4325+ Returns `napi_ok` if the API succeeded.
4326+
4327+ This API returns a Node-API value corresponding to a JavaScript `SharedArrayBuffer`.
4328+ `SharedArrayBuffer`s are used to represent fixed-length binary data buffers that
4329+ can be shared across multiple workers.
4330+
4331+ The `SharedArrayBuffer` allocated will have an underlying byte buffer whose size is
4332+ determined by the `byte_length` parameter that's passed in.
4333+ The underlying buffer is optionally returned back to the caller in case the
4334+ caller wants to directly manipulate the buffer. This buffer can only be
4335+ written to directly from native code. To write to this buffer from JavaScript,
4336+ a typed array or `DataView` object would need to be created.
4337+
4338+ JavaScript `SharedArrayBuffer` objects are described in
4339+ [Section SharedArrayBuffer objects][] of the ECMAScript Language Specification.
4340+
42814341## Working with JavaScript properties
42824342
42834343Node-API exposes a set of APIs to get and set properties on JavaScript
@@ -6791,6 +6851,7 @@ the add-on's file name during loading.
67916851[Section IsArray]: https://tc39.es/ecma262/#sec-isarray
67926852[Section IsStrctEqual]: https://tc39.es/ecma262/#sec-strict-equality-comparison
67936853[Section Promise objects]: https://tc39.es/ecma262/#sec-promise-objects
6854+ [Section SharedArrayBuffer objects]: https://tc39.es/ecma262/#sec-sharedarraybuffer-objects
67946855[Section ToBoolean]: https://tc39.es/ecma262/#sec-toboolean
67956856[Section ToNumber]: https://tc39.es/ecma262/#sec-tonumber
67966857[Section ToObject]: https://tc39.es/ecma262/#sec-toobject
0 commit comments