Vladimir Morozov
146f2be146
node-api: fix node_api_create_object_with_properties name
...
PR-URL: https://github.com/nodejs/node/pull/61319
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2026-01-23 03:51:23 +00:00
Vladimir Morozov
53b3c83ed4
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-16 16:00:54 +00:00
Miguel Marcondes Filho
a556db4782
node-api: add napi_create_object_with_properties
...
PR-URL: https://github.com/nodejs/node/pull/59953
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com >
2025-10-30 14:10:44 +00:00
Anna Henningsen
4b289d047d
test: expand linting rules around assert w literal messages
...
Expands the existing restrictions around not using literal messages
to the `not` variants of `strictEqual` and `deepStrictEqual`, and
forbids `assert()` where the second argument is a non-string literal,
which almost always is a mis-typed `assert.strictEquals()`.
PR-URL: https://github.com/nodejs/node/pull/59147
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2025-07-23 16:28:06 +00:00
Nathan Baulch
28c7394319
test: fix typos
...
PR-URL: https://github.com/nodejs/node/pull/55063
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2024-09-28 13:58:55 +00:00
Niels Martignène
c1bbc5d569
node-api: copy external type tags when they are set
...
In order to adapt to V8 changes regarding storing private
properties on Externals, ExternalWrapper objects were introduced
in #51149 .
However, this new code stores the type tag pointer and not the
128-bit value inside. This breaks some pre-existing code that
were making temporary tags. It also means that unloading the module
will cause existing External objects to have a tag pointer that
points nowhere (use-after-free bug).
Change ExternalWrapper to store tags by value to fix this regression.
PR-URL: https://github.com/nodejs/node/pull/52426
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2024-04-15 17:18:37 +00:00
Chengzhong Wu
52fcf14258
node-api: return napi_exception_pending on proxy handlers
...
Accessing JS objects can be trapped with proxy handlers. These
handlers can throw when no node-api errors occur. In such cases,
`napi_pending_exception` should be returned.
PR-URL: https://github.com/nodejs/node/pull/48607
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
Reviewed-By: Michael Dawson <midawson@redhat.com >
2023-10-23 18:17:49 -04:00
legendecas
178dff255f
test: avoid copying test source files
...
Converting the helper functions to be inlined and making the helper file
header only.
PR-URL: https://github.com/nodejs/node/pull/49515
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com >
2023-09-10 06:11:36 +00: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
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
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
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
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
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
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 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 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
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
Octavian Soldea
db1c4a7592
n-api: refactor a previous commit
...
This is a refactoring of https://github.com/nodejs/node/issues/27628
following https://github.com/nodejs/node/pull/28505 .
This change factors out functions `add_last_status()` and
`add_returned_status()` so they may be reused in the tests for passing
information about the last error status and/or a returned `napi_status`
to JavaScript.
PR-URL: https://github.com/nodejs/node/pull/28848
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
2019-07-26 15:09:04 -07:00
Octavian Soldea
ddbaddcce1
test: pass null params to napi_xxx_property()
...
For napi_set_property(), each one of the following arguments is checked:
napi_env env,
napi_value object,
napi_value key,
napi_value* value.
For napi_has_property(), each one of the following arguments is checked:
napi_env env,
napi_value object,
napi_value key,
bool* result
For napi_get_property, each one of the following arguments is checked:
napi_env env,
napi_value object,
napi_value key,
napi_value* result
PR-URL: https://github.com/nodejs/node/pull/27628
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-05-13 16:27:13 -07:00
Anna Henningsen
5c08481aa7
n-api: make napi_get_property_names return strings
...
The documentation says that this method returns an array of strings.
Currently, it does not do so for indices. Resolve that by telling
V8 explicitly to convert to string.
PR-URL: https://github.com/nodejs/node/pull/27524
Fixes: https://github.com/nodejs/node/issues/27496
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Minwoo Jung <minwoo@nodesource.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2019-05-06 05:12:27 +02:00
Gabriel Schulhof
baa54a5ae7
test: cover napi_get/set/has_named_property()
...
Add test coverage for these N-APIs.
PR-URL: https://github.com/nodejs/node/pull/26947
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-04-05 11:56:09 -07: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