David Carpenter
David Carpenter

Reputation: 1680

Node js, passing a javascript function into an add on and storing it

I am developing a Node.js extension and I would like to pass a javascript function into it that can be called later from the c++ code. If I store the javascript function in my wrapper class and call it right when it is passed in it works fine, however if I store it and try to call it later i get the following error:

node: /home/david/.node-gyp/0.10.28/src/node_object_wrap.h:61: static T*    
node::ObjectWrap::Unwrap(v8::Handle<v8::Object>) [with T = Queue]: Assertion       
`handle->InternalFieldCount() > 0' failed.

I am trying to accomplish something like

var callback = require('my_addon');
callback.setCallback(function(){ console.log("test"); } // works fine if i call the function fron setCallback
callback.callCallback(); // gives that error if i try calling it from here

Does anyone know if this is possible in Node.js?

Upvotes: 0

Views: 475

Answers (1)

David Carpenter
David Carpenter

Reputation: 1680

Got it, you have to store the value in a Persistent rather than a Local

Upvotes: 1

Related Questions