This commit is contained in:
Luis Blanco 2019-11-10 22:50:09 +03:00
parent 46e82f8ea8
commit 77995f76f6
1 changed files with 19 additions and 9 deletions

View File

@ -40,20 +40,19 @@ the second is the name of the setter to be created.
## Class Implementation ## Class Implementation
``` ```
// Some utility stuff
IMPLEMENT_ES5_CLASS(ClassName); IMPLEMENT_ES5_CLASS(ClassName);
// Fill the properties and export the class
void ClassName::init(Napi::Env env, Napi::Object exports) { void ClassName::init(Napi::Env env, Napi::Object exports) {
Napi::Function ctor = wrap(env); Napi::Function ctor = wrap(env);
JS_ASSIGN_METHOD(destroy); JS_ASSIGN_METHOD(destroy);
JS_ASSIGN_GETTER(isDestroyed); JS_ASSIGN_GETTER(isDestroyed);
// ...
exports.Set("JSClassName", ctor); exports.Set("JSClassName", ctor);
} }
Body::Body(const Napi::CallbackInfo &info) { NAPI_ENV; ClassName::ClassName(const Napi::CallbackInfo &info) { NAPI_ENV;
super(info); super(info);
@ -63,15 +62,26 @@ Body::Body(const Napi::CallbackInfo &info) { NAPI_ENV;
} }
Body::~Body() { ClassName::~ClassName() {
_destroy(); _destroy();
} }
void ClassName::_destroy() { DES_CHECK;
void Body::_destroy() { DES_CHECK; // ...
_isDestroyed = true; _isDestroyed = true;
} }
JS_IMPLEMENT_METHOD(ClassName, destroy) { THIS_CHECK;
emit("destroy");
_destroy();
RET_UNDEFINED;
}
JS_IMPLEMENT_GETTER(ClassName, isDestroyed) { THIS_CHECK;
RET_BOOL(_isDestroyed);
}
``` ```