diff --git a/src/cpp/include/nodegui/QtGui/QApplication/napplication.hpp b/src/cpp/include/nodegui/QtGui/QApplication/napplication.hpp index ebbb881b5..7280d9336 100644 --- a/src/cpp/include/nodegui/QtGui/QApplication/napplication.hpp +++ b/src/cpp/include/nodegui/QtGui/QApplication/napplication.hpp @@ -30,7 +30,7 @@ class DLL_EXPORT NApplication : public QApplication, public EventWidget { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); auto instance = - WrapperCache::instance.get(env, screen, false); + WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); this->emitOnNode.Call( {Napi::String::New(env, "primaryScreenChanged"), instance}); }); @@ -39,7 +39,7 @@ class DLL_EXPORT NApplication : public QApplication, public EventWidget { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); auto instance = - WrapperCache::instance.get(env, screen, false); + WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); this->emitOnNode.Call({Napi::String::New(env, "screenAdded"), instance}); }); @@ -48,7 +48,7 @@ class DLL_EXPORT NApplication : public QApplication, public EventWidget { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); auto instance = - WrapperCache::instance.get(env, screen, false); + WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); this->emitOnNode.Call( {Napi::String::New(env, "screenRemoved"), instance}); }); diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index c9a0d0355..4dd0f1c27 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -427,7 +427,7 @@ Napi::Env env = info.Env(); \ QWindow* window = this->instance->windowHandle(); \ if (window) { \ - return WrapperCache::instance.get(env, window, false); \ + return WrapperCache::instance.get(env, window, &QWindowWrap::constructor, false); \ } else { \ return env.Null(); \ } \ diff --git a/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h b/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h index 984820bd3..2e379d5fb 100644 --- a/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h +++ b/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h @@ -44,8 +44,8 @@ class DLL_EXPORT WrapperCache : public QObject { * @param object - Pointer to the QObject for which a wrapper is required. * @return The JS wrapper object. */ - template - Napi::Object get(Napi::Env env, T* object, bool isCreatedByNodeGui) { + template + Napi::Object get(Napi::Env env, T* object, Napi::FunctionReference* constructorFunc, bool isCreatedByNodeGui) { uint64_t ptrHash = extrautils::hashPointerTo53bit(object); if (this->cache.contains(ptrHash)) { napi_value result = nullptr; @@ -58,8 +58,7 @@ class DLL_EXPORT WrapperCache : public QObject { } } - Napi::Object wrapper = - W::constructor.New({Napi::External::New(env, object)}); + Napi::Object wrapper = constructorFunc->New({Napi::External::New(env, object)}); store(env, extrautils::hashPointerTo53bit(object), object, wrapper, isCreatedByNodeGui); return wrapper; diff --git a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp index 964fcb56c..a17e33367 100644 --- a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp +++ b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp @@ -118,8 +118,8 @@ Napi::Value StaticQApplicationWrapMethods::clipboard( Napi::Env env = info.Env(); QClipboard* clipboard = QApplication::clipboard(); if (clipboard) { - return WrapperCache::instance.get(env, - clipboard, false); + return WrapperCache::instance.get(env, + clipboard, &QClipboardWrap::constructor, false); } else { return env.Null(); } @@ -163,7 +163,7 @@ Napi::Value StaticQApplicationWrapMethods::primaryScreen( Napi::Env env = info.Env(); auto screen = QApplication::primaryScreen(); if (screen) { - return WrapperCache::instance.get(env, screen, false); + return WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); } else { return env.Null(); } @@ -177,7 +177,7 @@ Napi::Value StaticQApplicationWrapMethods::screens( for (int i = 0; i < screens.size(); i++) { QScreen* screen = screens[i]; auto instance = - WrapperCache::instance.get(env, screen, false); + WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); jsArray[i] = instance; } return jsArray; diff --git a/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp index 8412070ff..0058cf299 100644 --- a/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp +++ b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp @@ -56,7 +56,7 @@ void QWindowWrap::connectSignalsToEventEmitter() { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); auto instance = - WrapperCache::instance.get(env, screen, false); + WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); this->emitOnNode.Call( {Napi::String::New(env, "screenChanged"), instance}); }); @@ -81,7 +81,7 @@ Napi::Value QWindowWrap::screen(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); QScreen* screen = this->instance->screen(); if (screen) { - return WrapperCache::instance.get(env, screen, false); + return WrapperCache::instance.get(env, screen, &QScreenWrap::constructor, false); } else { return env.Null(); } diff --git a/src/cpp/lib/test/cachetestqobject_wrap.cpp b/src/cpp/lib/test/cachetestqobject_wrap.cpp index 9beca174f..2f2624d51 100644 --- a/src/cpp/lib/test/cachetestqobject_wrap.cpp +++ b/src/cpp/lib/test/cachetestqobject_wrap.cpp @@ -47,8 +47,8 @@ void CacheTestQObjectWrap::connectSignalsToEventEmitter() { Napi::Value CacheTestQObjectWrap::foo(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); CacheTestQObject* foo = this->instance->foo(); - return WrapperCache::instance.get( - env, foo, false); + return WrapperCache::instance.get( + env, foo, &CacheTestQObjectWrap::constructor, false); } Napi::Value CacheTestQObjectWrap::clearFoo(const Napi::CallbackInfo& info) { @@ -60,6 +60,6 @@ Napi::Value CacheTestQObjectWrap::clearFoo(const Napi::CallbackInfo& info) { Napi::Value CacheTestQObjectWrap::bar(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); CacheTestQObject* bar = this->instance->bar(); - return WrapperCache::instance.get( - env, bar, false); + return WrapperCache::instance.get( + env, bar, &CacheTestQObjectWrap::constructor, false); }