Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
n-api: add napi_get_version#13207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
n-api: add napi_get_version #13207
Uh oh!
There was an error while loading. Please reload this page.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added: REPLACEME
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument alignment is slightly off here
mhdawson commented May 25, 2017
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this test going to need to be updated every time the napi version is bumped?
jasongin commented May 25, 2017
@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 |
addaleax commented May 25, 2017
@jasongin Fwiw, addons can use |
jasongin commented May 25, 2017
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. mhdawson commented May 25, 2017
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: runnign
Also, do we prefer American or British spelling of "behaviour"?
mhdawson commented May 26, 2017
Pushed commit to address remaining comments. |
mhdawson commented May 26, 2017
OSX failure was unrelated to change being made. Opened this issue to track: #13248 Going to land. |
mhdawson commented May 26, 2017
Landed as d9ee297 |
Add napi_get_version function so that addons can query the level of N-API supported. PR-URL: #13207Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
Add napi_get_version function so that addons can query the level of N-API supported. PR-URL: #13207Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
| #include"uv.h" | ||
| #include"node_api.h" | ||
| #defineNAPI_VERSION1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhdawson - Was there any reason this is not inside src/node_api.h instead?
mhdawson commented May 31, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I made it internal as it was only used by node_api.cc. Not sure if we want code doing compile time checks. |
jasongin commented May 31, 2017
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#13207Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
Add napi_get_version function so that addons can query the level of N-API supported. Backport-PR-URL: #19447 PR-URL: #13207Fixes: nodejs/abi-stable-node#231 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
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