Skip to content

Commit 3acf151

Browse files
author
Gabriel Schulhof
committed
src: change guards to NAPI_VERSION > 5
Since we have made the decision that we shall include `BigInt` into N-API 6, we can change the guards for the `BigInt` and `BigInt`-based typed array wrappers accordingly, and end our reliance on guarding by `NODE_MAJOR_VERSION`. Signed-off-by: Gabriel Schulhof <[email protected]>
1 parent 89e62a9 commit 3acf151

File tree

7 files changed

+22
-71
lines changed

7 files changed

+22
-71
lines changed

common.gypi

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
'variables': {
33
'NAPI_VERSION%': "<!(node -p \"process.versions.napi\")",
4-
'NODE_MAJOR_VERSION%': "<!(node -p \"process.versions.node.match(/\\d+/)[0]\")",
54
'disable_deprecated': "<!(node -p \"process.env['npm_config_disable_deprecated']\")"
65
},
76
'conditions': [
@@ -16,7 +15,6 @@
1615
}
1716
}]
1817
],
19-
'defines': ['NODE_MAJOR_VERSION=<@(NODE_MAJOR_VERSION)'],
2018
'include_dirs': ["<!@(node -p \"require('../').include\")"],
2119
'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ],
2220
'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ]

napi-inl.h

+4-10
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,11 @@ inline bool Value::IsNumber() const {
386386
return Type() == napi_number;
387387
}
388388

389-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
390-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
391-
// released instead.
392-
#ifdef NAPI_EXPERIMENTAL
389+
#if NAPI_VERSION > 5
393390
inline bool Value::IsBigInt() const {
394391
return Type() == napi_bigint;
395392
}
396-
#endif // NAPI_EXPERIMENTAL
393+
#endif // NAPI_VERSION > 5
397394

398395
#if (NAPI_VERSION > 4)
399396
inline bool Value::IsDate() const {
@@ -624,10 +621,7 @@ inline double Number::DoubleValue() const {
624621
return result;
625622
}
626623

627-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
628-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
629-
// released instead.
630-
#ifdef NAPI_EXPERIMENTAL
624+
#if NAPI_VERSION > 5
631625
////////////////////////////////////////////////////////////////////////////////
632626
// BigInt Class
633627
////////////////////////////////////////////////////////////////////////////////
@@ -688,7 +682,7 @@ inline void BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words)
688682
_env, _value, sign_bit, word_count, words);
689683
NAPI_THROW_IF_FAILED_VOID(_env, status);
690684
}
691-
#endif // NAPI_EXPERIMENTAL
685+
#endif // NAPI_VERSION > 5
692686

693687
#if (NAPI_VERSION > 4)
694688
////////////////////////////////////////////////////////////////////////////////

napi.h

