Skip to content

nan2 #1

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "Jacob Groundwater <[email protected]>",
"license": "MIT",
"dependencies": {
"nan": "^1.2.0",
"minimist": "^0.0.10"
"minimist": "^0.0.10",
"nan": "^2.0.9"
},
"bin": {
"century": "century.js"
Expand Down
8 changes: 4 additions & 4 deletions src/binding.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "binding.h"

void InitAll(Handle<Object> exports) {
exports->Set(NanNew<String>("wait"),
NanNew<FunctionTemplate>(Wait)->GetFunction());
exports->Set(NanNew<String>("demo"),
NanNew<FunctionTemplate>(Demo)->GetFunction());
exports->Set(Nan::New<String>("wait").ToLocalChecked(),
Nan::New<FunctionTemplate>(Wait)->GetFunction());
exports->Set(Nan::New<String>("demo").ToLocalChecked(),
Nan::New<FunctionTemplate>(Demo)->GetFunction());
}

NODE_MODULE(binding, InitAll)
4 changes: 2 additions & 2 deletions src/popen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

// this is just for demo purposes
NAN_METHOD(Demo) {
NanScope();
Nan::HandleScope scope;

popen("sleep 30", "r");

NanReturnUndefined();
return;
}
38 changes: 14 additions & 24 deletions src/wait.cc
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
#include "binding.h"

NAN_METHOD(Wait) {
NanScope();

Nan::HandleScope scope;
int status;

// non-blocking

// do not wait for a dead child because this is run on the main event loop
// this method is intended for init, who inherits children that it did not spawn
pid_t ok = waitpid(-1, &status, WNOHANG);

if (ok == 0) {

// no child exited
NanReturnNull();
}
else if (ok == -1) {

// no children
NanReturnUndefined();
}
else {
info.GetReturnValue().Set(Nan::Null());
} else if (ok != -1) {
// we caught a child exiting

// the exit status is an integer containing bits of useful information

Handle<Object> o = NanNew<Object>();
v8::Local<Object> o = Nan::New<Object>();

o->Set(NanNew<String>("_") , NanNew<Number>(status));
o->Set(NanNew<String>("exited") , NanNew<Number>(WIFEXITED(status)));
o->Set(NanNew<String>("status") , NanNew<Number>(WEXITSTATUS(status)));
o->Set(NanNew<String>("signal") , NanNew<Number>(WIFSIGNALED(status)));
o->Set(NanNew<String>("termsig") , NanNew<Number>(WTERMSIG(status)));
o->Set(NanNew<String>("coredump") , NanNew<Number>(WCOREDUMP(status)));
o->Set(NanNew<String>("ifstopped"), NanNew<Number>(WIFSTOPPED(status)));
o->Set(NanNew<String>("stopsig") , NanNew<Number>(WSTOPSIG(status)));
o->Set(NanNew<String>("continued"), NanNew<Number>(WIFCONTINUED(status)));
o->Set(Nan::New<String>("_").ToLocalChecked() , Nan::New<Number>(status));
o->Set(Nan::New<String>("exited").ToLocalChecked() , Nan::New<Number>(WIFEXITED(status)));
o->Set(Nan::New<String>("status").ToLocalChecked() , Nan::New<Number>(WEXITSTATUS(status)));
o->Set(Nan::New<String>("signal").ToLocalChecked() , Nan::New<Number>(WIFSIGNALED(status)));
o->Set(Nan::New<String>("termsig").ToLocalChecked() , Nan::New<Number>(WTERMSIG(status)));
o->Set(Nan::New<String>("coredump").ToLocalChecked() , Nan::New<Number>(WCOREDUMP(status)));
o->Set(Nan::New<String>("ifstopped").ToLocalChecked(), Nan::New<Number>(WIFSTOPPED(status)));
o->Set(Nan::New<String>("stopsig").ToLocalChecked() , Nan::New<Number>(WSTOPSIG(status)));
o->Set(Nan::New<String>("continued").ToLocalChecked(), Nan::New<Number>(WIFCONTINUED(status)));

NanReturnValue(o);
info.GetReturnValue().Set(o);
}
}