There was an error while loading. Please reload this page.
1 parent 7930d7a commit cb3f792Copy full SHA for cb3f792
5 files changed
doc/api/n-api.md
@@ -2286,6 +2286,13 @@ object such that no properties can be set on it, and no prototype.
2286
2287
#### `napi_typedarray_type`
2288
2289
+<!-- YAML
2290
+changes:
2291
+ - version: REPLACEME
2292
+ pr-url: https://github.com/nodejs/node/pull/58879
2293
+ description: Added `napi_float16_array` for Float16Array support.
2294
+-->
2295
+
2296
```c
2297
typedef enum {
2298
napi_int8_array,
@@ -2299,6 +2306,7 @@ typedef enum {
2299
2306
napi_float64_array,
2300
2307
napi_bigint64_array,
2301
2308
napi_biguint64_array,
2309
+ napi_float16_array,
2302
2310
} napi_typedarray_type;
2303
2311
```
2304
2312
src/js_native_api_types.h
@@ -133,6 +133,8 @@ typedef enum {
133
134
135
136
+#define NODE_API_HAS_FLOAT16_ARRAY
137
+napi_float16_array,
138
139
140
typedefenum {
src/js_native_api_v8.cc
@@ -3259,6 +3259,10 @@ napi_status NAPI_CDECL napi_create_typedarray(napi_env env,
3259
CREATE_TYPED_ARRAY(
3260
env, BigUint64Array, 8, buffer, byte_offset, length, typedArray);
3261
break;
3262
+case napi_float16_array:
3263
+CREATE_TYPED_ARRAY(
3264
+ env, Float16Array, 2, buffer, byte_offset, length, typedArray);
3265
+break;
3266
default:
3267
returnnapi_set_last_error(env, napi_invalid_arg);
3268
}
@@ -3297,6 +3301,8 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env,
3297
3301
*type = napi_int32_array;
3298
3302
} elseif (value->IsUint32Array()) {
3299
3303
*type = napi_uint32_array;
3304
+ } elseif (value->IsFloat16Array()) {
3305
+ *type = napi_float16_array;
3300
3306
} elseif (value->IsFloat32Array()) {
3307
*type = napi_float32_array;
3308
} elseif (value->IsFloat64Array()) {
test/js-native-api/test_typedarray/test.js
@@ -41,8 +41,8 @@ assert.strictEqual(externalResult[2], 2);
41
// Validate creation of all kinds of TypedArrays
42
constbuffer=newArrayBuffer(128);
43
constarrayTypes=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,
44
-Uint16Array,Int32Array,Uint32Array,Float32Array,
45
-Float64Array,BigInt64Array,BigUint64Array];
+Uint16Array,Int32Array,Uint32Array,Float16Array,
+Float32Array,Float64Array,BigInt64Array,BigUint64Array];
46
47
arrayTypes.forEach((currentType)=>{
48
consttemplate=Reflect.construct(currentType,buffer);
@@ -64,7 +64,7 @@ arrayTypes.forEach((currentType) => {
64
});
65
66
constnonByteArrayTypes=[Int16Array,Uint16Array,Int32Array,Uint32Array,
67
-Float32Array,Float64Array,
+Float16Array,Float32Array,Float64Array,
68
BigInt64Array,BigUint64Array];
69
nonByteArrayTypes.forEach((currentType)=>{
70
test/js-native-api/test_typedarray/test_typedarray.c
@@ -75,10 +75,9 @@ static napi_value Multiply(napi_env env, napi_callback_info info) {
75
returnoutput_array;
76
77
78
-staticvoidFinalizeCallback(napi_envenv,
+staticvoidFinalizeCallback(node_api_basic_envenv,
79
void*finalize_data,
80
-void*finalize_hint)
81
-{
+void*finalize_hint) {
82
free(finalize_data);
83
84
0 commit comments