I have two subclasses of Nan::ObjectWrap
class Zyre: public Nan::ObjectWrap {...}
class ZyreEvent: public Nan::ObjectWrap {...}
How can I return a ZyreEvent
javascript object from a method in Zyre
?
I have the following method, in which I create a ZyreEvent
:
NAN_METHOD (Zyre::_recv) {
Zyre *node = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
ZyreEvent *zyre_event = new ZyreEvent (node->self);
info.GetReturnValue().Set(zyre_event->Wrap(info.This()));
}
But I can't Wrap the zyre_event because Wrap
is a protected member.
If I understand correctly, you want to return from (subclass of) Nan::ObjectWrap
's method instance of another (subclass of) Nan::ObjectWrap
.
Note: I'm not experienced so this may have faults or be wrong. I've put my sources in brackets where are examples how it's is done I guess.
- Create
static NewInstance
method in a first class which receives pointer of itself (NewInstance)
- Use
v8::External
to wrap first class' C++ object and pass it as an argument for New
with argc
and argv
to first class' constructor (using v8::External) (v8::External doc)
- Edit first class'
New
method and handle info.Length() == 1 && info[0]->IsExternal()
case which is basically copy constructor in this case (copying passed pointer)
- Use
...::NewInstance()
in second class to set return value