@@ -1339,7 +1339,21 @@ class TypedArray : public Object {
13391339
13401340 napi_typedarray_type TypedArrayType ()
13411341 const ; // /< Gets the type of this typed-array.
1342- Napi::ArrayBuffer ArrayBuffer () const ; // /< Gets the backing array buffer.
1342+
1343+ // Gets the backing `ArrayBuffer`.
1344+ //
1345+ // If this `TypedArray` is not backed by an `ArrayBuffer`, this method will
1346+ // terminate the process with a fatal error when using
1347+ // `NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` or exhibit undefined behavior
1348+ // otherwise. Use `Buffer()` instead to get the backing buffer without
1349+ // assuming its type.
1350+ Napi::ArrayBuffer ArrayBuffer () const ;
1351+
1352+ // Gets the backing buffer (an `ArrayBuffer` or `SharedArrayBuffer`).
1353+ //
1354+ // Use `IsArrayBuffer()` or `IsSharedArrayBuffer()` to check the type of the
1355+ // backing buffer prior to casting with `As<T>()`.
1356+ Napi::Value Buffer () const ;
13431357
13441358 uint8_t ElementSize ()
13451359 const ; // /< Gets the size in bytes of one element in the array.
@@ -1433,6 +1447,32 @@ class TypedArrayOf : public TypedArray {
14331447 // /< template parameter T.
14341448 );
14351449
1450+ #ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
1451+ // / Creates a new TypedArray instance over a provided SharedArrayBuffer.
1452+ // /
1453+ // / The array type parameter can normally be omitted (because it is inferred
1454+ // / from the template parameter T), except when creating a "clamped" array:
1455+ // /
1456+ // / Uint8Array::New(env, length, buffer, 0, napi_uint8_clamped_array)
1457+ static TypedArrayOf New (
1458+ napi_env env, // /< Node-API environment
1459+ size_t elementLength, // /< Length of the created array, as a number of
1460+ // /< elements
1461+ Napi::SharedArrayBuffer
1462+ arrayBuffer, // /< Backing shared array buffer instance to use
1463+ size_t bufferOffset, // /< Offset into the array buffer where the
1464+ // /< typed-array starts
1465+ #if defined(NAPI_HAS_CONSTEXPR)
1466+ napi_typedarray_type type =
1467+ TypedArray::TypedArrayTypeForPrimitiveType<T>()
1468+ #else
1469+ napi_typedarray_type type
1470+ #endif
1471+ // /< Type of array, if different from the default array type for the
1472+ // /< template parameter T.
1473+ );
1474+ #endif
1475+
14361476 static void CheckCast (napi_env env, napi_value value);
14371477
14381478 TypedArrayOf (); // /< Creates a new _empty_ TypedArrayOf instance.
0 commit comments