Gabriel Schulhof
4d02901935
node-api: test passing NULL to napi_define_class
...
PR-URL: https://github.com/nodejs/node/pull/47567
Reviewed-By: Michael Dawson <midawson@redhat.com >
2023-05-02 09:34:07 +02:00
Gabriel Schulhof
568256dca0
node-api: test passing NULL to number APIs
...
PR-URL: https://github.com/nodejs/node/pull/47549
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-05-02 09:33:59 +02:00
Gabriel Schulhof
b4365c161c
node-api: extend type-tagging to externals
...
Since externals behave as JavaScript objects on the JavaScript side,
allow them to be type-tagged.
Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/47141
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-03-22 04:47:08 +00:00
Antoine du Hamel
7079158d29
test: add trailing commas in test/js-native-api
...
PR-URL: https://github.com/nodejs/node/pull/46385
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-02-03 17:12:18 +01:00
Jordan Harband
757c104147
tools: add prefer-proto rule
...
fixup: add support for `Object.create(null)`
fixup: extend to any 1-argument Object.create call
fixup: add tests
PR-URL: https://github.com/nodejs/node/pull/46083
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2023-01-10 05:38:36 +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
Chengzhong Wu
926c830995
node-api: fix immediate napi_remove_wrap test
...
As documented in napi_wrap section, the returned reference must be
deleted with `napi_delete_reference` in response to the finalize
callback, in which `napi_unwrap` and `napi_remove_wrap` is not
available.
When the reference needs to be deleted early, it should be
deleted after the wrapped value is not accessed with `napi_unwrap`
and `napi_remove_wrap` too.
This test is previously added in response to duplicating the test
https://github.com/nodejs/node-addon-api/blob/main/test/objectwrap_constructor_exception.cc
in the node-addon-api. As Napi::ObjectWrap<> is a subclass of
Napi::Reference<>, napi_remove_wrap in the destructor of
Napi::ObjectWrap<> is called before napi_delete_reference in the
destructor of Napi::Reference<>.
PR-URL: https://github.com/nodejs/node/pull/45406
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2022-11-18 09:31:25 +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
Vladimir Morozov
5b316fe43f
node-api,test: fix test_reference_double_free crash
...
PR-URL: https://github.com/nodejs/node/pull/44927
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-10-19 08:07:58 +08:00
Chengzhong Wu
987176298e
test: verify napi_remove_wrap with napi_delete_reference
...
Verify that napi_remove_wrap and napi_delete_reference should be safe
to be called consecutively on the in-out params of napi_wrap.
PR-URL: https://github.com/nodejs/node/pull/44754
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2022-09-26 14:20:20 +00:00
Daeyeon Jeong
cc7d4ab493
src: fix napi_check_object_type_tag()
...
This fixes a comparison failure occurring when the upper value of a
type tag is 0, or a type tag value is 0.
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
PR-URL: https://github.com/nodejs/node/pull/43788
Fixes: https://github.com/nodejs/node/issues/43786
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2022-07-14 15:22:46 -04: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
6b968fdbca
node-api: fix napi_get_all_property_names
...
PR-URL: https://github.com/nodejs/node/pull/42463
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-05-10 15:47:22 -04:00
Vladimir Morozov
44fdf953ba
node-api,src: fix module registration in MSVC C++
...
PR-URL: https://github.com/nodejs/node/pull/42459
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
2022-04-07 09:40:07 -04:00
Joyee Cheung
7c8d98ea84
test: pass data into napi_create_external
...
Since v8 10.1 v8::External::New DCHECKs that the data passed
into it cannot be a nullptr because that's not serializable
as external references. This updates the test to pass a
dummy data pointer to the call - which does not matter for the
test since we only care about whether the finalizer is
called.
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/3513234
PR-URL: https://github.com/nodejs/node/pull/42532
Refs: https://github.com/nodejs/node/pull/42115
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2022-04-02 23:57:33 +01:00
Rich Trott
8432f73724
tools,test: enable no-prototype-builtins
...
PR-URL: https://github.com/nodejs/node/pull/41801
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Mestery <mestery@protonmail.com >
2022-02-03 05:00:03 +00:00
Darshan Sen
ef4c115cc8
test: replace commented out expectations with tests
...
Signed-off-by: Darshan Sen <raisinten@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/41667
Reviewed-By: Mestery <mestery@protonmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-01-29 10:01:10 +00:00
Darshan Sen
726711fe4e
node-api: add node_api_symbol_for()
...
Fixes: https://github.com/nodejs/node/issues/41294
Signed-off-by: Darshan Sen <raisinten@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/41329
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-01-24 16:35:07 -05:00
Rich Trott
94abcbde8b
tools: enable ESLint no-loss-of-precision rule
...
PR-URL: https://github.com/nodejs/node/pull/41463
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2022-01-13 17:11:11 -08:00
JckXia
86e976f1f4
src: reset error struct if error code is napi_ok
...
PR-URL: https://github.com/nodejs/node/pull/40552
Refs: https://github.com/nodejs/node-addon-api/issues/1089
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2021-11-17 16:52:15 -05:00
Idan Attias
4265f2769b
src,doc: add SyntaxError napi support
...
Add `napi_create_syntax_error` and `napi_throw_syntax_error`.
Fixes: https://github.com/nodejs/node-addon-api/issues/1099
PR-URL: https://github.com/nodejs/node/pull/40736
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-11-16 16:30:45 -05:00
Tobias Nießen
dd52c05046
test: avoid deep comparisons with literals
...
Comparing any value to any non-RegExp literal or undefined using
strictEqual (or notStrictEqual) passes if and only if deepStrictEqual
(or notDeepStrictEqual, respectively) passes.
Unnecessarily using deep comparisons adds confusion.
This patch adds an ESLint rule that forbids the use of deepStrictEqual
and notDeepStrictEqual when the expected value (i.e., the second
argument) is a non-RegExp literal or undefined.
For reference, an ESTree literal is defined as follows.
extend interface Literal <: Expression {
type: "Literal";
value: string | boolean | null | number | RegExp | bigint;
}
The value `undefined` is an `Identifier` with `name: 'undefined'`.
PR-URL: https://github.com/nodejs/node/pull/40634
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Voltrex <mohammadkeyvanzade94@gmail.com >
2021-11-02 10:11:49 +00:00
Daniel Bevenius
35dc3861cd
test: suppress compiler warning in test_bigint
...
Currently the are two of following compiler warnings is
generated:
In file included from ../test_bigint.c:5:
../test_bigint.c: In function ‘CreateTooBigBigInt’:
../test_bigint.c:120:22: warning:
‘words’ may be used uninitialized [-Wmaybe-uninitialized]
This commit initialized the words array to avoid these warnings.
PR-URL: https://github.com/nodejs/node/pull/40253
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-10-01 05:13:32 +02:00
JckXia
33b5107d13
src: make napi_create_reference accept symbol
...
PR-URL: https://github.com/nodejs/node/pull/39926
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-09-08 13:10:38 -04:00
Michael Dawson
79b2c9a371
node-api: handle pending exception in cb wrapper
...
fixes: https://github.com/nodejs/node-addon-api/issues/1025
The functionreference test from the node-api tests
was reporting a failed v8 check when Node.js was compiled
as debug. The failure was because an exception was
pending but the C++ wrappers were returning
a return value that was invalid.
Signed-off-by: Michael Dawson <mdawson@devrus.com >
PR-URL: https://github.com/nodejs/node/pull/39476
Fixes: https://github.com/nodejs/node-addon-api/issues/1025
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2021-08-03 16:38:45 -04:00
Gabriel Schulhof
d615aeb758
node-api: avoid crashing on passed-in null string
...
When `napi_create_string_*` receives a null pointer as its second
argument, it must null-check it before passing it into V8, otherwise a
crash will occur.
Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/38923
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-06-11 09:01:22 -07:00
legendecas
78af363aa7
node-api: rtn pending excep on napi_new_instance
...
When there are any JavaScript exceptions pending,
`napi_pending_exception` should be returned.
PR-URL: https://github.com/nodejs/node/pull/38798
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-06-04 16:38:06 -04:00
Gabriel Schulhof
3f025cb5d0
test: give js-native-api tests consistent names
...
The convention for js-native-api/<test_name>:
* <test_name>.c or <test_name>.cc has the entry point
* The name of the target is <test_name>
PR-URL: https://github.com/nodejs/node/pull/38692
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2021-05-19 16:43:19 -04:00
Voltrex
29f1b609ba
test: call functions internally
...
All (or at least most) of the tests uses lambdas (or arrow functions
if you will) to call these functions internally inside of directly
calling them, this should also use this technique for consistency.
PR-URL: https://github.com/nodejs/node/pull/38560
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
2021-05-07 15:17:44 -07:00
Rich Trott
7e516aaac0
test: remove unneeded m flag on regular expressions
...
The m flag has no effect on regular expressions that don't match the
start or the end of a line.
PR-URL: https://github.com/nodejs/node/pull/38124
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2021-04-09 06:35:51 -07:00
Rich Trott
330f25ef82
test: prepare for consistent comma-dangle lint rule
...
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.
PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is >
2021-04-01 23:14:29 -07:00
Gabriel Schulhof
d15475578a
node-api: define version 8
...
Mark as stable the APIs that define Node-API version 8.
PR-URL: https://github.com/nodejs/node/pull/37652
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2021-03-10 16:31:16 -05:00
Gabriel Schulhof and Chengzhong Wu
03806a0bb2
node-api: force env shutdown deferring behavior
...
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.
Fixes: https://github.com/nodejs/node/issues/37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2021-02-18 20:31:03 -08:00
Gabriel Schulhof
4b7f23f868
test: rename n-api to node-api
...
This renames the macros used in the tests from `NAPI_*` to
`NODE_API_*`.
PR-URL: https://github.com/nodejs/node/pull/37217
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Beth Griggs <bgriggs@redhat.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-02-06 05:03:38 -08:00
Michaël Zasso
bf31d3c3b1
tools: enable no-unused-expressions lint rule
...
Fixes: https://github.com/nodejs/node/issues/36246
PR-URL: https://github.com/nodejs/node/pull/36248
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-12-07 20:33:45 +01:00
Shelley Vohr
19f14517c7
n-api: support for object freeze/seal
...
PR-URL: https://github.com/nodejs/node/pull/35359
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2020-10-07 08:31:43 -07:00
Gabriel Schulhof
31b3202d59
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
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-09-18 19:58:39 -07:00
Gabriel Schulhof and Anna Henningsen
cc7ec889e8
n-api: support type-tagging objects
...
`napi_instanceof()` is insufficient for reliably establishing the data
type to which a pointer stored with `napi_wrap()` or
`napi_create_external()` inside a JavaScript object points. Thus, we
need a way to "mark" an object with a value that, when later retrieved,
can unambiguously tell us whether it is safe to cast the pointer stored
inside it to a certain structure.
Such a check must survive loading/unloading/multiple instances of an
addon, so we use UUIDs chosen *a priori*.
Fixes: https://github.com/nodejs/node/issues/28164
Co-authored-by: Anna Henningsen <github@addaleax.net >
PR-URL: https://github.com/nodejs/node/pull/28237
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
2020-07-31 18:30:30 -07:00
Gabriel Schulhof
0cc2a54a53
n-api: simplify bigint-from-word creation
...
Macro `CHECK_MAYBE_EMPTY_WITH_PREAMBLE()` does the work of checking
the `TryCatch` and returning `napi_pending_exception` so this change
reuses it for `napi_create_bigint_words()`.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
PR-URL: https://github.com/nodejs/node/pull/34554
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-07-31 13:45:25 -07:00
Gabriel Schulhof
a74a6e3ba1
n-api: run all finalizers via SetImmediate()
...
Throwing an exception from a finalizer can cause the following fatal
error:
Error: async hook stack has become corrupted (actual: 2, expected: 0)
1: 0x970b5a node::InternalCallbackScope::~InternalCallbackScope()
[./node]
2: 0x99dda0 node::Environment::RunTimers(uv_timer_s*) [./node]
3: 0x13d8b22 [./node]
4: 0x13dbe42 uv_run [./node]
5: 0xa57974 node::NodeMainInstance::Run() [./node]
6: 0x9dbc17 node::Start(int, char**) [./node]
7: 0x7f4965417f43 __libc_start_main [/lib64/libc.so.6]
8: 0x96f4ae _start [./node]
By https://github.com/nodejs/node/issues/34341#issuecomment-658426281 ,
calling into JS from a finalizer and/or throwing exceptions from there
is not advised, because the stack may or may not be set up for JS
execution. The best solution is to run the user's finalizer from a
`SetImmediate()` callback.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
Fixes: https://github.com/nodejs/node/issues/34341
PR-URL: https://github.com/nodejs/node/pull/34386
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2020-07-23 23:28:09 -07:00
Gabriel Schulhof
c08920b0c4
test: add n-api null checks for conversions
...
Add assertions that conversion and coercion N-APIs return appropriate
error statuses when given `NULL`s for parameters they expect to not be
`NULL`.
For `napi_get_value_string_*` this also checks that it returns
`napi_string_expected` when passed a `napi_value` not containing a
string.
PR-URL: https://github.com/nodejs/node/pull/34142
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-07-08 10:32:16 -07:00
Tobias Nießen
656260b4b6
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/195
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-06-02 20:35:51 +02:00
Antoine du HAMEL
6443ab9595
module: deprecate module.parent
...
This feature does not work when a module is imported using ECMAScript
modules specification, therefore it is deprecated.
Fixes: https://github.com/nodejs/modules/issues/469
PR-URL: https://github.com/nodejs/node/pull/32217
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Bradley Farias <bradley.meck@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2020-05-24 03:38:39 +02:00
Gabriel Schulhof
e454e9b33f
n-api: add uint32 test for -1
...
Adds a test to ensure that napi_get_value_uint32 returns 0xffffffff for
-1.
Re: https://github.com/nodejs/node/issues/33117
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Zeyu Yang <himself65@outlook.com >
2020-05-06 23:52:05 -07:00
Michaël Zasso
d23eed256b
src: remove calls to deprecated ArrayBuffer methods
...
v8::ArrayBuffer::IsExternal and v8::ArrayBuffer::Externalize are
no longer necessary.
PR-URL: https://github.com/nodejs/node/pull/32358
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Matheus Marchini <mat@mmarchini.me >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
2020-03-21 12:00:57 +01:00
Michael Dawson
e063ebd337
n-api: fix comment on expected N-API version
...
Remove the comment about the expected version so
that it does not get out of sync. The code shows
the expected version anyway.
Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com >
PR-URL: https://github.com/nodejs/node/pull/32236
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2020-03-16 16:48:30 -04:00
Gabriel Schulhof and legendecas
c0c81ed204
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
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-03-09 11:58:51 -07:00
Gabriel Schulhof
42995a3a11
test: cover property n-api null cases
...
Add test coverage for passing `NULL` to each parameter of
`napi.*(propert|element)` and `napi_set_prototype`. In the case of
`napi_define_properties` also test setting various initializer fields
to `NULL`.
PR-URL: https://github.com/nodejs/node/pull/31488
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-01-25 21:23:05 -08:00
legendecas
689ab46c64
n-api: return napi_invalid_arg on napi_create_bigint_words
...
N-API statuses shall be preferred over throwing JavaScript Errors on
checks occurred in N-APIs.
PR-URL: https://github.com/nodejs/node/pull/31312
Refs: https://github.com/nodejs/node/issues/29849
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2020-01-13 21:16:05 -08:00
himself65 and Gabriel Schulhof
6219f1fb44
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
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-01-11 18:50:28 -08:00