From 5e60c76d96c73556445309cb25474f6f09fde018 Mon Sep 17 00:00:00 2001 From: flames of love Date: Thu, 24 Sep 2015 00:38:25 +0200 Subject: [PATCH 1/2] convert to nan2 --- package.json | 4 ++-- src/binding.cc | 8 ++++---- src/popen.cc | 4 ++-- src/wait.cc | 28 ++++++++++++++-------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b10a44a..76035cf 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "author": "Jacob Groundwater ", "license": "MIT", "dependencies": { - "nan": "^1.2.0", - "minimist": "^0.0.10" + "minimist": "^0.0.10", + "nan": "^2.0.9" }, "bin": { "century": "century.js" diff --git a/src/binding.cc b/src/binding.cc index fbbb4a0..3fb0bff 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -1,10 +1,10 @@ #include "binding.h" void InitAll(Handle exports) { - exports->Set(NanNew("wait"), - NanNew(Wait)->GetFunction()); - exports->Set(NanNew("demo"), - NanNew(Demo)->GetFunction()); + exports->Set(Nan::New("wait").ToLocalChecked(), + Nan::New(Wait)->GetFunction()); + exports->Set(Nan::New("demo").ToLocalChecked(), + Nan::New(Demo)->GetFunction()); } NODE_MODULE(binding, InitAll) diff --git a/src/popen.cc b/src/popen.cc index e5d346a..39b4aa8 100644 --- a/src/popen.cc +++ b/src/popen.cc @@ -4,9 +4,9 @@ // this is just for demo purposes NAN_METHOD(Demo) { - NanScope(); + Nan::HandleScope scope; popen("sleep 30", "r"); - NanReturnUndefined(); + return; } diff --git a/src/wait.cc b/src/wait.cc index 08fcb5d..79d1df8 100644 --- a/src/wait.cc +++ b/src/wait.cc @@ -1,7 +1,7 @@ #include "binding.h" NAN_METHOD(Wait) { - NanScope(); + Nan::HandleScope scope; int status; @@ -14,30 +14,30 @@ NAN_METHOD(Wait) { if (ok == 0) { // no child exited - NanReturnNull(); + info.GetReturnValue().Set(Nan::Null()); } else if (ok == -1) { // no children - NanReturnUndefined(); + return; } else { // we caught a child exiting // the exit status is an integer containing bits of useful information - Handle o = NanNew(); + v8::Local o = Nan::New(); - o->Set(NanNew("_") , NanNew(status)); - o->Set(NanNew("exited") , NanNew(WIFEXITED(status))); - o->Set(NanNew("status") , NanNew(WEXITSTATUS(status))); - o->Set(NanNew("signal") , NanNew(WIFSIGNALED(status))); - o->Set(NanNew("termsig") , NanNew(WTERMSIG(status))); - o->Set(NanNew("coredump") , NanNew(WCOREDUMP(status))); - o->Set(NanNew("ifstopped"), NanNew(WIFSTOPPED(status))); - o->Set(NanNew("stopsig") , NanNew(WSTOPSIG(status))); - o->Set(NanNew("continued"), NanNew(WIFCONTINUED(status))); + o->Set(Nan::New("_").ToLocalChecked() , Nan::New(status)); + o->Set(Nan::New("exited").ToLocalChecked() , Nan::New(WIFEXITED(status))); + o->Set(Nan::New("status").ToLocalChecked() , Nan::New(WEXITSTATUS(status))); + o->Set(Nan::New("signal").ToLocalChecked() , Nan::New(WIFSIGNALED(status))); + o->Set(Nan::New("termsig").ToLocalChecked() , Nan::New(WTERMSIG(status))); + o->Set(Nan::New("coredump").ToLocalChecked() , Nan::New(WCOREDUMP(status))); + o->Set(Nan::New("ifstopped").ToLocalChecked(), Nan::New(WIFSTOPPED(status))); + o->Set(Nan::New("stopsig").ToLocalChecked() , Nan::New(WSTOPSIG(status))); + o->Set(Nan::New("continued").ToLocalChecked(), Nan::New(WIFCONTINUED(status))); - NanReturnValue(o); + info.GetReturnValue().Set(o); } } From d08d4d08bb459f756d67f4be99276330a96e7e2f Mon Sep 17 00:00:00 2001 From: flames of love Date: Thu, 24 Sep 2015 00:41:30 +0200 Subject: [PATCH 2/2] cleanup --- src/wait.cc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/wait.cc b/src/wait.cc index 79d1df8..e5cd4c5 100644 --- a/src/wait.cc +++ b/src/wait.cc @@ -2,28 +2,18 @@ NAN_METHOD(Wait) { 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 info.GetReturnValue().Set(Nan::Null()); - } - else if (ok == -1) { - - // no children - return; - } - else { + } else if (ok != -1) { // we caught a child exiting - // the exit status is an integer containing bits of useful information v8::Local o = Nan::New();