+10-25
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,9 @@ namespace Napi {
119119
class Value;
120120
class Boolean;
121121
class Number;
122-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
123-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
124-
// released instead.
125-
#ifdef NAPI_EXPERIMENTAL
122+
#if NAPI_VERSION > 5
126123
class BigInt;
127-
#endif // NAPI_EXPERIMENTAL
124+
#endif // NAPI_VERSION > 5
128125
#if (NAPI_VERSION > 4)
129126
class Date;
130127
#endif
@@ -147,13 +144,10 @@ namespace Napi {
147144
typedef TypedArrayOf<uint32_t> Uint32Array; ///< Typed-array of unsigned 32-bit integers
148145
typedef TypedArrayOf<float> Float32Array; ///< Typed-array of 32-bit floating-point values
149146
typedef TypedArrayOf<double> Float64Array; ///< Typed-array of 64-bit floating-point values
150-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
151-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
152-
// released instead.
153-
#ifdef NAPI_EXPERIMENTAL
147+
#if NAPI_VERSION > 5
154148
typedef TypedArrayOf<int64_t> BigInt64Array; ///< Typed array of signed 64-bit integers
155149
typedef TypedArrayOf<uint64_t> BigUint64Array; ///< Typed array of unsigned 64-bit integers
156-
#endif // NAPI_EXPERIMENTAL
150+
#endif // NAPI_VERSION > 5
157151

158152
/// Defines the signature of a N-API C++ module's registration callback (init) function.
159153
typedef Object (*ModuleRegisterCallback)(Env env, Object exports);
@@ -257,12 +251,9 @@ namespace Napi {
257251
bool IsNull() const; ///< Tests if a value is a null JavaScript value.
258252
bool IsBoolean() const; ///< Tests if a value is a JavaScript boolean.
259253
bool IsNumber() const; ///< Tests if a value is a JavaScript number.
260-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
261-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
262-
// released instead.
263-
#ifdef NAPI_EXPERIMENTAL
254+
#if NAPI_VERSION > 5
264255
bool IsBigInt() const; ///< Tests if a value is a JavaScript bigint.
265-
#endif // NAPI_EXPERIMENTAL
256+
#endif // NAPI_VERSION > 5
266257
#if (NAPI_VERSION > 4)
267258
bool IsDate() const; ///< Tests if a value is a JavaScript date.
268259
#endif
@@ -335,10 +326,7 @@ namespace Napi {
335326
double DoubleValue() const; ///< Converts a Number value to a 64-bit floating-point value.
336327
};
337328

338-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
339-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
340-
// released instead.
341-
#ifdef NAPI_EXPERIMENTAL
329+
#if NAPI_VERSION > 5
342330
/// A JavaScript bigint value.
343331
class BigInt : public Value {
344332
public:
@@ -377,7 +365,7 @@ namespace Napi {
377365
/// be needed to store this BigInt (i.e. the return value of `WordCount()`).
378366
void ToWords(int* sign_bit, size_t* word_count, uint64_t* words);
379367
};
380-
#endif // NAPI_EXPERIMENTAL
368+
#endif // NAPI_VERSION > 5
381369

382370
#if (NAPI_VERSION > 4)
383371
/// A JavaScript date value.
@@ -859,13 +847,10 @@ namespace Napi {
859847
: std::is_same<T, uint32_t>::value ? napi_uint32_array
860848
: std::is_same<T, float>::value ? napi_float32_array
861849
: std::is_same<T, double>::value ? napi_float64_array
862-
// Currently experimental guard with the definition of NAPI_EXPERIMENTAL.
863-
// Once it is no longer experimental guard with the NAPI_VERSION in which it is
864-
// released instead.
865-
#ifdef NAPI_EXPERIMENTAL
850+
#if NAPI_VERSION > 5
866851
: std::is_same<T, int64_t>::value ? napi_bigint64_array
867852
: std::is_same<T, uint64_t>::value ? napi_biguint64_array
868-
#endif // NAPI_EXPERIMENTAL
853+
#endif // NAPI_VERSION > 5
869854
: unknown_array_type;
870855
}
871856
/// !endcond

test/bigint.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
2-
// released. Once it is no longer experimental guard with the NAPI_VERSION
3-
// in which it is released instead.
4-
#if (NODE_MAJOR_VERSION >= 10)
1+
#if (NAPI_VERSION > 5)
52

63
#define NAPI_EXPERIMENTAL
74
#include "napi.h"

test/binding.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Object InitBasicTypesValue(Env env);
1717
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
1818
// released. Once it is no longer experimental guard with the NAPI_VERSION
1919
// in which it is released instead.
20-
#if (NODE_MAJOR_VERSION >= 10)
20+
#if (NAPI_VERSION > 5)
2121
Object InitBigInt(Env env);
2222
#endif
2323
Object InitBuffer(Env env);
@@ -73,7 +73,7 @@ Object Init(Env env, Object exports) {
7373
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
7474
// released. Once it is no longer experimental guard with the NAPI_VERSION
7575
// in which it is released instead.
76-
#if (NODE_MAJOR_VERSION >= 10)
76+
#if (NAPI_VERSION > 5)
7777
exports.Set("bigint", InitBigInt(env));
7878
#endif
7979
#if (NAPI_VERSION > 4)

test/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ let testModules = [
5757
];
5858

5959
const napiVersion = Number(process.versions.napi)
60-
const nodeMajorVersion = Number(process.versions.node.match(/\d+/)[0])
6160

62-
if (nodeMajorVersion < 10) {
63-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
64-
// released. Once it is no longer experimental guard with the NAPI_VERSION
65-
// in which it is released instead.
61+
if (napiVersion < 6) {
6662
testModules.splice(testModules.indexOf('bigint'), 1);
6763
testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
6864
}
@@ -89,7 +85,6 @@ if (napiVersion < 5) {
8985

9086
if (typeof global.gc === 'function') {
9187
console.log(`Testing with N-API Version '${napiVersion}'.`);
92-
console.log(`Testing with Node.js Major Version '${nodeMajorVersion}'.\n`);
9388

9489
console.log('Starting test suite\n');
9590

test/typedarray.cc

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
2-
// released. Once it is no longer experimental guard with the NAPI_VERSION
3-
// in which it is released instead.
4-
#if (NODE_MAJOR_VERSION >= 10)
5-
#define NAPI_EXPERIMENTAL
6-
#endif
71
#include "napi.h"
82

93
using namespace Napi;
@@ -70,10 +64,7 @@ Value CreateTypedArray(const CallbackInfo& info) {
7064
NAPI_TYPEDARRAY_NEW(Float64Array, info.Env(), length, napi_float64_array) :
7165
NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array, info.Env(), length, buffer, bufferOffset,
7266
napi_float64_array);
73-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
74-
// released. Once it is no longer experimental guard with the NAPI_VERSION
75-
// in which it is released instead.
76-
#if (NODE_MAJOR_VERSION >= 10)
67+
#if (NAPI_VERSION > 5)
7768
} else if (arrayType == "bigint64") {
7869
return buffer.IsUndefined() ?
7970
NAPI_TYPEDARRAY_NEW(BigInt64Array, info.Env(), length, napi_bigint64_array) :
@@ -107,10 +98,7 @@ Value GetTypedArrayType(const CallbackInfo& info) {
10798
case napi_uint32_array: return String::New(info.Env(), "uint32");
10899
case napi_float32_array: return String::New(info.Env(), "float32");
109100
case napi_float64_array: return String::New(info.Env(), "float64");
110-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
111-
// released. Once it is no longer experimental guard with the NAPI_VERSION
112-
// in which it is released instead.
113-
#if (NODE_MAJOR_VERSION >= 10)
101+
#if (NAPI_VERSION > 5)
114102
case napi_bigint64_array: return String::New(info.Env(), "bigint64");
115103
case napi_biguint64_array: return String::New(info.Env(), "biguint64");
116104
#endif
@@ -150,10 +138,7 @@ Value GetTypedArrayElement(const CallbackInfo& info) {
150138
return Number::New(info.Env(), array.As<Float32Array>()[index]);
151139
case napi_float64_array:
152140
return Number::New(info.Env(), array.As<Float64Array>()[index]);
153-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
154-
// released. Once it is no longer experimental guard with the NAPI_VERSION
155-
// in which it is released instead.
156-
#if (NODE_MAJOR_VERSION >= 10)
141+
#if (NAPI_VERSION > 5)
157142
case napi_bigint64_array:
158143
return BigInt::New(info.Env(), array.As<BigInt64Array>()[index]);
159144
case napi_biguint64_array:
@@ -197,10 +182,7 @@ void SetTypedArrayElement(const CallbackInfo& info) {
197182
case napi_float64_array:
198183
array.As<Float64Array>()[index] = value.DoubleValue();
199184
break;
200-
// Currently experimental guard with NODE_MAJOR_VERISION in which it was
201-
// released. Once it is no longer experimental guard with the NAPI_VERSION
202-
// in which it is released instead.
203-
#if (NODE_MAJOR_VERSION >= 10)
185+
#if (NAPI_VERSION > 5)
204186
case napi_bigint64_array: {
205187
bool lossless;
206188
array.As<BigInt64Array>()[index] = value.As<BigInt>().Int64Value(&lossless);

0 commit comments

Comments
 (0)