Creating an instance of a JavaScript object is easy, for example;
myObj1 = new myObject("Object1");
Next step is to call a node.js c++ addon which triggers a callback to the Javascript object...
myAddon = require('myAddon');
myAddon.greet(myObj1.name);
Here is the c++ callback code snippet:
Local<Function> callback = Local<Function>::Cast(args[0]);
Isolate* isolate = args.GetIsolate();
const int argc = 1;
const char *parm = "Hello";
v8::Local<v8::Value> argv[argc] = { v8::String::NewFromUtf8(isolate, parm) };
callback->Call(isolate->GetCurrentContext()->Global(), argc, argv);
Encountering a problem where the binding doesn't correctly callback to the specified instance of myObject, but instead seems to go back to the base JavaScript class. Thus, causing a loss of instance data.
After extensive research in the past couple of days, it appears that the first parameter passed to the Call() method serves as the "this" pointer in v8. Could the issue lie in using a Global context?
If anyone has insights on how to accurately callback to a JavaScript object stored on the heap, please share.