-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
n-api: add napi_get_version #13207
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2946,6 +2946,34 @@ the `complete` callback will be invoked with a status value of | |
`napi_cancelled`. The work should not be deleted before the `complete` | ||
callback invocation, even if it has been successfully cancelled. | ||
|
||
## Version Management | ||
|
||
### napi_get_version | ||
<!-- YAML | ||
added: v8.0.0 | ||
--> | ||
```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 commentThe reason will be displayed to describe this comment to others. Learn more. The argument alignment is slightly off here |
||
``` | ||
|
||
- `[in] env`: The environment that the API is invoked under. | ||
- `[out] result`: The highest version of N-API supported. | ||
|
||
Returns `napi_ok` if the API succeeded. | ||
|
||
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. Since | ||
the goal is forward compatibility, older versions may not support | ||
the new functions even if we port empty stubs to earlier Node.js | ||
versions in order to facilitate use of the new functions with later | ||
Node.js releases. To support this case an addon can call | ||
`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 commentThe 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:
|
||
|
||
|
||
[Aynchronous Operations]: #n_api_asynchronous_operations | ||
[Basic N-API Data Types]: #n_api_basic_n_api_data_types | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
#include "uv.h" | ||
#include "node_api.h" | ||
|
||
#define NAPI_VERSION 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mhdawson - Was there any reason this is not inside |
||
|
||
static | ||
napi_status napi_set_last_error(napi_env env, napi_status error_code, | ||
uint32_t engine_error_code = 0, | ||
|
@@ -2713,6 +2715,13 @@ napi_status napi_get_typedarray_info(napi_env env, | |
return napi_clear_last_error(env); | ||
} | ||
|
||
napi_status napi_get_version(napi_env env, uint32_t* result) { | ||
CHECK_ENV(env); | ||
CHECK_ARG(env, result); | ||
*result = NAPI_VERSION; | ||
return napi_clear_last_error(env); | ||
} | ||
|
||
namespace uvimpl { | ||
|
||
static napi_status ConvertUVErrorCode(int code) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,7 @@ assert.strictEqual(test_general.testGetPrototype(extendedObject), | |
assert.ok(test_general.testGetPrototype(baseObject) !== | ||
test_general.testGetPrototype(extendedObject), | ||
'Prototypes for base and extended should be different'); | ||
|
||
// 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 commentThe 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? |
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