-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
node-api: add napi_create_external_sharedarraybuffer #62623
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 all commits
3b8f808
6bc42e2
32fe154
5578c1a
5d2dd37
236ef28
a23c508
182151c
a021c17
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 |
|---|---|---|
|
|
@@ -437,6 +437,16 @@ napi_create_external_arraybuffer(napi_env env, | |
| node_api_basic_finalize finalize_cb, | ||
| void* finalize_hint, | ||
| napi_value* result); | ||
| #ifdef NAPI_EXPERIMENTAL | ||
| #define NODE_API_EXPERIMENTAL_HAS_CREATE_EXTERNAL_SHAREDARRAYBUFFER | ||
| NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_sharedarraybuffer( | ||
| napi_env env, | ||
| void* external_data, | ||
| size_t byte_length, | ||
| void (*finalize_cb)(void* external_data, void* finalize_hint), | ||
|
Member
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. We typically do not use the inline function pointer types.
Member
Author
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. I did that intentionally, of course. Passing nullptr is just setting up users for segfaults.
Member
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. I think the semantic of this finalizer is different from
Member
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. Then it would be better to define a new type alias for it. It is better to follow the established patterns.
Contributor
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. 👍 on dedicated type |
||
| void* finalize_hint, | ||
| napi_value* result); | ||
| #endif // NAPI_EXPERIMENTAL | ||
| #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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| { | ||
| "target_name": "test_buffer", | ||
| "defines": [ | ||
| 'NAPI_VERSION=10' | ||
| "NAPI_EXPERIMENTAL", | ||
| "NAPI_VERSION=10", | ||
|
Member
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. The |
||
| "NODE_API_EXPERIMENTAL_NO_WARNING" | ||
| ], | ||
| "sources": [ "test_buffer.c" ] | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,16 @@ const tick = require('util').promisify(require('../../common/tick')); | |||||||
| console.log('gc2'); | ||||||||
| assert.strictEqual(binding.getDeleterCallCount(), 2); | ||||||||
|
|
||||||||
| // Caveat emptor: it's indeterminate when the SharedArrayBuffer's backing | ||||||||
| // store is reclaimed; at least some of the time it happens even before | ||||||||
| // calling gc(). | ||||||||
| let sab = binding.newExternalSharedArrayBuffer(); | ||||||||
|
Member
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. Minor suggestion:
Suggested change
|
||||||||
| sab = null; // eslint-disable-line no-unused-vars | ||||||||
| global.gc(); | ||||||||
| await tick(10); | ||||||||
| console.log('gc3'); | ||||||||
| assert.strictEqual(binding.getDeleterCallCount(), 3); | ||||||||
bnoordhuis marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| // To test this doesn't crash | ||||||||
| binding.invalidObjectAsBuffer({}); | ||||||||
|
|
||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.