diff --git a/.travis.yml b/.travis.yml index ef8931d..6d91f06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: + - "12" - "10" - "8" - "6" - - "4" os: - linux diff --git a/appveyor.yml b/appveyor.yml index cfc3147..d65ecf5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,11 +2,11 @@ environment: NODE_PRE_GYP_GITHUB_TOKEN: secure: I1J9L1ylzwS2WgQh67uUdYifKjCLGL7CibDFxpUgEjT9sNBsyjpljByCQw6jHt2F matrix: + - nodejs_version: "12" - nodejs_version: "10" - nodejs_version: "9" - nodejs_version: "8" - nodejs_version: "6" - - nodejs_version: "4" platform: - x64 diff --git a/binding.gyp b/binding.gyp index d54023c..ddd49bc 100644 --- a/binding.gyp +++ b/binding.gyp @@ -5,7 +5,7 @@ "product_extension": "node", "defines": [ "V8_DEPRECATION_WARNINGS=1" ], "include_dirs": [ - "=4.0.0" + "node": ">=6.0.0" }, "dependencies": { - "nan": "^2.10.0", + "node-addon-api": "*", "node-pre-gyp": "=0.9.1" }, "devDependencies": { diff --git a/src/node-windows-kill.cpp b/src/node-windows-kill.cpp index 1e6567e..43d019d 100644 --- a/src/node-windows-kill.cpp +++ b/src/node-windows-kill.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "windows-kill-library.h" @@ -6,22 +6,23 @@ using WindowsKillLibrary::sendSignal; using WindowsKillLibrary::warmUp; using WindowsKillLibrary::SIGNAL_TYPE_CTRL_C; using WindowsKillLibrary::SIGNAL_TYPE_CTRL_BREAK; - #define NODEWINDOWSKILL_VERSION "0.3.0" -void send(const Nan::FunctionCallbackInfo& info) { +Napi::Value SendSig(const Napi::CallbackInfo &info) { + Napi::Env env = info.Env(); if (info.Length() < 2) { - Nan::ThrowTypeError("Wrong number of arguments"); - return; + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); } - if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - Nan::ThrowTypeError("Wrong arguments"); - return; + if (!info[0].IsNumber() || !info[1].IsNumber()) { + Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); } - DWORD signal_pid = (DWORD)info[0]->NumberValue(); - DWORD signal_type = (DWORD)info[1]->NumberValue(); + DWORD signal_pid = (DWORD)info[0].As().Int32Value(); + DWORD signal_type = (DWORD)info[1].As().Int32Value(); try { if (signal_type == 1) { @@ -30,48 +31,47 @@ void send(const Nan::FunctionCallbackInfo& info) { else { sendSignal(signal_pid, SIGNAL_TYPE_CTRL_C); } - info.GetReturnValue().Set(0); + // info.GetReturnValue().Set(0); + return Napi::Number::New(env,0); } catch (const std::invalid_argument& exception) { if (strcmp(exception.what(), "ESRCH") == 0) { - info.GetReturnValue().Set(Nan::New("ESRCH").ToLocalChecked()); - return; + return Napi::String::New(env, "ESRCH"); } - info.GetReturnValue().Set(Nan::New("ESYS").ToLocalChecked()); + return Napi::String::New(env, "ESYS"); } catch (const std::runtime_error& exception) { if (strcmp(exception.what(), "EPERM") == 0) { - info.GetReturnValue().Set(Nan::New("EPERM").ToLocalChecked()); - return; + return Napi::String::New(env, "EPERM"); } - info.GetReturnValue().Set(Nan::New("ESYS").ToLocalChecked()); + return Napi::String::New(env, "ESYS"); } catch (std::exception) { - info.GetReturnValue().Set(Nan::New("ESYS").ToLocalChecked()); + return Napi::String::New(env, "ESYS"); } } -void warmUp(const Nan::FunctionCallbackInfo& info) { +Napi::Value WarmUp(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); try { warmUp(); } catch (const std::invalid_argument& exception) { if (strcmp(exception.what(), "Invalid which argument.") == 0) { - info.GetReturnValue().Set(Nan::New("Invalid which argument.").ToLocalChecked()); - return; + return Napi::String::New(env, "Invalid which argument."); } - info.GetReturnValue().Set(Nan::New("ESYS").ToLocalChecked()); + return Napi::String::New(env, "ESYS"); } catch (std::exception) { - info.GetReturnValue().Set(Nan::New("ESYS").ToLocalChecked()); + return Napi::String::New(env, "ESYS"); } + return env.Null(); } -void Init(v8::Local exports) { - exports->Set(Nan::New("send").ToLocalChecked(), - Nan::New(send)->GetFunction()); - exports->Set(Nan::New("warmUp").ToLocalChecked(), - Nan::New(warmUp)->GetFunction()); +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports.Set(Napi::String::New(env, "send"), Napi::Function::New(env, SendSig)); + exports.Set(Napi::String::New(env, "warmUp"), Napi::Function::New(env, WarmUp)); + return exports; } -NODE_MODULE(windowskill, Init) +NODE_API_MODULE(windowskill, Init) \ No newline at end of file