Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,13 @@ object such that no properties can be set on it, and no prototype.

#### `napi_typedarray_type`

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/58879
description: Added `napi_float16_array` for Float16Array support.
-->

```c
typedef enum {
napi_int8_array,
Expand All @@ -2299,6 +2306,7 @@ typedef enum {
napi_float64_array,
napi_bigint64_array,
napi_biguint64_array,
napi_float16_array,
} napi_typedarray_type;
```

Expand Down
2 changes: 2 additions & 0 deletions src/js_native_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ typedef enum {
napi_float64_array,
napi_bigint64_array,
napi_biguint64_array,
#define NODE_API_HAS_FLOAT16_ARRAY
napi_float16_array,
} napi_typedarray_type;

typedef enum {
Expand Down
6 changes: 6 additions & 0 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,10 @@ napi_status NAPI_CDECL napi_create_typedarray(napi_env env,
CREATE_TYPED_ARRAY(
env, BigUint64Array, 8, buffer, byte_offset, length, typedArray);
break;
case napi_float16_array:
CREATE_TYPED_ARRAY(
env, Float16Array, 2, buffer, byte_offset, length, typedArray);
break;
default:
return napi_set_last_error(env, napi_invalid_arg);
}
Expand Down Expand Up @@ -3297,6 +3301,8 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env,
*type = napi_int32_array;
} else if (value->IsUint32Array()) {
*type = napi_uint32_array;
} else if (value->IsFloat16Array()) {
*type = napi_float16_array;
} else if (value->IsFloat32Array()) {
*type = napi_float32_array;
} else if (value->IsFloat64Array()) {
Expand Down
6 changes: 3 additions & 3 deletions test/js-native-api/test_typedarray/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ assert.strictEqual(externalResult[2], 2);
// Validate creation of all kinds of TypedArrays
const buffer = new ArrayBuffer(128);
const arrayTypes = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array,
Uint16Array, Int32Array, Uint32Array, Float32Array,
Float64Array, BigInt64Array, BigUint64Array ];
Uint16Array, Int32Array, Uint32Array, Float16Array,
Float32Array, Float64Array, BigInt64Array, BigUint64Array ];

arrayTypes.forEach((currentType) => {
const template = Reflect.construct(currentType, buffer);
Expand All @@ -64,7 +64,7 @@ arrayTypes.forEach((currentType) => {
});

const nonByteArrayTypes = [ Int16Array, Uint16Array, Int32Array, Uint32Array,
Float32Array, Float64Array,
Float16Array, Float32Array, Float64Array,
BigInt64Array, BigUint64Array ];
nonByteArrayTypes.forEach((currentType) => {
const template = Reflect.construct(currentType, buffer);
Expand Down
5 changes: 2 additions & 3 deletions test/js-native-api/test_typedarray/test_typedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ static napi_value Multiply(napi_env env, napi_callback_info info) {
return output_array;
}

static void FinalizeCallback(napi_env env,
static void FinalizeCallback(node_api_basic_env env,
void* finalize_data,
void* finalize_hint)
{
void* finalize_hint) {
free(finalize_data);
}

Expand Down
Loading