@@ -3293,6 +3293,10 @@ Specification.
32933293<!-- YAML
32943294added: v8.0.0
32953295napiVersion: 1
3296+ changes:
3297+ - version: REPLACEME
3298+ pr-url: https://github.com/nodejs/node/pull/59071
3299+ description: Added support for `SharedArrayBuffer`.
32963300-->
32973301
32983302```c
@@ -3303,21 +3307,20 @@ napi_status napi_get_arraybuffer_info(napi_env env,
33033307```
33043308
33053309* `[in] env`: The environment that the API is invoked under.
3306- * `[in] arraybuffer`: `napi_value` representing the `ArrayBuffer` being queried.
3307- * `[out] data`: The underlying data buffer of the `ArrayBuffer`. If byte\_length
3310+ * `[in] arraybuffer`: `napi_value` representing the `ArrayBuffer` or `SharedArrayBuffer` being queried.
3311+ * `[out] data`: The underlying data buffer of the `ArrayBuffer` or `SharedArrayBuffer`
33083312 is `0`, this may be `NULL` or any other pointer value.
33093313* `[out] byte_length`: Length in bytes of the underlying data buffer.
33103314
33113315Returns `napi_ok` if the API succeeded.
33123316
3313- This API is used to retrieve the underlying data buffer of an `ArrayBuffer` and
3314- its length.
3317+ This API is used to retrieve the underlying data buffer of an `ArrayBuffer` or `SharedArrayBuffer` and its length.
33153318
33163319_WARNING_: Use caution while using this API. The lifetime of the underlying data
3317- buffer is managed by the `ArrayBuffer` even after it's returned. A
3320+ buffer is managed by the `ArrayBuffer` or `SharedArrayBuffer` even after it's returned. A
33183321possible safe way to use this API is in conjunction with
33193322[`napi_create_reference`][], which can be used to guarantee control over the
3320- lifetime of the `ArrayBuffer`. It's also safe to use the returned data buffer
3323+ lifetime of the `ArrayBuffer` or `SharedArrayBuffer` . It's also safe to use the returned data buffer
33213324within the same callback as long as there are no calls to other APIs that might
33223325trigger a GC.
33233326
@@ -4272,6 +4275,63 @@ This API represents the invocation of the `ArrayBuffer` `IsDetachedBuffer`
42724275operation as defined in [Section isDetachedBuffer][] of the ECMAScript Language
42734276Specification.
42744277
4278+ ### `node_api_is_sharedarraybuffer`
4279+
4280+ <!-- YAML
4281+ added: REPLACEME
4282+ -->
4283+
4284+ > Stability: 1 - Experimental
4285+
4286+ ```c
4287+ napi_status node_api_is_sharedarraybuffer(napi_env env, napi_value value, bool* result)
4288+ ```
4289+
4290+ * `[in] env`: The environment that the API is invoked under.
4291+ * `[in] value`: The JavaScript value to check.
4292+ * `[out] result`: Whether the given `napi_value` represents a `SharedArrayBuffer`.
4293+
4294+ Returns `napi_ok` if the API succeeded.
4295+
4296+ This API checks if the Object passed in is a `SharedArrayBuffer`.
4297+
4298+ ### `node_api_create_sharedarraybuffer`
4299+
4300+ <!-- YAML
4301+ added: REPLACEME
4302+ -->
4303+
4304+ > Stability: 1 - Experimental
4305+
4306+ ```c
4307+ napi_status node_api_create_sharedarraybuffer(napi_env env,
4308+ size_t byte_length,
4309+ void** data,
4310+ napi_value* result)
4311+ ```
4312+
4313+ * `[in] env`: The environment that the API is invoked under.
4314+ * `[in] byte_length`: The length in bytes of the shared array buffer to create.
4315+ * `[out] data`: Pointer to the underlying byte buffer of the `SharedArrayBuffer`.
4316+ `data` can optionally be ignored by passing `NULL`.
4317+ * `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`.
4318+
4319+ Returns `napi_ok` if the API succeeded.
4320+
4321+ This API returns a Node-API value corresponding to a JavaScript `SharedArrayBuffer`.
4322+ `SharedArrayBuffer`s are used to represent fixed-length binary data buffers that
4323+ can be shared across multiple workers.
4324+
4325+ The `SharedArrayBuffer` allocated will have an underlying byte buffer whose size is
4326+ determined by the `byte_length` parameter that's passed in.
4327+ The underlying buffer is optionally returned back to the caller in case the
4328+ caller wants to directly manipulate the buffer. This buffer can only be
4329+ written to directly from native code. To write to this buffer from JavaScript,
4330+ a typed array or `DataView` object would need to be created.
4331+
4332+ JavaScript `SharedArrayBuffer` objects are described in
4333+ [Section SharedArrayBuffer objects][] of the ECMAScript Language Specification.
4334+
42754335## Working with JavaScript properties
42764336
42774337Node-API exposes a set of APIs to get and set properties on JavaScript
@@ -6785,6 +6845,7 @@ the add-on's file name during loading.
67856845[Section IsArray]: https://tc39.es/ecma262/#sec-isarray
67866846[Section IsStrctEqual]: https://tc39.es/ecma262/#sec-strict-equality-comparison
67876847[Section Promise objects]: https://tc39.es/ecma262/#sec-promise-objects
6848+ [Section SharedArrayBuffer objects]: https://tc39.es/ecma262/#sec-sharedarraybuffer-objects
67886849[Section ToBoolean]: https://tc39.es/ecma262/#sec-toboolean
67896850[Section ToNumber]: https://tc39.es/ecma262/#sec-tonumber
67906851[Section ToObject]: https://tc39.es/ecma262/#sec-toobject
0 commit comments