node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

Call Local<Function> with ObjectWrap as argument

Open ghost opened this issue 9 years ago • 2 comments

I cannot find any information on how to create an ObjectWrap and pass it as an argument to a Local<Function>. I have a persistent callback registered and need to call it with a new instance of an ObjectWrap. I could do this by calling the (JS) constructor and pass it (JS) arguments which returns a new instance, but I want to avoid this round tripping.

Basically: how to create an ObjectWrap and get a Local<Value> out of it so that I can pass it as an argument to a JS function?

ghost avatar Jan 29 '16 03:01 ghost

You can get a v8::Local<v8::Object> from an ObjectWrap by calling its Handle() method.

tomjakubowski avatar Feb 11 '16 22:02 tomjakubowski

Hi.

Thanks for the interest. The problem is (was) that I had no Object in the first place. I wanted to create an object. I solved this by using the ObjectTemplate and a HandleScope (I have now gone from using ObjectWrap to using pure V8 calls).

ghost avatar Feb 11 '16 22:02 ghost