From bb8a836f76ba2870deb5d3afc7e8155c22b34dc5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 11 Aug 2020 16:44:47 +0200 Subject: [PATCH] Revert "Revert "Add support for NAPI 6"" This reverts commit 3887480ad2a68cee9fd44e53256a829ba3dfc471. --- include/ref-napi.h | 2 ++ src/binding.cc | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/ref-napi.h b/include/ref-napi.h index 8db31b2..c1503c2 100644 --- a/include/ref-napi.h +++ b/include/ref-napi.h @@ -1,7 +1,9 @@ #ifndef REF_NAPI_H #define REF_NAPI_H +#if !defined(NAPI_VERSION) || NAPI_VERSION < 6 #include +#endif #include "napi.h" // The definitions in this file are intended to be used by node-ffi-napi. diff --git a/src/binding.cc b/src/binding.cc index c3bff0b..418bf83 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -24,6 +24,7 @@ using namespace Napi; namespace { +#if !defined(NAPI_VERSION) || NAPI_VERSION < 6 napi_status napix_set_instance_data( napi_env env, void* data, napi_finalize finalize_cb, void* finalize_hint) { typedef napi_status (*napi_set_instance_data_fn)( @@ -50,6 +51,17 @@ napi_status napix_get_instance_data( return napi_generic_failure; return napi_get_instance_data__(env, data); } +#else // NAPI_VERSION >= 6 +napi_status napix_set_instance_data( + napi_env env, void* data, napi_finalize finalize_cb, void* finalize_hint) { + return napi_set_instance_data(env, data, finalize_cb, finalize_hint); +} + +napi_status napix_get_instance_data( + napi_env env, void** data) { + return napi_get_instance_data(env, data); +} +#endif // used by the Int64 functions to determine whether to return a Number // or String based on whether or not a Number will lose precision.