node-api: add support for Float16Array · nodejs/node@36ce6d6 · GitHub
Skip to content

Commit 36ce6d6

Browse files
IlyasShabiaduh95
authored andcommitted
node-api: add support for Float16Array
PR-URL: #58879 Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 2d5f20e commit 36ce6d6

5 files changed

Lines changed: 21 additions & 6 deletions

File tree

doc/api/n-api.md

Lines changed: 8 additions & 0 deletions

src/js_native_api_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ typedef enum {
121121
napi_float64_array,
122122
napi_bigint64_array,
123123
napi_biguint64_array,
124+
#define NODE_API_HAS_FLOAT16_ARRAY
125+
napi_float16_array,
124126
} napi_typedarray_type;
125127

126128
typedef enum {

src/js_native_api_v8.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,10 @@ napi_status NAPI_CDECL napi_create_typedarray(napi_env env,
32593259
CREATE_TYPED_ARRAY(
32603260
env, BigUint64Array, 8, buffer, byte_offset, length, typedArray);
32613261
break;
3262+
case napi_float16_array:
3263+
CREATE_TYPED_ARRAY(
3264+
env, Float16Array, 2, buffer, byte_offset, length, typedArray);
3265+
break;
32623266
default:
32633267
return napi_set_last_error(env, napi_invalid_arg);
32643268
}
@@ -3297,6 +3301,8 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env,
32973301
*type = napi_int32_array;
32983302
} else if (value->IsUint32Array()) {
32993303
*type = napi_uint32_array;
3304+
} else if (value->IsFloat16Array()) {
3305+
*type = napi_float16_array;
33003306
} else if (value->IsFloat32Array()) {
33013307
*type = napi_float32_array;
33023308
} else if (value->IsFloat64Array()) {

test/js-native-api/test_typedarray/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ assert.strictEqual(externalResult[2], 2);
4141
// Validate creation of all kinds of TypedArrays
4242
const buffer = new ArrayBuffer(128);
4343
const arrayTypes = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array,
44-
Uint16Array, Int32Array, Uint32Array, Float32Array,
45-
Float64Array, BigInt64Array, BigUint64Array ];
44+
Uint16Array, Int32Array, Uint32Array, Float16Array,
45+
Float32Array, Float64Array, BigInt64Array, BigUint64Array ];
4646

4747
arrayTypes.forEach((currentType) => {
4848
const template = Reflect.construct(currentType, buffer);
@@ -64,7 +64,7 @@ arrayTypes.forEach((currentType) => {
6464
});
6565

6666
const nonByteArrayTypes = [ Int16Array, Uint16Array, Int32Array, Uint32Array,
67-
Float32Array, Float64Array,
67+
Float16Array, Float32Array, Float64Array,
6868
BigInt64Array, BigUint64Array ];
6969
nonByteArrayTypes.forEach((currentType) => {
7070
const template = Reflect.construct(currentType, buffer);

test/js-native-api/test_typedarray/test_typedarray.c

Lines changed: 2 additions & 3 deletions

0 commit comments

Comments
 (0)