-
Notifications
You must be signed in to change notification settings - Fork 74
Initial support for javascript callbacks for node >= 0.12 running on linux #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Initial support for javascript callbacks for node >= 0.12 running on linux
This breaks with node.js 0.10:
|
Thanks @papandreou |
Makes sense, I'll take a look at implementing this in a NAN friendly way. |
a Nan friendly way: // Globals:
static bool has_user_callback = false;
static Nan::Persistent<v8::Function> user_defined_callback{};
// add to RegisterHandler:
if (info.Length() > 1) {
user_defined_callback.Reset(info[1].As<v8::Function>());
has_user_callback = true;
}
// add to SEGFAULT_HANDLER:
if(has_user_callback) {
Isolate* isolate = Isolate::GetCurrent();
Local<Function> cb = New(user_defined_callback);
const unsigned int argc = 3;
Local<Value> argv[argc] ={String::NewFromUtf8(isolate, "hello world"),
String::NewFromUtf8(isolate, "hello world"),
String::NewFromUtf8(isolate, "hello world")
};
cb->Call(Null(isolate), argc, argv);
has_user_callback = false;
user_defined_callback.Reset(); // destroy persistent object
} the bool has_user_callback is probably already integrated in Nan::Persistent and could be replaced (if you're striving for elegance). for the windows part of this issue i wrote some stuff in #38 tested with node 6.9.4 |
Inspired by #11 and updated to support newer versions of Node.js as well as proper handling of cross-thread callbacks.
I haven't had the time to look into what it would take to get it fully implemented for Windows, it would need a dependency or alternative for pthreads and a way to get the stack array from StackWalker.
Regardless, it should still build and run the same as always on Windows, just without callback support.