GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node-api: run finalizers directly from GC · nodejs/node@5148f03

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • n-api.md
  • src
    • js_native_api.h
    • js_native_api_v8.cc
    • js_native_api_v8.h
    • js_native_api_v8_internals.h
    • node_api.cc
  • test/js-native-api/test_finalizer
    • binding.gyp
    • test.js
    • test_fatal_finalize.js
    • test_finalizer.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+36Lines changed: 36 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -5420,6 +5420,42 @@ invocation. If it is deleted before then, then the finalize callback may never
54205420
be invoked. Therefore, when obtaining a reference a finalize callback is also
54215421
required in order to enable correct disposal of the reference.
54225422

5423+
#### `node_api_post_finalizer`
5424+
5425+
<!-- YAML
5426+
added: REPLACEME
5427+
-->
5428+
5429+
> Stability: 1 - Experimental
5430+
5431+
```c
5432+
napi_status node_api_post_finalizer(napi_env env,
5433+
napi_finalize finalize_cb,
5434+
void* finalize_data,
5435+
void* finalize_hint);
5436+
```
5437+
5438+
* `[in] env`: The environment that the API is invoked under.
5439+
* `[in] finalize_cb`: Native callback that will be used to free the
5440+
native data when the JavaScript object has been garbage-collected.
5441+
[`napi_finalize`][] provides more details.
5442+
* `[in] finalize_data`: Optional data to be passed to `finalize_cb`.
5443+
* `[in] finalize_hint`: Optional contextual hint that is passed to the
5444+
finalize callback.
5445+
5446+
Returns `napi_ok` if the API succeeded.
5447+
5448+
Schedules a `napi_finalize` callback to be called asynchronously in the
5449+
event loop.
5450+
5451+
Normally, finalizers are called while the GC (garbage collector) collects
5452+
objects. At that point calling any Node-API that may cause changes in the GC
5453+
state will be disabled and will crash Node.js.
5454+
5455+
`node_api_post_finalizer` helps to work around this limitation by allowing the
5456+
add-on to defer calls to such Node-APIs to a point in time outside of the GC
5457+
finalization.
5458+
54235459
## Simple asynchronous operations
54245460

54255461
Addon modules often need to leverage async helpers from libuv as part of their
Collapse file

‎src/js_native_api.h‎

Copy file name to clipboardExpand all lines: src/js_native_api.h
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,16 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env,
517517

518518
#endif // NAPI_VERSION >= 5
519519

520+
#ifdef NAPI_EXPERIMENTAL
521+
522+
NAPI_EXTERN napi_status NAPI_CDECL
523+
node_api_post_finalizer(napi_env env,
524+
napi_finalize finalize_cb,
525+
void* finalize_data,
526+
void* finalize_hint);
527+
528+
#endif // NAPI_EXPERIMENTAL
529+
520530
#if NAPI_VERSION >= 6
521531

522532
// BigInt

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.