Conversation
Add napi_get_version function so that addons can query the level of N-API supported. Fixes: nodejs/abi-stable-node#231
doc/api/n-api.md
Outdated
|
|
||
| ### napi_get_version | ||
| <!-- YAML | ||
| added: v8.0.0 |
doc/api/n-api.md
Outdated
| --> | ||
| ```C | ||
| NAPI_EXTERN napi_status napi_get_version(napi_env env, | ||
| uint32_t* result); |
There was a problem hiding this comment.
The argument alignment is slightly off here
|
Thanks for the comments, push commit to address. |
|
|
||
| // test version management funcitons | ||
| // expected version is currently 1 | ||
| assert.strictEqual(test_general.testGetVersion(), 1); |
There was a problem hiding this comment.
Is this test going to need to be updated every time the napi version is bumped?
|
@mhdawson I don't understand how this API can be very useful in practice, even after reading the doc added here. Consider a native module that wants to use a function that was added in N-API v2. Even if that native module code calls |
|
@jasongin Fwiw, addons can use |
Yes, we discussed this in the N-API sync meeting earlier today. That is a way module authors could use this |
doc/api/n-api.md
Outdated
| `napi_get_version` to check which level of N-API is supported | ||
| at run time. Based on the result of this check the addon can | ||
| implement appropriate code paths when functions | ||
| are, or are not, fully implemented. |
There was a problem hiding this comment.
I would omit the mention of backporting stubs, since that wouldn't provide addon developers any real guarantees because many applications will not have the updates with the backported stubs. Instead, if addon developers desire backward compatibility with Node versions having older N-API versions, we should recommend dynamically loading APIs that might not be present, after checking the version.
I'd suggest changing this paragraph to something like this:
This API returns the highest N-API version supported by the
Node.js runtime. N-API is planned to be additive such that newer
releases of Node.js may support additional API functions. To allow
an addon to use a newer API when it's available while providing a
fallback behavior when it's not, first call `napi_get_version()` to
determine if the API is available, then use `uv_dlsym()` to dynamically
load a pointer to the function.
|
@jasongin pushed commit to address suggestion. |
doc/api/n-api.md
Outdated
| newer releases of Node.js may support additional API functions. | ||
| In order to allow an addon to use a newer function when running with | ||
| versions of Node.js that support it, while providing | ||
| fallback behaviour when runnign with Node.js versions that don't |
There was a problem hiding this comment.
Typo: runnign
Also, do we prefer American or British spelling of "behaviour"?
|
Pushed commit to address remaining comments. |
|
OSX failure was unrelated to change being made. Opened this issue to track: #13248 Going to land. |
|
Landed as d9ee297 |
Add napi_get_version function so that addons can query the level of N-API supported. PR-URL: #13207 Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Add napi_get_version function so that addons can query the level of N-API supported. PR-URL: #13207 Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
| #include "uv.h" | ||
| #include "node_api.h" | ||
|
|
||
| #define NAPI_VERSION 1 |
There was a problem hiding this comment.
@mhdawson - Was there any reason this is not inside src/node_api.h instead?
|
I made it internal as it was only used by node_api.cc. Not sure if we want code doing compile time checks. |
|
We don't want to encourage people to do compile-time checks of the N-API version, because the runtime version could be different. I think it should stay internal-only. |
Add napi_get_version function so that addons can query the level of N-API supported. PR-URL: nodejs#13207 Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Add napi_get_version function so that addons can query the level of N-API supported. Backport-PR-URL: #19447 PR-URL: #13207 Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Add napi_get_version function so that addons can
query the level of N-API supported.
Fixes: nodejs/abi-stable-node#231
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
n-api