In javascript the code i trying to run is
const Element = require("element.node");
let element = new Element();
console.log(element.parent); // null
element.parent = element;
console.log(element.parent === element); // should be true
So in the cpp Element class i have
void Element::SetParent(const Napi::CallbackInfo &info, const Napi::Value &value) {
this->parent = Element::Unwrap(info[0].As<Napi::Object>());
}
but i don't know how to implement the GetParent method, this->parent has the correct pointer but all the exemples i find on internet create a new instance of c++ Element calling js constructor to have an Napi::Object
Can i call some method to reverse Element::Unwrap ?
Like
Napi::Value Element::GetParent(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
if (this->parent == NULL) {
return env.Null();
}
return Napi::Object::Wrap(this->parent);
}