Skip to content

Commit

Permalink
n-api: expose n-api version in process.versions
Browse files Browse the repository at this point in the history
Expose n-api version in process.versions so that it is
available for use in javascript by external modules
like node-pre-gyp. It was previously accessible through
a functon available in the N-API.

Backport-PR-URL: #19447
PR-URL: #18067
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Tobias Nießn <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
mhdawson authored and MylesBorins committed Apr 16, 2018
1 parent bb99f31 commit 62427bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3198,6 +3198,12 @@ void SetupProcessObject(Environment* env,
"modules",
FIXED_ONE_BYTE_STRING(env->isolate(), node_modules_version));

const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION);
READONLY_PROPERTY(
versions,
"napi",
FIXED_ONE_BYTE_STRING(env->isolate(), node_napi_version));

// process._promiseRejectEvent
Local<Object> promiseRejectEvent = Object::New(env->isolate());
READONLY_DONT_ENUM_PROPERTY(process,
Expand Down
2 changes: 0 additions & 2 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "node_api_backport.h"
#include "util.h"

#define NAPI_VERSION 2

static
napi_status napi_set_last_error(napi_env env, napi_status error_code,
uint32_t engine_error_code = 0,
Expand Down
3 changes: 3 additions & 0 deletions src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@
*/
#define NODE_MODULE_VERSION 48 /* Node.js v6.0.0 */

// the NAPI_VERSION provided by this version of the runtime
#define NAPI_VERSION 2

#endif // SRC_NODE_VERSION_H_
2 changes: 1 addition & 1 deletion test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common');
const assert = require('assert');

const expected_keys = ['ares', 'http_parser', 'modules', 'node',
'uv', 'v8', 'zlib'];
'uv', 'v8', 'zlib', 'napi'];

if (common.hasCrypto) {
expected_keys.push('openssl');
Expand Down

0 comments on commit 62427bb

Please sign in to comment.