I'm new to NAPI, and I'm trying to convert and old Nan code to NAPI.
What happens is that I have a structure like this:
class PointWrapper : public Napi::ObjectWrap<PointWrapper> {
public:
static void init(Napi::Env env, Napi::Object exports);
PointWrapper(const Napi::CallbackInfo& info);
private:
Point point;
}
And I wrapped everything in the right way, so if I call on JS new Pointer(1, 2) it'll instantiate a PointerWrapper and set the right fields to Point. So far, so good.
Now, the problem is that somewhere later I have a C++ code that wraps a Range - a Range is basically start and end, each containing a Point.
I also have RangeWrapper that does the same thing as PointWrapper, but for range. This RangeWrapper have a getStart that basically needs to return a PointWrapper.
Now, how do I instantiate a PointWrapper from RangeWrapper? Basically, I want a constructor on PointWrapper that, giving a Point, I can get a PointWrapper, all this in C++ and not on JS. Is it possible? Every code I saw tried to instantiate from inside PointWrapper, never outside