I'm working on a Node module, and am trying to pass an instance of a class that subclasses ObjectWrap
as an argument to a JavaScript callback.
In other places I've been able to successfully unwrap JavaScript objects to the same class, using:
GitCommit *commit = ObjectWrap::Unwrap<GitCommit>(args[0]->ToObject());
How might I do the reverse? I want to pass an instance of GitCommit
to a JavaScript callback, like:
Local<Value> argv[] = {
// Error code
Local<Value>::New(Integer::New(0)),
// The commit
commit // Instance of GitCommit : ObjectWrap
};
// Both error code and the commit are passed, JS equiv: callback(error, commit)
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
Is this possible? If so would someone please give me an example, or a link to the relevant documentation?
So you are writing a node addon. Try:
Handle<Value> argv[] = {
// Error code
Integer::New(0),
// The commit
commit->handle_ // Instance of GitCommit : ObjectWrap
};
// Both error code and the commit are passed, JS equiv: callback(error, commit)
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With