Return a Nan::ObjectWrap from another Nan::ObjectWrap

帅比萌擦擦* 提交于 2019-12-05 17:10:25

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.

  1. Create static NewInstance method in a first class which receives pointer of itself (NewInstance)
  2. 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)
  3. 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)
  4. Use ...::NewInstance() in second class to set return value
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!