-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
node-api: handle no support for external buffers #45181
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
Changes from 1 commit
e29b2c0
9d67a66
ac56ab0
5ba9934
ebefb2b
a8038ac
e66382b
15a43d6
d3f0252
874cac1
981f9ae
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 |
---|---|---|
|
@@ -2362,6 +2362,19 @@ This API allocates a JavaScript value with external data attached to it. This | |
is used to pass external data through JavaScript code, so it can be retrieved | ||
later by native code using [`napi_get_value_external`][]. | ||
|
||
**Some runtimes other than Node.ja hasve dropped support for external buffers**. | ||
On runtimes other than Node.js this method may return | ||
`napi_no_external_buffers_allowed` to indicate that external | ||
buffers are not supported. One such runtime is electron as | ||
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. Should we spell Electron with an upper-case letter first? 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. Will update |
||
described in this issue | ||
[electron/issues/35801](https://github.com/electron/electron/issues/35801). | ||
|
||
In order to maintain broadest compatibility with all runtimes | ||
you may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before | ||
includes for the node-api headers. Doing so will hide the 2 methods | ||
mhdawson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
that create external buffers. This will ensure a compilation error | ||
occurs if you accidentally use one of these methods. | ||
|
||
The API adds a `napi_finalize` callback which will be called when the JavaScript | ||
object just created is ready for garbage collection. It is similar to | ||
`napi_wrap()` except that: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,12 +402,14 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_arraybuffer(napi_env env, | |
void** data, | ||
napi_value* result); | ||
NAPI_EXTERN napi_status NAPI_CDECL | ||
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED | ||
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. This line should be moved one line up, above the Maybe we should simply add a testing addon that defines 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. @legendecas thats a good idea, I had manually tested defining it, but I only checked that I got an error, not that would not get an error. I'll plan to add that. 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. @legendecas fixed and added to the two flavors of test_general |
||
napi_create_external_arraybuffer(napi_env env, | ||
void* external_data, | ||
size_t byte_length, | ||
napi_finalize finalize_cb, | ||
void* finalize_hint, | ||
napi_value* result); | ||
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED | ||
NAPI_EXTERN napi_status NAPI_CDECL napi_get_arraybuffer_info( | ||
napi_env env, napi_value arraybuffer, void** data, size_t* byte_length); | ||
NAPI_EXTERN napi_status NAPI_CDECL napi_is_typedarray(napi_env env, | ||
|
Uh oh!
There was an error while loading. Please reload this page.