Chandler Freeman Chandler Freeman - 2 months ago 14
Node.js Question

How can I get a v8 function to return a c++ object?

I'm currently trying to update a C++ library wrapper for Node.js. Currently it uses Nan 1.0 and I need to convert it to use the latest version, Nan 2.0. However, I have run into an interesting problem. I have these two lines:

Local<Object> obj;
obj = Nan::Get(result_object, conns[i].from_neuron).As<Object>();


When compiled using node-gyp, I receive the error

../src/fann-accs.cc:286:59: error: ‘Nan::MaybeLocal<v8::Value>’ has no member named ‘As’
obj = Nan::Get(result_object, conns[i].from_neuron).As<Object>();


How can I get the Nan::Get function to return a c++ object?

Answer

Fixed by changing the line from

obj = Nan::Get(result_object, conns[i].from_neuron).As<Object>();

to

obj = result_object->Get(conns[i].from_neuron).As<Object>();

Comments