Search code examples
node.jsv8embedded-v8

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?


Solution

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