Gabriel Schulhof
54c2bc2e62
n-api: create N-API version 7
...
Mark `napi_detach_arraybuffer` and `napi_is_detached_arraybuffer` as
stable.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
PR-URL: https://github.com/nodejs/node/pull/35199
Backport-PR-URL: https://github.com/nodejs/node/pull/35336
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <mdawson@devrus.com >
2020-10-07 07:25:00 -04:00
Denys Otrishko
b744ffd586
n-api: implement napi_is_detached_arraybuffer
...
This implements ArrayBuffer#IsDetachedBuffer operation as per ECMAScript
specification Section 24.1.1.2 https://tc39.es/ecma262/#sec-isdetachedbuffer
Closes: https://github.com/nodejs/node/issues/29955
PR-URL: https://github.com/nodejs/node/pull/30613
Backport-PR-URL: https://github.com/nodejs/node/pull/33061
Fixes: https://github.com/nodejs/node/issues/29955
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-07-01 14:54:50 -04:00
legendecas
961598b9be
n-api: add napi_detach_arraybuffer
...
As ArrayBuffer#detach is an ecma spec operation
([Section 24.1.1.3](https://tc39.es/ecma262/#sec-detacharraybuffer )),
it might be good to have it in N-API.
Fixes: https://github.com/nodejs/node/issues/29674
PR-URL: https://github.com/nodejs/node/pull/29768
Backport-PR-URL: https://github.com/nodejs/node/pull/33061
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
2020-07-01 14:53:26 -04:00
Tobias Nießen
cd9827f105
napi: fix memory corruption vulnerability
...
Fixes: https://hackerone.com/reports/784186
CVE-ID: CVE-2020-8174
PR-URL: https://github.com/nodejs-private/node-private/pull/203
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2020-06-02 14:59:22 +01:00
Gabriel Schulhof and legendecas
e9c590ea00
n-api: define release 6
...
Mark all N-APIs that have been added since version 5 as stable.
PR-URL: https://github.com/nodejs/node/pull/32058
Backport-PR-URL: https://github.com/nodejs/node/pull/32488
Fixes: https://github.com/nodejs/abi-stable-node/issues/393
Co-Authored-By: legendecas <legendecas@gmail.com >
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-04-06 11:39:06 +01:00
Gabriel Schulhof
239377b654
n-api: correct instance data tests
...
When instance data was backported, some of the tests ended up in a
location where they do not get run. This moves the tests into
test/addons-napi, merging them with existing tests therein, thereby
ensuring that they do get run.
PR-URL: https://github.com/nodejs/node/pull/32488
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-04-06 11:37:29 +01:00
himself65 and Gabriel Schulhof
ecbb331be0
n-api: add napi_get_all_property_names
...
Co-Authored-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
PR-URL: https://github.com/nodejs/node/pull/30006
Backport-PR-URL: https://github.com/nodejs/node/pull/31384
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-03-02 11:05:58 +00:00
Gabriel Schulhof
f29fb14cf6
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
Backport-PR-URL: https://github.com/nodejs/node/pull/30537
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-02-25 19:20:38 +00:00
Gabriel Schulhof
c74c6a5ccf
n-api: mark version 5 N-APIs as stable
...
PR-URL: https://github.com/nodejs/node/pull/29401
Backport-PR-URL: https://github.com/nodejs/node/pull/29458
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-10-01 19:38:58 +01:00
legendecas
f8622762e3
n-api: make func argument of napi_create_threadsafe_function optional
...
PR-URL: https://github.com/nodejs/node/pull/27791
Backport-PR-URL: https://github.com/nodejs/node/pull/28399
Refs: https://github.com/nodejs/node/issues/27592
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
2019-09-20 10:53:13 +01:00
Jarrod Connolly
4f41e4f471
n-api: implement date object
...
Implements `napi_create_date()` as well as `napi_is_date()` to
allow working with JavaScript Date objects.
Backport-PR-URL: https://github.com/nodejs/node/pull/28298
PR-URL: https://github.com/nodejs/node/pull/25917
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-09-03 16:58:59 +01:00
Daniel Bevenius
6bc7fd9b3c
test: fix compiler warning in test_string.c
...
Currently, the following compiler warnings is generated:
../test_string.c:235:50: warning:
incompatible pointer types passing 'char [1]' to parameter of type
'const char16_t *' (aka 'const unsigned short *')
[-Wincompatible-pointer-types]
NAPI_CALL(env, napi_create_string_utf16(env,
"", ((size_t)INT_MAX) + 1, &output));
^~
../../common.h:50:23: note: expanded from macro 'NAPI_CALL'
NAPI_CALL_BASE(env, the_call, NULL)
^~~~~~~~
../../common.h:42:10: note: expanded from macro 'NAPI_CALL_BASE'
if ((the_call) != napi_ok) { \
^~~~~~~~
/node/src/js_native_api.h:80:66: note:
passing argument to parameter 'str' here const char16_t* str,
^
1 warning generated.
This commit adds a cast to silence this warning.
PR-URL: https://github.com/nodejs/node/pull/26539
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-04-16 23:22:45 +01:00
Anthony Tuininga
2643801d9d
n-api: improve performance creating strings
...
Improve performance creating strings using N-API by ensuring that the
strings are not internalized.
Added test cases for latin-1 and utf-16 strings.
PR-URL: https://github.com/nodejs/node/pull/26439
Fixes: https://github.com/nodejs/node/issues/26437
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-04-05 11:17:01 -04:00
Gabriel Schulhof
48a5241b46
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
Backport-PR-URL: https://github.com/nodejs/node/pull/25633
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-03-12 22:07:22 +00:00
Rich Trott
80c9282dc7
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 >
2019-02-28 23:37:39 +11:00
Gireesh Punathil
36ace726da
test: mark test_threadsafe_function/test as flaky
...
The test fails consistently on windows-fanned with vs2017.
mark it as flaky while the issue is being progressed, and
to keep CI green / amber.
Ref: https://github.com/nodejs/node/issues/23621
PR-URL: https://github.com/nodejs/node/pull/24714
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-02-28 23:37:37 +11:00
susantruong
b2dfddc353
n-api,test: remove last argument in assert.strictEqual()
...
PR-URL: https://github.com/nodejs/node/pull/24584
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2019-02-28 23:37:34 +11:00
Michael Dawson
30d04fc402
n-api: handle reference delete before finalize
...
Crashes were reported during finalization due to
the memory for a reference being deleted and the
finalizer running after the deletion.
This change ensures the deletion of the memory for
the reference only occurs after the finalizer has run.
Fixes: https://github.com/nodejs/node-addon-api/issues/393
Backport-PR-URL: https://github.com/nodejs/node/pull/25574
PR-URL: https://github.com/nodejs/node/pull/24494
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2019-02-28 23:37:31 +11:00
kanishk30
644a9d6919
test: fix arguments order in napi test_exception
...
PR-URL: https://github.com/nodejs/node/pull/24413
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-01-28 21:54:52 -08:00
Daniel Bevenius
d8ac55a012
test: use NULL instead of 0 in common.h
...
This commit updates the macros in test/addons-napi/common.h to use NULL
instead of 0. This is very minor, but I had to look twice while going
through the code and finding what the macro was doing and comparing
with the struct definition. Using NULL makes it a little clearer I
think.
PR-URL: https://github.com/nodejs/node/pull/24104
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-12-26 11:18:54 -05:00
Kevin Seidel
2e0d3c9de9
test: fix order in assert.strictEqual to actual, expected
...
PR-URL: https://github.com/nodejs/node/pull/24184
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2018-12-26 11:18:49 -05:00
Joshua Belcher
cf0dbbd49f
test: fix order of assert.strictEqual() args to actual, expected
...
PR-URL: https://github.com/nodejs/node/pull/23501
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2018-11-29 11:38:37 -05:00
Andrew MacCuaig
c1b752355c
test: fix ordering of assertion values
2018-11-29 11:38:35 -05:00
et4891
b2e173be48
test: fix assert.strictEqual argument order
...
PR-URL: https://github.com/nodejs/node/pull/23518
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2018-11-29 11:38:19 -05:00
Rich Trott
a15bfdad78
test: remove string literal message from assertion
...
Remove string literal message in assert.strictEqual() call in napi test
testFinalizer.js.
Backport-PR-URL: https://github.com/nodejs/node/pull/22912
PR-URL: https://github.com/nodejs/node/pull/22849
Reviewed-By: Teddy Katz <teddy.katz@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-09-20 08:09:24 +02:00
Lucas Woo
bd6b2ab21d
test: checks on napi factory wrap’s finalization
...
Fixes: https://github.com/nodejs/node/issues/22396
PR-URL: https://github.com/nodejs/node/pull/22612
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
2018-09-20 07:41:15 +02:00
Gabriel Schulhof
bb2bbc8ebe
n-api: add generic finalizer callback
...
Add `napi_add_finalizer()`, which provides the ability to attach data
to an arbitrary object and be notified when that object is garbage-
collected so as to have an opportunity to delete the data previously
attached.
This differs from `napi_wrap()` in that it does not use up the private
slot on the object, and is therefore neither removable, nor retrievable
after the call to `napi_add_finalizer()`. It is assumed that the data
is accessible by other means, yet it must be tied to the lifetime of
the object. This is the case for data passed to a dynamically created
function which is itself heap-allocated and must therefore be freed
along with the function.
Fixes: https://github.com/nodejs/abi-stable-node/issues/313
PR-URL: https://github.com/nodejs/node/pull/22244
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-09-20 07:41:15 +02:00
yahavfuchs
77ce40fa03
test: remove unused argument in assertion
...
PR-URL: https://github.com/nodejs/node/pull/22113
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Jon Moss <me@jonathanmoss.me >
Reviewed-By: Weijia Wang <starkwang@126.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2018-08-15 20:23:17 +10:00
Kyle Farnung
d38ccaa421
test: fix n-api addon build warnings
...
Fixed an MSVC warning on Windows:
* test_general.c - Lossy conversion from int64 to double, explicitly
casting to double resolved the warning
PR-URL: https://github.com/nodejs/node/pull/21808
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-08-06 21:28:25 +02:00
Gabriel Schulhof
45816c50ac
n-api: guard against cond null dereference
...
A condition variable is only created by the thread-safe function if the
queue size is set to something larger than zero. This adds null-checks
around the condition variable and tests for the case where the queue
size is zero.
Fixes: https://github.com/nodejs/help/issues/1387
PR-URL: https://github.com/nodejs/node/pull/21871
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-07-24 20:52:39 +02:00
Michaël Zasso
bea1ee8e8e
test: make crashOnUnhandleRejection opt-out
...
This commit removes `common.crashOnUnhandledRejection()` and adds
`common.disableCrashOnUnhandledRejection()`.
To reduce the risk of mistakes and make writing tests that involve
promises simpler, always install the unhandledRejection hook in tests
and provide a way to disable it for the rare cases where it's needed.
PR-URL: https://github.com/nodejs/node/pull/21849
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-07-24 20:42:32 +02:00
Anna Henningsen
67908e9933
test: fix build warnings in bigint N-API test
...
PR-URL: https://github.com/nodejs/node/pull/21796
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Jon Moss <me@jonathanmoss.me >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-07-16 21:26:29 +02:00
Gus Caplan
3096ee5a4b
napi: add bigint support
...
PR-URL: https://github.com/nodejs/node/pull/21226
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com >
2018-07-14 12:03:01 +02:00
Gabriel Schulhof
4f3bbfaaca
n-api: test uint32 truncation
...
Re: https://github.com/nodejs/abi-stable-node/issues/55#issuecomment-403382424
PR-URL: https://github.com/nodejs/node/pull/21722
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-07-12 09:09:01 +02:00
Gabriel Schulhof
109c59971a
n-api: create functions directly
...
Avoid using `v8::FunctionTemplate::New()` when using
`v8::Function::New()` suffices. This ensures that individual functions
can be gc-ed and that functions can be created dynamically without
running out of memory.
PR-URL: https://github.com/nodejs/node/pull/21688
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Yang Guo <yangguo@chromium.org >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
2018-07-10 08:57:34 +02:00
Gabriel Schulhof
91384bfe5f
n-api: add API for asynchronous functions
...
Bundle a `uv_async_t`, a `uv_idle_t`, a `uv_mutex_t`, a `uv_cond_t`,
and a `v8::Persistent<v8::Function>` to make it possible to call into JS
from another thread. The API accepts a void data pointer and a callback
which will be invoked on the loop thread and which will receive the
`napi_value` representing the JavaScript function to call so as to
perform the call into JS. The callback is run inside a
`node::CallbackScope`.
A `std::queue<void*>` is used to store calls from the secondary
threads, and an idle loop is started by the `uv_async_t` callback on the
loop thread to drain the queue, calling into JS with each item.
Items can be added to the queue blockingly or non-blockingly.
The thread-safe function can be referenced or unreferenced, with the
same semantics as libuv handles.
Re: https://github.com/nodejs/help/issues/1035
Re: https://github.com/nodejs/node/issues/20964
Fixes: https://github.com/nodejs/node/issues/13512
PR-URL: https://github.com/nodejs/node/pull/17887
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-06-30 11:09:25 +02:00
Gabriel Schulhof
53f8563353
n-api: back up env before async work finalize
...
We must back up the value of `_env` before calling the async work
complete callback, because the complete callback may delete the
instance in which `_env` is stored by calling `napi_delete_async_work`,
and because we need to use it after the complete callback has
completed.
Fixes: https://github.com/nodejs/node/issues/20966
PR-URL: https://github.com/nodejs/node/pull/21129
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-06-12 05:07:16 -05:00
Gabriel Schulhof
ba30d149ea
n-api: throw when entry point is null
...
PR-URL: https://github.com/nodejs/node/pull/20779
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-05-25 14:01:04 +02:00
Ruben Bridgewater
045b37b32d
test: add eslint rule to verify assertion input
...
The input for `assert.deepStrictEqual` and similar expect the actual
input first and the expected input as second argument. This verifies
that this is actually done correct in our tests.
This is important so the possible error message actually makes sense.
PR-URL: https://github.com/nodejs/node/pull/20718
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-05-22 14:13:28 -04:00
Anna Henningsen
ba269585ed
src: add environment cleanup hooks
...
This adds pairs of methods to the `Environment` class and to public APIs
which can add and remove cleanup handlers.
Unlike `AtExit`, this API targets addon developers rather than
embedders, giving them (and Node’s internals) the ability to register
per-`Environment` cleanup work.
We may want to replace `AtExit` with this API at some point.
Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.
Refs: https://github.com/ayojs/ayo/pull/82
PR-URL: https://github.com/nodejs/node/pull/19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-05-14 19:19:32 +02:00
Gabriel Schulhof
70b2e169b4
test: fix up N-API error test
...
Replace assert.throws() with an explicit try/catch in order to catch
the thrown value and be able to compare it strictly to an expected
value.
Re: https://github.com/nodejs/node/pull/20428#issuecomment-386160684
PR-URL: https://github.com/nodejs/node/pull/20487
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-05-08 18:26:16 -07:00
Gabriel Schulhof
17dbf6c77f
n-api: make test_error functions static
...
PR-URL: https://github.com/nodejs/node/pull/20373/
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2018-05-08 14:22:25 -07:00
Gabriel Schulhof
ad793ab93c
n-api: test and doc napi_throw() of a primitive
...
Ensure that napi_throw() is able to throw a primitive value, and
document that it is able to throw any JavaScript value.
Fixes: https://github.com/nodejs/abi-stable-node/issues/309
PR-URL: https://github.com/nodejs/node/pull/20428
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-05-04 12:48:38 -04:00
Daniel Bevenius
705d9ecd13
n-api: remove unused Test function
...
Currently when building the following warning is emitted:
../test_symbol.c:4:19:
warning: unused function 'Test' [-Wunused-function]
static napi_value Test(napi_env env, napi_callback_info info) {
^
1 warning generated.
This commit removes this unused function.
PR-URL: https://github.com/nodejs/node/pull/20320
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2018-05-04 11:51:12 -04:00
Gabriel Schulhof
b5c1c146f5
n-api,test: remove superfluous persistent
...
Remove a superfluos persistent from test_constructor_name.c.
PR-URL: https://github.com/nodejs/node/pull/20299
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2018-05-04 11:51:12 -04:00
Gabriel Schulhof
2de3343474
n-api,test: make method static
...
One non-static method remains
PR-URL: https://github.com/nodejs/node/pull/20292
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-05-04 11:51:12 -04:00
Gabriel Schulhof
b239591ed8
n-api,test: make methods static
...
PR-URL: https://github.com/nodejs/node/pull/20243
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-05-04 11:49:32 -04:00
Gabriel Schulhof
d4b19cf43f
test,n-api: re-write test_error in C
...
PR-URL: https://github.com/nodejs/node/pull/20244
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-05-04 11:49:32 -04:00
Gabriel Schulhof
cd83df386b
n-api: initialize a module via a special symbol
...
Much like regular modules, N-API modules can also benefit from having
a special symbol which they can expose.
Fixes: https://github.com/nodejs/node/issues/19845
PR-URL: https://github.com/nodejs/node/pull/20161
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2018-05-04 11:47:53 -04:00
Kyle Farnung
c529168249
n-api: add more int64_t tests
...
* Updated tests for `Number` and `int32_t`
* Added new tests for `int64_t`
* Updated N-API `int64_t` behavior to return zero for all non-finite
numbers
* Clarified the documentation for these calls.
PR-URL: https://github.com/nodejs/node/pull/19402
Refs: https://github.com/nodejs/node-chakracore/pull/500
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2018-04-08 11:31:12 -07:00