From 6b8dd47c551d2ecc1e923cba6fbce8f3d66eea3a Mon Sep 17 00:00:00 2001 From: NickNaso Date: Mon, 23 Mar 2020 11:19:55 +0100 Subject: [PATCH 1/4] Added badge section to documentation. --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 52e0c3137..a67051d00 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ to ideas specified in the **ECMA262 Language Specification**. - **[Examples](#examples)** - **[Tests](#tests)** - **[More resource and info about native Addons](#resources)** +- **[Badges](#badges)** - **[Code of Conduct](CODE_OF_CONDUCT.md)** - **[Contributors](#contributors)** - **[License](#license)** @@ -185,6 +186,24 @@ such packages with `node-addon-api` to provide more visibility to the community. Quick links to NPM searches: [keywords:node-addon-api](https://www.npmjs.com/search?q=keywords%3Anode-addon-api). + + +### **Badges** + +The use of badges is recommended to indicate the minimum version of N-API +required for the module. This helps to determine which Node.js major versions are +supported. Addon maintainers can consult the [N-API support matrix][] to determine +which Node.js versions provide a given N-API version. The following badges are +available: + +![N-API v1 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v1%20Badge.svg) +![N-API v2 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v2%20Badge.svg) +![N-API v3 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v3%20Badge.svg) +![N-API v4 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v4%20Badge.svg) +![N-API v5 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v5%20Badge.svg) +![N-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v6%20Badge.svg) +![N-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20Experimental%20Version%20Badge.svg) + ## **Contributing** We love contributions from the community to **node-addon-api**! @@ -220,3 +239,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around Licensed under [MIT](./LICENSE.md) [ABI stability guide]: https://nodejs.org/en/docs/guides/abi-stability/ +[N-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix From 6c97913d1f44ffa334c9f3d4f36a56d7cc0e9096 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Sat, 28 Mar 2020 15:11:58 -0400 Subject: [PATCH 2/4] Fix minor typo in object_lifetime_management.md --- doc/object_lifetime_management.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/object_lifetime_management.md b/doc/object_lifetime_management.md index 4ab19ecd1..a888ff59e 100644 --- a/doc/object_lifetime_management.md +++ b/doc/object_lifetime_management.md @@ -69,7 +69,7 @@ for (int i = 0; i < LOOP_MAX; i++) { Napi::HandleScope scope(info.Env()); std::string name = std::string("inner-scope") + std::to_string(i); Napi::Value newValue = Napi::String::New(info.Env(), name.c_str()); - // do something with neValue + // do something with newValue }; ``` From e1a827ae295d4e426ab6c77272c3f3e87e31817c Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Tue, 7 Apr 2020 14:53:33 -0700 Subject: [PATCH 3/4] src: fix AsyncProgressQueueWorker compilation (#696) We need to cast the `nullptr` to the templated type of the `AsyncProgressQueueWorker`. Fixes: https://github.com/nodejs/node-addon-api/issues/695 PR-URL: https://github.com/nodejs/node-addon-api/pull/696 Signed-off-by: Gabriel Schulhof --- napi-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napi-inl.h b/napi-inl.h index 82846c257..f8657ae3f 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -4792,7 +4792,7 @@ inline void AsyncProgressWorker::SendProgress_(const T* data, size_t count) { template inline void AsyncProgressWorker::Signal() const { - this->NonBlockingCall(nullptr); + this->NonBlockingCall(static_cast(nullptr)); } template From 4f19ef785563439c81b19d93492c320ff6dd6a65 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Mon, 30 Mar 2020 09:22:42 -0700 Subject: [PATCH 4/4] 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 --- common.gypi | 2 -- napi-inl.h | 14 ++++---------- napi.h | 35 ++++++++++------------------------- test/bigint.cc | 5 +---- test/binding.cc | 4 ++-- test/index.js | 7 +------ test/typedarray.cc | 26 ++++---------------------- 7 files changed, 22 insertions(+), 71 deletions(-) diff --git a/common.gypi b/common.gypi index 76f8d251c..088f961ea 100644 --- a/common.gypi +++ b/common.gypi @@ -1,7 +1,6 @@ { 'variables': { 'NAPI_VERSION%': " 5 inline bool Value::IsBigInt() const { return Type() == napi_bigint; } -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 #if (NAPI_VERSION > 4) inline bool Value::IsDate() const { @@ -624,10 +621,7 @@ inline double Number::DoubleValue() const { return result; } -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 //////////////////////////////////////////////////////////////////////////////// // BigInt Class //////////////////////////////////////////////////////////////////////////////// @@ -688,7 +682,7 @@ inline void BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words) _env, _value, sign_bit, word_count, words); NAPI_THROW_IF_FAILED_VOID(_env, status); } -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 #if (NAPI_VERSION > 4) //////////////////////////////////////////////////////////////////////////////// diff --git a/napi.h b/napi.h index e4b964f87..7828a2b3f 100644 --- a/napi.h +++ b/napi.h @@ -119,12 +119,9 @@ namespace Napi { class Value; class Boolean; class Number; -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 class BigInt; -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 #if (NAPI_VERSION > 4) class Date; #endif @@ -147,13 +144,10 @@ namespace Napi { typedef TypedArrayOf Uint32Array; ///< Typed-array of unsigned 32-bit integers typedef TypedArrayOf Float32Array; ///< Typed-array of 32-bit floating-point values typedef TypedArrayOf Float64Array; ///< Typed-array of 64-bit floating-point values -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 typedef TypedArrayOf BigInt64Array; ///< Typed array of signed 64-bit integers typedef TypedArrayOf BigUint64Array; ///< Typed array of unsigned 64-bit integers -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 /// Defines the signature of a N-API C++ module's registration callback (init) function. typedef Object (*ModuleRegisterCallback)(Env env, Object exports); @@ -257,12 +251,9 @@ namespace Napi { bool IsNull() const; ///< Tests if a value is a null JavaScript value. bool IsBoolean() const; ///< Tests if a value is a JavaScript boolean. bool IsNumber() const; ///< Tests if a value is a JavaScript number. -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 bool IsBigInt() const; ///< Tests if a value is a JavaScript bigint. -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 #if (NAPI_VERSION > 4) bool IsDate() const; ///< Tests if a value is a JavaScript date. #endif @@ -335,10 +326,7 @@ namespace Napi { double DoubleValue() const; ///< Converts a Number value to a 64-bit floating-point value. }; -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 /// A JavaScript bigint value. class BigInt : public Value { public: @@ -377,7 +365,7 @@ namespace Napi { /// be needed to store this BigInt (i.e. the return value of `WordCount()`). void ToWords(int* sign_bit, size_t* word_count, uint64_t* words); }; -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 #if (NAPI_VERSION > 4) /// A JavaScript date value. @@ -859,13 +847,10 @@ namespace Napi { : std::is_same::value ? napi_uint32_array : std::is_same::value ? napi_float32_array : std::is_same::value ? napi_float64_array -// Currently experimental guard with the definition of NAPI_EXPERIMENTAL. -// Once it is no longer experimental guard with the NAPI_VERSION in which it is -// released instead. -#ifdef NAPI_EXPERIMENTAL +#if NAPI_VERSION > 5 : std::is_same::value ? napi_bigint64_array : std::is_same::value ? napi_biguint64_array -#endif // NAPI_EXPERIMENTAL +#endif // NAPI_VERSION > 5 : unknown_array_type; } /// !endcond diff --git a/test/bigint.cc b/test/bigint.cc index a62ed3c30..1f89db84a 100644 --- a/test/bigint.cc +++ b/test/bigint.cc @@ -1,7 +1,4 @@ -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) #define NAPI_EXPERIMENTAL #include "napi.h" diff --git a/test/binding.cc b/test/binding.cc index 111bcce01..c20063018 100644 --- a/test/binding.cc +++ b/test/binding.cc @@ -17,7 +17,7 @@ Object InitBasicTypesValue(Env env); // Currently experimental guard with NODE_MAJOR_VERISION in which it was // released. Once it is no longer experimental guard with the NAPI_VERSION // in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) Object InitBigInt(Env env); #endif Object InitBuffer(Env env); @@ -73,7 +73,7 @@ Object Init(Env env, Object exports) { // Currently experimental guard with NODE_MAJOR_VERISION in which it was // released. Once it is no longer experimental guard with the NAPI_VERSION // in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) exports.Set("bigint", InitBigInt(env)); #endif #if (NAPI_VERSION > 4) diff --git a/test/index.js b/test/index.js index e96ac5bf8..1971ef49a 100644 --- a/test/index.js +++ b/test/index.js @@ -57,12 +57,8 @@ let testModules = [ ]; const napiVersion = Number(process.versions.napi) -const nodeMajorVersion = Number(process.versions.node.match(/\d+/)[0]) -if (nodeMajorVersion < 10) { - // Currently experimental guard with NODE_MAJOR_VERISION in which it was - // released. Once it is no longer experimental guard with the NAPI_VERSION - // in which it is released instead. +if (napiVersion < 6) { testModules.splice(testModules.indexOf('bigint'), 1); testModules.splice(testModules.indexOf('typedarray-bigint'), 1); } @@ -89,7 +85,6 @@ if (napiVersion < 5) { if (typeof global.gc === 'function') { console.log(`Testing with N-API Version '${napiVersion}'.`); - console.log(`Testing with Node.js Major Version '${nodeMajorVersion}'.\n`); console.log('Starting test suite\n'); diff --git a/test/typedarray.cc b/test/typedarray.cc index 3b16ca2f5..08c667699 100644 --- a/test/typedarray.cc +++ b/test/typedarray.cc @@ -1,9 +1,3 @@ -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) -#define NAPI_EXPERIMENTAL -#endif #include "napi.h" using namespace Napi; @@ -70,10 +64,7 @@ Value CreateTypedArray(const CallbackInfo& info) { NAPI_TYPEDARRAY_NEW(Float64Array, info.Env(), length, napi_float64_array) : NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array, info.Env(), length, buffer, bufferOffset, napi_float64_array); -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) } else if (arrayType == "bigint64") { return buffer.IsUndefined() ? NAPI_TYPEDARRAY_NEW(BigInt64Array, info.Env(), length, napi_bigint64_array) : @@ -107,10 +98,7 @@ Value GetTypedArrayType(const CallbackInfo& info) { case napi_uint32_array: return String::New(info.Env(), "uint32"); case napi_float32_array: return String::New(info.Env(), "float32"); case napi_float64_array: return String::New(info.Env(), "float64"); -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) case napi_bigint64_array: return String::New(info.Env(), "bigint64"); case napi_biguint64_array: return String::New(info.Env(), "biguint64"); #endif @@ -150,10 +138,7 @@ Value GetTypedArrayElement(const CallbackInfo& info) { return Number::New(info.Env(), array.As()[index]); case napi_float64_array: return Number::New(info.Env(), array.As()[index]); -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) case napi_bigint64_array: return BigInt::New(info.Env(), array.As()[index]); case napi_biguint64_array: @@ -197,10 +182,7 @@ void SetTypedArrayElement(const CallbackInfo& info) { case napi_float64_array: array.As()[index] = value.DoubleValue(); break; -// Currently experimental guard with NODE_MAJOR_VERISION in which it was -// released. Once it is no longer experimental guard with the NAPI_VERSION -// in which it is released instead. -#if (NODE_MAJOR_VERSION >= 10) +#if (NAPI_VERSION > 5) case napi_bigint64_array: { bool lossless; array.As()[index] = value.As().Int64Value(&lossless);