Vladimir Morozov
179162fe42
node-api: use Node-API in comments
...
PR-URL: https://github.com/nodejs/node/pull/61320
Reviewed-By: Aviv Keller <me@aviv.sh >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2026-01-27 22:52:26 +01:00
Mika Fischer and Gabriel Schulhof
1e13e84f16
node-api: fix data race and use-after-free in napi_threadsafe_function
...
Other threads can still hold a valid handle to the tsfn after
finalization if finalization was triggered by
- release with napi_tsfn_abort, or
- environment shutdown
Handle this by:
- protecting finalization itself with the mutex
- if necessary, delay deletion after finalization to when thread_count
drops to 0
- releasing all resources as soon as possible before deletion
Fixes: https://github.com/nodejs/node/issues/55706
PR-URL: https://github.com/nodejs/node/pull/55877
Co-Authored-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2026-01-19 19:19:13 +01:00
Chengzhong Wu
02fb7f4ecb
src: remove unconditional NAPI_EXPERIMENTAL in node.h
...
PR-URL: https://github.com/nodejs/node/pull/60345
Fixes: https://github.com/nodejs/node/issues/60311
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
2025-11-13 22:44:14 +01:00
Anna Henningsen
463c6450cf
src: use Utf8Value and TwoByteValue instead of V8 helpers
...
Our own helper classes have the advantage of using stack storage
a lot of the time, so they should always be preferred.
PR-URL: https://github.com/nodejs/node/pull/60244
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
2025-11-07 18:11:31 +01:00
Shelley Vohr
ba661459f5
src: fix -Wunreachable-code in src/node_api.cc
...
PR-URL: https://github.com/nodejs/node/pull/58901
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
2025-07-08 11:16:17 -03:00
Eusgor
11e4cd698b
src: fix possible dereference of null pointer
...
There is a CHECK_NOT_NULL check before dereferencing node_env on
line 710 in the "if" block, but there is no CHECK_NOT_NULL check before
dereferencing node_env on line 721. Maybe it makes sense to put
CHECK_NOT_NULL right after calling the Environment::GetCurrent function.
PR-URL: https://github.com/nodejs/node/pull/58459
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-05-31 15:02:41 +02:00
James M Snell
08615b1020
src: prepare for v8 sandboxing
...
PR-URL: https://github.com/nodejs/node/pull/58376
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-05-31 13:30:50 +02:00
Vladimir Morozov
b4f6aa8a87
node-api: convert NewEnv to node_napi_env__::New
...
PR-URL: https://github.com/nodejs/node/pull/57834
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2025-05-02 17:06:33 -03:00
Gabriel Schulhof
c5aa8b8ef1
node-api: define version 10
...
Notable runtime changes to existing APIs:
- returning `node_api_cannot_run_js` instead of
`napi_pending_exception`.
- allow creating references to objects, functions, and symbols.
PR-URL: https://github.com/nodejs/node/pull/55676
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-12-31 16:29:50 +00:00
Mert Can Altin
fdf838aee6
node-api: add napi_create_buffer_from_arraybuffer method
...
PR-URL: https://github.com/nodejs/node/pull/54505
Fixes: https://github.com/nodejs/node/issues/54440
Reviewed-By: Robert Nagy <ronagy@icloud.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
2024-10-11 15:21:57 +00:00
Vladimir Morozov
431ac161e6
node-api: remove RefBase and CallbackWrapper
...
PR-URL: https://github.com/nodejs/node/pull/53590
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2024-08-27 09:30:19 +00:00
Stephen Belanger
d1229eeca4
lib: rewrite AsyncLocalStorage without async_hooks
...
PR-URL: https://github.com/nodejs/node/pull/48528
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
2024-08-02 19:44:20 +00:00
Gabriel Schulhof
2d1b4a8cf7
node-api: rename nogc to basic
...
Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/53830
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2024-07-26 09:25:02 -07:00
Gabriel Schulhof
f0e6acde2d
node-api: make tsfn accept napi_finalize once more
...
The thread-safe function's finalizer is not called in conjunction with
the garbage collection of a JS value. In fact, it keeps a strong
reference to the JS function it is expected to call. Thus, it is safe
to make calls that affect GC state from its body.
PR-URL: https://github.com/nodejs/node/pull/51801
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2024-03-09 05:58:42 +00:00
Janrupf
281c342717
node-api: make napi_get_buffer_info check if passed buffer is valid
...
PR-URL: https://github.com/nodejs/node/pull/51571
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2024-02-23 16:50:07 +00:00
Gabriel Schulhof
7a216d5fd6
node-api: segregate nogc APIs from rest via type system
...
We define a new type called `node_api_nogc_env` as the `const` version
of `napi_env` and `node_api_nogc_finalize` as a variant of
`napi_finalize` that accepts a `node_api_nogc_env` as its first
argument.
We then modify those APIs which do not affect GC state as accepting a
`node_api_nogc_env`. APIs accepting finalizer callbacks are modified to
accept `node_api_nogc_finalize` callbacks. Thus, the only way to attach
a `napi_finalize` callback, wherein Node-APIs affecting GC state may be
called is to call `node_api_post_finalizer` from a
`node_api_nogc_finalize` callback.
In keeping with the process of introducing new Node-APIs, this feature
is guarded by `NAPI_EXPERIMENTAL`. Since this feature modifies APIs
already marked as stable, it is additionally guared by
`NODE_API_EXPERIMENTAL_NOGC_ENV`, so as to provide a further buffer to
adoption. Nevertheless, both guards must be removed upon releasing a
new version of Node-API.
PR-URL: https://github.com/nodejs/node/pull/50060
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2023-12-19 07:37:15 +00:00
Gabriel Schulhof
5e250bd726
node-api: factor out common code into macros
...
* Create macro for checking new string arguments.
* Create macro for combining env check and inside-gc check.
PR-URL: https://github.com/nodejs/node/pull/50664
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-11-12 23:05:04 +00:00
Vladimir Morozov
b38e312486
node-api: run finalizers directly from GC
...
PR-URL: https://github.com/nodejs/node/pull/42651
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2023-10-03 10:06:01 -04:00
Chengzhong Wu
77597d3aea
node-api: enable uncaught exceptions policy by default
...
This enables the option `--force-node-api-uncaught-exceptions-policy`
for a specific Node-API addon when it is compiled with
`NAPI_EXPERIMENTAL` (and this would be the default behavior when
`NAPI_VERSION` 10 releases). This would not break existing Node-API
addons.
PR-URL: https://github.com/nodejs/node/pull/49313
Refs: https://github.com/nodejs/node/pull/36510
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
2023-09-25 04:23:58 +00:00
Chengzhong Wu
6ffacbf0f9
node-api: rename internal NAPI_VERSION definition
...
PR-URL: https://github.com/nodejs/node/pull/48501
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2023-06-28 17:08:58 -04:00
Chengzhong Wu
66f112d8e9
node-api: define version 9
...
PR-URL: https://github.com/nodejs/node/pull/48151
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
2023-06-02 09:50:26 +00:00
Vladimir Morozov
c542d3a1d3
node-api: get Node API version used by addon
...
PR-URL: https://github.com/nodejs/node/pull/45715
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-05-05 11:00:27 -04:00
Chengzhong Wu
6700aac615
src: mark fatal error functions as noreturn
...
OnFatalError and OOMErrorHandler will not return control flow to the
calling function.
node::FatalError is an alias of node::OnFatalError. Replace all the
callsites with node::OnFatalError instead.
PR-URL: https://github.com/nodejs/node/pull/47695
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2023-04-27 08:57:52 +00:00
Chengzhong Wu
682256c76d
node-api: remove unused mark_arraybuffer_as_untransferable
...
napi_create_external_arraybuffer creates the arraybuffer with
node::Buffer, which already marks the buffer as untransferable.
The napi_env__::mark_arraybuffer_as_untransferable is not used
anymore.
PR-URL: https://github.com/nodejs/node/pull/47557
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2023-04-18 14:04:07 +08:00
Anna Henningsen
b85b5ba10c
src: use string_view for report and related code
...
Use `std::string_view` for process.report code and related
code, drop a few unnecessary `std::to_string` calls,
and use `MaybeStackBuffer` instead of `MallocedBuffer`,
all in order to avoid unnecessary heap allocations.
PR-URL: https://github.com/nodejs/node/pull/46723
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-02-20 22:01:45 +00:00
Yagiz Nizipli
c4581abff6
url: replace url-parser with ada
...
PR-URL: https://github.com/nodejs/node/pull/46410
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Robert Nagy <ronagy@icloud.com >
2023-02-06 19:21:39 +00:00
ywave620
8438f3b73b
process,worker: ensure code after exit() effectless
...
Cope with the delay(to the next function call) of
v8::Isolate::TerminateExecution()
PR-URL: https://github.com/nodejs/node/pull/45620
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2022-12-25 09:54:12 +00:00
legendecas
f14fa1bbca
node-api: generalize finalizer second pass callback
...
Generalize the finalizer's second pass callback to make it
cancellable and simplify the code around the second pass callback.
With this change, it is determined that Reference::Finalize or
RefBase::Finalize are called once, either from the env's shutdown,
or from the env's second pass callback.
All existing node-api js tests should pass without a touch. The
js_native_api cctest is no longer applicable with this change,
just removing it.
PR-URL: https://github.com/nodejs/node/pull/44141
Refs: https://github.com/nodejs/node/issues/44071
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-12-20 01:44:42 +08:00
Michael Dawson
0bbef56760
node-api: address coverity warning
...
- address coverity unitialized variable warning
Signed-off-by: Michael Dawson <mdawson@devrus.com >
PR-URL: https://github.com/nodejs/node/pull/45563
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2022-11-24 09:21:03 -05:00
Chengzhong Wu
62cde6195f
node-api: declare type napi_cleanup_hook
...
Declare type `napi_cleanup_hook` so that the function signature can be
shared across the codebase.
PR-URL: https://github.com/nodejs/node/pull/45391
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com >
2022-11-19 17:31:36 +00:00
Michael Dawson
09ae62b9a8
node-api: handle no support for external buffers
...
Refs: https://github.com/electron/electron/issues/35801
Refs: https://github.com/nodejs/abi-stable-node/issues/441
Electron recently dropped support for external
buffers. Provide a way for addon authors to:
- hide the methods to create external buffers so they can
avoid using them if they want the broadest compatibility.
- call the methods that create external buffers at runtime
to check if external buffers are supported and either
use them or not based on the return code.
Signed-off-by: Michael Dawson <mdawson@devrus.com >
PR-URL: https://github.com/nodejs/node/pull/45181
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2022-11-09 13:30:43 -05:00
theanarkh
8fb282e2b4
src: trace threadpool event
...
PR-URL: https://github.com/nodejs/node/pull/44458
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2022-11-01 04:21:13 +00:00
Chengzhong Wu
9b369824cb
node-api: add deprecation code of uncaught exception
...
Deprecation should reference a valid deprecation code.
PR-URL: https://github.com/nodejs/node/pull/44624
Refs: https://github.com/nodejs/node/pull/36510
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-09-21 00:02:14 +08:00
Chengzhong Wu
ad3c7bcb03
node-api: avoid calling virtual methods in base's dtor
...
Derived classes' fields are already destroyed if the virtual methods are
invoked in the base class's destructor. It is not safe to call virtual
methods in base's dtor.
PR-URL: https://github.com/nodejs/node/pull/44424
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2022-08-31 13:47:10 +00:00
legendecas
f33a038384
node-api: cleanup redundant static modifiers
...
Functions declared in anonymous namespaces are not necessarily to be
marked as static.
PR-URL: https://github.com/nodejs/node/pull/44301
Refs: https://github.com/nodejs/node/pull/44141
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-08-25 08:15:00 +08:00
legendecas
681fb3a200
node-api: emit uncaught-exception on unhandled tsfn callbacks
...
PR-URL: https://github.com/nodejs/node/pull/36510
Fixes: https://github.com/nodejs/node/issues/36402
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-05-27 13:32:08 -04:00
Vladimir Morozov
fb744749e2
node-api: explicitly set __cdecl for API functions
...
PR-URL: https://github.com/nodejs/node/pull/42780
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-05-13 15:42:10 -04:00
Vladimir Morozov
718be08686
node-api: format Node-API related code
...
PR-URL: https://github.com/nodejs/node/pull/42396
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2022-03-21 13:24:16 -04:00
Anna Henningsen
64832c12b1
src: return proper URLs from node_api_get_module_file_name
...
Using `file://${path}` does not properly escape special URL characters.
PR-URL: https://github.com/nodejs/node/pull/41758
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-03-07 15:57:54 +01:00
Austin Kelleher
663a669b0b
node-api: fix typo in node_api.cc
...
PR-URL: https://github.com/nodejs/node/pull/42110
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Mestery <mestery@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2022-02-24 19:04:50 +01:00
Darshan Sen
16853c9d55
src: add a constructor overload for CallbackScope
...
This overload accepts the current Environment* as an argument, unlike
the other constructor, which accepts an Isolate*. This is useful because
we can pass the current Environment* directly instead of recomputing it
from the Isolate* inside the constructor.
Signed-off-by: Darshan Sen <darshan.sen@postman.com >
PR-URL: https://github.com/nodejs/node/pull/39768
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
2021-08-21 06:53:50 +00:00
legendecas
392213a387
node-api: cctest on v8impl::Reference
...
PR-URL: https://github.com/nodejs/node/pull/38970
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
2021-07-05 13:55:51 +08:00
XadillaX
46acbb058f
src: replace autos in node_api.cc
...
PR-URL: https://github.com/nodejs/node/pull/38852
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-06-01 21:17:12 +08:00
Michael Dawson
c32c5f0d43
node-api: fix shutdown crashes
...
Refs: https://github.com/nodejs/node-addon-api/issues/906
Ensure that finalization is not defered during shutdown.
The env for the addon is deleted immediately after
iterating the list of finalizers to be run. Defering
causes crashes as the finalization uses the already
deleted env.
Signed-off-by: Michael Dawson <mdawson@devrus.com >
PR-URL: https://github.com/nodejs/node/pull/38492
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
2021-05-20 10:17:45 -04:00
Fedor Indutny
7abc7e45b2
node-api: faster threadsafe_function
...
Invoke threadsafe_function during the same tick and avoid marshalling
costs between threads and/or churning event loop if either:
1. There's a queued call already
2. `Push()` is called while the main thread was running
threadsafe_function
PR-URL: https://github.com/nodejs/node/pull/38506
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-05-04 18:39:28 -07:00
Gabriel Schulhof and Michael Dawson
ad3ebed046
node-api: allow retrieval of add-on file name
...
Unlike JS-only modules, native add-ons are always associated with a
dynamic shared object from which they are loaded. Being able to
retrieve its absolute path is important to native-only add-ons, i.e.
add-ons that are not themselves being loaded from a JS-only module
located in the same package as the native add-on itself.
Currently, the file name is obtained at environment construction time
from the JS `module.filename`. Nevertheless, the presence of `module`
is not required, because the file name could also be passed in via a
private property added onto `exports` from the `process.dlopen`
binding.
As an attempt at future-proofing, the file name is provided as a URL,
i.e. prefixed with the `file://` protocol.
Fixes: https://github.com/nodejs/node-addon-api/issues/449
PR-URL: https://github.com/nodejs/node/pull/37195
Co-authored-by: Michael Dawson <mdawson@devrus.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-02-09 23:34:30 -08:00
Gabriel Schulhof
2fd22353ea
n-api: factor out calling pattern
...
Factor out how we handle a `napi_status`-valued return internally.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
PR-URL: https://github.com/nodejs/node/pull/36113
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-11-15 21:48:27 -08:00
legendecas
3a7537de7d
n-api: napi_make_callback emit async init with resource of async_context
...
instead of emit async init with receiver of the callback.
PR-URL: https://github.com/nodejs/node/pull/32930
Fixes: https://github.com/nodejs/node/issues/32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
2020-10-31 00:17:59 +00:00
Anna Henningsen
ff38165820
src: allow N-API addon in AddLinkedBinding()
...
`AddLinkedBinding()` can be used to load old-style Node.js addons, but
currently not N-API addons. There’s no good reason not to support
N-API addons as well, so add that.
PR-URL: https://github.com/nodejs/node/pull/35301
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Zeyu Yang <himself65@outlook.com >
2020-09-26 08:22:47 +00:00
Gabriel Schulhof and Anna Henningsen
0848f56cb3
n-api: re-implement async env cleanup hooks
...
* Avoid passing core `void*` and function pointers into add-on.
* Document `napi_async_cleanup_hook_handle` type.
* Render receipt of the handle mandatory from the point where the
hook gets called. Removal of the handle remains mandatory.
Fixes: https://github.com/nodejs/node/issues/34715
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
Co-authored-by: Anna Henningsen <github@addaleax.net >
PR-URL: https://github.com/nodejs/node/pull/34819
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Zeyu Yang <himself65@outlook.com >
2020-08-27 08:18:37 -07:00