-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
node-api: add support for Float16Array #58879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
3d5bf56
4bff794
5bdffbb
9559ac9
5ff4dd4
dc28ba5
cf84ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,9 @@ typedef enum { | |
napi_float64_array, | ||
napi_bigint64_array, | ||
napi_biguint64_array, | ||
#ifdef NAPI_EXPERIMENTAL | ||
napi_float16_array, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
#endif // NAPI_EXPERIMENTAL | ||
} napi_typedarray_type; | ||
|
||
typedef enum { | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the unit test is failing because the test
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the experimental guards will be removed, we would not need this define. |
||||
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); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in the 11 July Node-API meeting.
In the past, we have added two enum values to
napi_status
that were not behind experimental guards:napi_no_external_buffers_allowed
(ref) andnapi_cannot_run_js
(ref).I'm not sure this should be guarded by an
NAPI_EXPERIMENTAL
flag.Adding this under an experimental flag would mean that it is possible for
napi_get_typedarray_info
(which has no guard) can return an enum that I (if I do not defineNAPI_EXPERIMENTAL
) have no way of checking against.Does it make sense to have this under a guard?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KevinEady , I believe for the correct versioning support we must use the experimental flag.
While we did not provide the experimental guard for the status values, we always used to do it for other enum types.
E.g. see the property attributes:
node/src/js_native_api_types.h
Lines 73 to 80 in a472745
It is important that Node-API keeps a good versioning story and the ABI stability.
For the same reason the
napi_get_typedarray_info
behavior must be properly guarded.E.g. today before this PR, the
napi_get_typedarray_info
has certain behavior and returns values that does not include the Float16 array type. We must ensure that this behavior is kept unchanged unless developers vote to use the newer API version where the behavior is changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should distinguish enum values used in in-parameters and out-parameters.
Unlike
napi_property_attributes
,napi_typedarray_type
is used as an out-parameter innapi_get_typedarray_info
. An addon should expect that JavaScript can introduce new typed array types, and it is inevitable to receive a new typed array as a parameter.I think guarding
napi_get_typedarray_info
does not make sense. What error should an addon expect whennapi_is_typedarray
returns true, butnapi_get_typedarray_info
rejects it? In general, an addon should expect unknown enum (integer) values being returned from Node-API functions, and handles them (like, throwing an error).I filed #59085 to discuss the ABI guarantee on enum values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After codifying our rules for enums and ABI stability in #59085 , the version guard should be removed.