mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
node-api: add support for Float16Array
PR-URL: https://github.com/nodejs/node/pull/58879 Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
1 parent
7930d7a19b
commit
cb3f79273a
5 files changed
+21
-6
No files matched your search
@@ -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,
|
||||
@@ -2299,6 +2306,7 @@ typedef enum {
|
||||
napi_float64_array,
|
||||
napi_bigint64_array,
|
||||
napi_biguint64_array,
|
||||
napi_float16_array,
|
||||
} napi_typedarray_type;
|
||||
```
|
||||
|
||||
|
||||
@@ -133,6 +133,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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user