diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp index f7fdf22..a6a9f84 100644 --- a/include/addon-tools.hpp +++ b/include/addon-tools.hpp @@ -510,6 +510,7 @@ typedef void (*Es5SetterCallback)(const Napi::CallbackInfo& info); #define DECLARE_ES5_CLASS(CLASS, NAME) \ +private: \ static Napi::FunctionReference _ctorEs5; \ static const char *_nameEs5; \ static void CLASS::_finalizeEs5(napi_env e, void *dest, void* hint); \ @@ -589,8 +590,19 @@ typedef void (*Es5SetterCallback)(const Napi::CallbackInfo& info); setter \ ) \ ); \ + }; \ +public: \ + inline static CLASS *unwrap(Napi::Object thatObj) { \ + CLASS *that; \ + napi_unwrap( \ + thatObj.Env(), \ + thatObj.Get(_nameEs5), \ + reinterpret_cast(&that) \ + ); \ + return that; \ }; + #define JS_GET_THAT(CLASS) \ CLASS *that; \ Napi::Object thatObj = info.This().As(); \