forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachetestqobject_wrap.cpp
More file actions
64 lines (55 loc) · 2.16 KB
/
cachetestqobject_wrap.cpp
File metadata and controls
64 lines (55 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "test/cachetestqobject_wrap.h"
#include "Extras/Utils/nutils.h"
#include "core/WrapperCache/wrappercache.h"
Napi::FunctionReference CacheTestQObjectWrap::constructor;
Napi::Object CacheTestQObjectWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "CacheTestQObject";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("foo", &CacheTestQObjectWrap::foo),
InstanceMethod("clearFoo", &CacheTestQObjectWrap::clearFoo),
InstanceMethod("bar", &CacheTestQObjectWrap::bar),
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(CacheTestQObjectWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
QOBJECT_REGISTER_WRAPPER(CacheTestQObject, CacheTestQObjectWrap);
return exports;
}
CacheTestQObject* CacheTestQObjectWrap::getInternalInstance() {
return this->instance;
}
CacheTestQObjectWrap::CacheTestQObjectWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<CacheTestQObjectWrap>(info) {
Napi::Env env = info.Env();
if (info.Length() == 1 && info[0].IsExternal()) {
this->instance = info[0].As<Napi::External<CacheTestQObject>>().Data();
} else {
if (info.Length() == 0) {
this->instance = new CacheTestQObject();
} else {
Napi::TypeError::New(env,
"Wrong number of arguments to CacheTestQObject.")
.ThrowAsJavaScriptException();
}
}
this->rawData = extrautils::configureQObject(this->getInternalInstance());
}
void CacheTestQObjectWrap::connectSignalsToEventEmitter() {
QOBJECT_SIGNALS_ON_TARGET(this->instance.data());
}
Napi::Value CacheTestQObjectWrap::foo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
CacheTestQObject* foo = this->instance->foo();
return WrapperCache::instance.getWrapper(env, foo);
}
Napi::Value CacheTestQObjectWrap::clearFoo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->instance->clearFoo();
return env.Null();
}
Napi::Value CacheTestQObjectWrap::bar(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
CacheTestQObject* bar = this->instance->bar();
return WrapperCache::instance.getWrapper(env, bar);
}