Gabriel Schulhof
884e287199
n-api: free instance data as reference
...
Instance data associated with a `napi_env` is no longer stored on the
env itself but is instead rendered as a reference. Since
`v8impl::Reference` is tied to a JS object, this modification factors
out the `v8impl::Reference` refcounting and the deletion process into
a base class for `v8impl::Reference`, called `v8impl::RefBase`. The
instance data is then stored as a `v8impl::RefBase`, along with other
references, preventing a segfault that arises from the fact that, up
until now, upon `napi_env` destruction, the instance data was freed
after all references had already been forcefully freed. If the addon
freed a reference during the `napi_set_instance_data` finalizer
callback, such a reference had already been freed during environment
teardown, causing a double free.
Re: https://github.com/nodejs/node-addon-api/pull/663
PR-URL: https://github.com/nodejs/node/pull/31638
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: David Carlier <devnexen@gmail.com >
2020-02-06 12:43:24 -08:00
Anna Henningsen
493faf606d
n-api: keep napi_env alive while it has finalizers
...
Manage the napi_env refcount from Finalizer instances, as the
finalizer may refer to the napi_env until it is deleted.
Fixes: https://github.com/nodejs/node/issues/31134
Fixes: https://github.com/node-ffi-napi/node-ffi-napi/issues/48
PR-URL: https://github.com/nodejs/node/pull/31140
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-01-04 07:38:36 +01:00
Thang Tran
4f523c2c1a
src: migrate to new V8 ArrayBuffer API
...
ArrayBuffer without BackingStore will soon be deprecated.
Fixes:https://github.com/nodejs/node/issues/30529
PR-URL: https://github.com/nodejs/node/pull/30782
Fixes: https://github.com/nodejs/node/issues/30529
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-12-12 10:05:44 -05:00
Anna Henningsen
f4f8ec2b65
test: port worker + buffer test to N-API
...
This ports `test/addons/worker-buffer-callback` to N-API,
with the small exception of using external `ArrayBuffer`s rather
than external Node.js `Buffer`s.
PR-URL: https://github.com/nodejs/node/pull/30551
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-11-30 02:02:52 +01:00
Gabriel Schulhof
4e5bb250d8
n-api: mark version 5 N-APIs as stable
...
PR-URL: https://github.com/nodejs/node/pull/29401
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-09-05 09:16:54 -07:00
Gabriel Schulhof
5030e81ce3
n-api: add APIs for per-instance state management
...
Adds `napi_set_instance_data()` and `napi_get_instance_data()`, which
allow native addons to store their data on and retrieve their data from
`napi_env`. `napi_set_instance_data()` accepts a finalizer which is
called when the `node::Environment()` is destroyed.
This entails rendering the `napi_env` local to each add-on.
Fixes: https://github.com/nodejs/abi-stable-node/issues/378
PR-URL: https://github.com/nodejs/node/pull/28682
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-07-25 16:53:07 -07:00
Anna Henningsen
d11b5382d6
test: use assert() in N-API async test
...
The `Execute()` callback is not allowed to call into JS, so
we should use `assert()` instead of potentially throwing JS errors.
PR-URL: https://github.com/nodejs/node/pull/28423
Fixes: https://github.com/nodejs/help/issues/1998
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-06-28 04:56:34 +02:00
legendecas
5705d7bf60
n-api: make func argument of napi_create_threadsafe_function optional
...
PR-URL: https://github.com/nodejs/node/pull/27791
Refs: https://github.com/nodejs/node/issues/27592
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
2019-06-21 20:23:22 -06:00
Anna Henningsen
3ca0df22e6
n-api: defer Buffer finalizer with SetImmediate
...
We have a test that verifies that JS execution from the Buffer
finalizer is accepted, and that errors thrown are passed
down synchronously.
However, since the finalizer executes during GC, this is behaviour is
fundamentally invalid and, for good reasons, disallowed by the
JS engine. This leaves us with the options of either finding a way
to allow JS execution from the callback, or explicitly forbidding it on
the N-API side as well.
This commit implements the former option, since it is the more
backwards-compatible one, in the sense that the current situation
sometimes appears to work as well and we should not break that
behaviour if we don’t have to, but rather try to actually make it
work reliably.
Since GC timing is largely unobservable anyway, this commit moves
the callback into a `SetImmediate()`, as we do elsewhere in the code,
and a second pass callback is not an easily implemented option,
as the API is supposed to wrap around Node’s `Buffer` API.
In this case, exceptions are handled like other uncaught exceptions.
Two tests have to be adjusted to account for the timing difference.
This is unfortunate, but unavoidable if we want to conform to the
JS engine API contract and keep all tests.
Fixes: https://github.com/nodejs/node/issues/26754
PR-URL: https://github.com/nodejs/node/pull/28082
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-06-14 13:03:12 +02:00
Evgenii Shchepotev
6a3d7cffab
test: cover import of a *.node file with a policy manifest
...
Cover import of a *.node file with a policy manifest. Add invalid
integrity test case.
PR-URL: https://github.com/nodejs/node/pull/27903
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-05-30 15:38:54 +02:00
Anna Henningsen
55fbcda864
n-api: do not require JS Context for napi_async_destroy()
...
Allow the function to be called during GC, which is a common use case.
Fixes: https://github.com/nodejs/node/issues/27218
PR-URL: https://github.com/nodejs/node/pull/27255
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-04-24 21:38:39 +02:00
Refael Ackermann
f2064dfc1f
src: de-lint header usage
...
PR-URL: https://github.com/nodejs/node/pull/26306
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2019-03-12 09:57:19 -04:00
Rich Trott
33880d79dd
test: remove flaky designation for test_threadsafe_function
...
The test_threadsafe_function doesn't seem to be flaky anymore on
Windows. Optimistically removing the flaky designation in the relevant
status file.
Refs: https://github.com/nodejs/node/issues/23621#issuecomment-468938980
PR-URL: https://github.com/nodejs/node/pull/26403
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2019-03-04 11:09:47 -08:00
Anna Henningsen
8ebd339031
worker: improve integration with native addons
...
Allow loading add-ons from multiple Node.js instances if they are
declared context-aware; in particular, this applies to N-API addons.
Also, plug a memory leak that occurred when registering N-API addons.
Refs: https://github.com/nodejs/node/pull/23319
PR-URL: https://github.com/nodejs/node/pull/26175
Fixes: https://github.com/nodejs/node/issues/21481
Fixes: https://github.com/nodejs/node/issues/21783
Fixes: https://github.com/nodejs/node/issues/25662
Fixes: https://github.com/nodejs/node/issues/20239
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
2019-02-22 21:42:09 +01:00
Anna Henningsen
441ef4d7f0
n-api: do not call into JS when that is not allowed
...
Check whether calling into JS is allowed before doing so.
PR-URL: https://github.com/nodejs/node/pull/26127
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-02-17 18:09:58 +01:00
Gabriel Schulhof
11387e1454
n-api: mark thread-safe function as stable
...
Fixes: https://github.com/nodejs/node/issues/24249
PR-URL: https://github.com/nodejs/node/pull/25556
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-01-21 22:30:11 -08:00
Rich Trott
06e5afa948
test: remove unused addons-napi directory
...
Refs: https://github.com/nodejs/node/pull/24557#issuecomment-444284512
PR-URL: https://github.com/nodejs/node/pull/24839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2018-12-04 20:48:39 -08:00
Rich Trott
61e332b3cb
test: add .gitignore file for node-api
...
Refs: https://github.com/nodejs/node/pull/24557#issuecomment-444284114
PR-URL: https://github.com/nodejs/node/pull/24839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2018-12-04 20:48:33 -08:00
Gabriel Schulhof
938e11882b
test: partition N-API tests
...
Partition test/addons-napi into test/js-native-api and test/node-api to
isolate the Node.js-agnostic portion of the N-API tests from the
Node.js-specific portion.
PR-URL: https://github.com/nodejs/node/pull/24557
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2018-12-04 13:58:17 -08:00