Skip to content

Commit 2595dd5

Browse files
addaleaxnodejs-github-bot
authored andcommitted
src: move Node-API version detection to where it is used
`src/js_native_api_types.h` and other files actually depend on the moved macros being evaluated, so before this change there was an implicit requirement that `src/js_native_api.h` would be included separately before any include of `src/js_native_api_types.h`, direct or transitive. PR-URL: #60512 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8f66bec commit 2595dd5

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/js_native_api.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@
55
#include <stdbool.h> // NOLINT(modernize-deprecated-headers)
66
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
77

8-
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
9-
#define NAPI_VERSION_EXPERIMENTAL 2147483647
10-
#ifndef NAPI_VERSION
11-
#ifdef NAPI_EXPERIMENTAL
12-
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
13-
#else
14-
// The baseline version for N-API.
15-
// The NAPI_VERSION controls which version will be used by default when
16-
// compilling a native addon. If the addon developer specifically wants to use
17-
// functions available in a new version of N-API that is not yet ported in all
18-
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
19-
// depended on that version.
20-
#define NAPI_VERSION 8
21-
#endif
22-
#endif
23-
24-
#if defined(NAPI_EXPERIMENTAL) && \
25-
!defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \
26-
!defined(NODE_WANT_INTERNALS)
27-
#ifdef _MSC_VER
28-
#pragma message("NAPI_EXPERIMENTAL is enabled. " \
29-
"Experimental features may be unstable.")
30-
#else
31-
#warning "NAPI_EXPERIMENTAL is enabled. " \
32-
"Experimental features may be unstable."
33-
#endif
34-
#endif
35-
368
#include "js_native_api_types.h"
379

3810
// If you need __declspec(dllimport), either include <node_api.h> instead, or

src/js_native_api_types.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
#ifndef SRC_JS_NATIVE_API_TYPES_H_
22
#define SRC_JS_NATIVE_API_TYPES_H_
33

4+
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
5+
#define NAPI_VERSION_EXPERIMENTAL 2147483647
6+
#ifndef NAPI_VERSION
7+
#ifdef NAPI_EXPERIMENTAL
8+
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
9+
#else
10+
// The baseline version for N-API.
11+
// The NAPI_VERSION controls which version will be used by default when
12+
// compilling a native addon. If the addon developer specifically wants to use
13+
// functions available in a new version of N-API that is not yet ported in all
14+
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
15+
// depended on that version.
16+
#define NAPI_VERSION 8
17+
#endif
18+
#endif
19+
20+
#if defined(NAPI_EXPERIMENTAL) && \
21+
!defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \
22+
!defined(NODE_WANT_INTERNALS)
23+
#ifdef _MSC_VER
24+
#pragma message("NAPI_EXPERIMENTAL is enabled. " \
25+
"Experimental features may be unstable.")
26+
#else
27+
#warning "NAPI_EXPERIMENTAL is enabled. " \
28+
"Experimental features may be unstable."
29+
#endif
30+
#endif
31+
432
// This file needs to be compatible with C compilers.
533
// This is a public include file, and these includes have essentially
634
// became part of it's API.

0 commit comments

Comments
 (0)