From 37b6c185ad079eb90c5fe5f48c6eea093b1ee4f6 Mon Sep 17 00:00:00 2001 From: NickNaso Date: Tue, 23 Jul 2019 21:52:32 +0200 Subject: [PATCH 1/2] Fix compilation breakage on 1.7.0 --- napi-inl.h | 4 ++++ napi.h | 2 ++ test/index.js | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/napi-inl.h b/napi-inl.h index 11822d43a..3fb4465bb 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -125,6 +125,7 @@ struct FinalizeData { Hint* hint; }; +#if (NAPI_VERSION > 3) template , typename FinalizerDataType=void> @@ -196,6 +197,7 @@ struct ThreadSafeFinalize { Finalizer callback; napi_threadsafe_function* tsfn; }; +#endif template struct AccessorCallbackData { @@ -3740,6 +3742,7 @@ inline void AsyncWorker::OnWorkComplete( } } +#if (NAPI_VERSION > 3) //////////////////////////////////////////////////////////////////////////////// // ThreadSafeFunction class //////////////////////////////////////////////////////////////////////////////// @@ -4058,6 +4061,7 @@ inline void ThreadSafeFunction::CallJS(napi_env env, Function(env, jsCallback).Call({}); } } +#endif //////////////////////////////////////////////////////////////////////////////// // Memory Management class diff --git a/napi.h b/napi.h index d772fd50d..7bbea198d 100644 --- a/napi.h +++ b/napi.h @@ -1830,6 +1830,7 @@ namespace Napi { bool _suppress_destruct; }; + #if (NAPI_VERSION > 3) class ThreadSafeFunction { public: // This API may only be called from the main thread. @@ -2029,6 +2030,7 @@ namespace Napi { std::unique_ptr _tsfn; }; + #endif // Memory management. class MemoryManagement { diff --git a/test/index.js b/test/index.js index 9a5409b9a..e8b26da80 100644 --- a/test/index.js +++ b/test/index.js @@ -62,6 +62,11 @@ if ((process.env.npm_config_NAPI_VERSION !== undefined) && testModules.splice(testModules.indexOf('version_management'), 1); } +if ((process.env.npm_config_NAPI_VERSION !== undefined) && + (process.env.npm_config_NAPI_VERSION < 4)) { + testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function'), 1); +} + if (typeof global.gc === 'function') { console.log('Starting test suite\n'); From 6720d572532fe74b256a4f9ed345963ca3369181 Mon Sep 17 00:00:00 2001 From: NickNaso Date: Tue, 23 Jul 2019 22:40:04 +0200 Subject: [PATCH 2/2] Create the native threadsafe_function for test only for N-API greater than 3. --- test/threadsafe_function/threadsafe_function.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/threadsafe_function/threadsafe_function.cc b/test/threadsafe_function/threadsafe_function.cc index 529bfb308..e9b16083b 100644 --- a/test/threadsafe_function/threadsafe_function.cc +++ b/test/threadsafe_function/threadsafe_function.cc @@ -2,6 +2,8 @@ #include #include "napi.h" +#if (NAPI_VERSION > 3) + using namespace Napi; constexpr size_t ARRAY_LENGTH = 10; @@ -177,3 +179,5 @@ Object InitThreadSafeFunction(Env env) { return exports; } + +#endif