diff --git a/package.json b/package.json index 20272fc8a..ef220f58d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "prepublish": "npm run tsc" }, "dependencies": { - "nan": "2.12.1" + "nan": "^2.13.2" }, "devDependencies": { "@types/mocha": "^5.0.0", diff --git a/src/unix/pty.cc b/src/unix/pty.cc index 57121b678..56581e7cf 100644 --- a/src/unix/pty.cc +++ b/src/unix/pty.cc @@ -151,7 +151,7 @@ NAN_METHOD(PtyFork) { signal(SIGINT, SIG_DFL); // file - v8::String::Utf8Value file(info[0]->ToString()); + Nan::Utf8String file(info[0]); // args int i = 0; @@ -162,7 +162,7 @@ NAN_METHOD(PtyFork) { argv[0] = strdup(*file); argv[argl-1] = NULL; for (; i < argc; i++) { - v8::String::Utf8Value arg(argv_->Get(Nan::New(i))->ToString()); + Nan::Utf8String arg(Nan::Get(argv_, i).ToLocalChecked()); argv[i+1] = strdup(*arg); } @@ -173,18 +173,18 @@ NAN_METHOD(PtyFork) { char **env = new char*[envc+1]; env[envc] = NULL; for (; i < envc; i++) { - v8::String::Utf8Value pair(env_->Get(Nan::New(i))->ToString()); + Nan::Utf8String pair(Nan::Get(env_, i).ToLocalChecked()); env[i] = strdup(*pair); } // cwd - v8::String::Utf8Value cwd_(info[3]->ToString()); + Nan::Utf8String cwd_(info[3]); char *cwd = strdup(*cwd_); // size struct winsize winp; - winp.ws_col = info[4]->IntegerValue(); - winp.ws_row = info[5]->IntegerValue(); + winp.ws_col = info[4]->IntegerValue(Nan::GetCurrentContext()).FromJust(); + winp.ws_row = info[5]->IntegerValue(Nan::GetCurrentContext()).FromJust(); winp.ws_xpixel = 0; winp.ws_ypixel = 0; @@ -192,7 +192,7 @@ NAN_METHOD(PtyFork) { struct termios t = termios(); struct termios *term = &t; term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT; - if (info[8]->ToBoolean()->Value()) { + if (info[8]->BooleanValue(Nan::GetCurrentContext()).FromJust()) { #if defined(IUTF8) term->c_iflag |= IUTF8; #endif @@ -227,8 +227,8 @@ NAN_METHOD(PtyFork) { cfsetospeed(term, B38400); // uid / gid - int uid = info[6]->IntegerValue(); - int gid = info[7]->IntegerValue(); + int uid = info[6]->IntegerValue(Nan::GetCurrentContext()).FromJust(); + int gid = info[7]->IntegerValue(Nan::GetCurrentContext()).FromJust(); // fork the pty int master = -1; @@ -312,8 +312,8 @@ NAN_METHOD(PtyOpen) { // size struct winsize winp; - winp.ws_col = info[0]->IntegerValue(); - winp.ws_row = info[1]->IntegerValue(); + winp.ws_col = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(); + winp.ws_row = info[1]->IntegerValue(Nan::GetCurrentContext()).FromJust(); winp.ws_xpixel = 0; winp.ws_ypixel = 0; @@ -357,11 +357,11 @@ NAN_METHOD(PtyResize) { return Nan::ThrowError("Usage: pty.resize(fd, cols, rows)"); } - int fd = info[0]->IntegerValue(); + int fd = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(); struct winsize winp; - winp.ws_col = info[1]->IntegerValue(); - winp.ws_row = info[2]->IntegerValue(); + winp.ws_col = info[1]->IntegerValue(Nan::GetCurrentContext()).FromJust(); + winp.ws_row = info[2]->IntegerValue(Nan::GetCurrentContext()).FromJust(); winp.ws_xpixel = 0; winp.ws_ypixel = 0; @@ -384,9 +384,9 @@ NAN_METHOD(PtyGetProc) { return Nan::ThrowError("Usage: pty.process(fd, tty)"); } - int fd = info[0]->IntegerValue(); + int fd = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(); - v8::String::Utf8Value tty_(info[1]->ToString()); + Nan::Utf8String tty_(info[1]); char *tty = strdup(*tty_); char *name = pty_getproc(fd, tty); free(tty); @@ -700,18 +700,10 @@ pty_forkpty(int *amaster, NAN_MODULE_INIT(init) { Nan::HandleScope scope; - Nan::Set(target, - Nan::New("fork").ToLocalChecked(), - Nan::New(PtyFork)->GetFunction()); - Nan::Set(target, - Nan::New("open").ToLocalChecked(), - Nan::New(PtyOpen)->GetFunction()); - Nan::Set(target, - Nan::New("resize").ToLocalChecked(), - Nan::New(PtyResize)->GetFunction()); - Nan::Set(target, - Nan::New("process").ToLocalChecked(), - Nan::New(PtyGetProc)->GetFunction()); + Nan::Export(target, "fork", PtyFork); + Nan::Export(target, "open", PtyOpen); + Nan::Export(target, "resize", PtyResize); + Nan::Export(target, "process", PtyGetProc); } NODE_MODULE(pty, init) diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index 860f3660b..f734653ea 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -3,7 +3,6 @@ * Copyright (c) 2016, Daniel Imms (MIT License). * Copyright (c) 2018, Microsoft Corporation (MIT License). */ - import * as net from 'net'; import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal'; import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces'; @@ -276,11 +275,10 @@ export class UnixTerminal extends Terminal { */ class PipeSocket extends net.Socket { constructor(fd: number) { - const tty = (process).binding('tty_wrap'); - const guessHandleType = tty.guessHandleType; - tty.guessHandleType = () => 'PIPE'; + const { Pipe, constants } = (process).binding('pipe_wrap'); // tslint:disable-line // @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275 - super({ fd: fd }); - tty.guessHandleType = guessHandleType; + const handle = new Pipe(constants.SOCKET); + handle.open(fd); + super({ handle }); } } diff --git a/src/win/conpty.cc b/src/win/conpty.cc index 1b5a74949..c3213ba32 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -18,7 +18,7 @@ #include #include "path_util.h" -extern "C" void init(v8::Handle); +extern "C" void init(v8::Local); // Taken from the RS5 Windows SDK, but redefined here in case we're targeting <= 17134 #ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE @@ -40,7 +40,7 @@ struct pty_baton { HANDLE hShell; HANDLE hWait; - Nan::Persistent cb; + Nan::Callback cb; uv_async_t async; uv_thread_t tid; @@ -170,11 +170,11 @@ static NAN_METHOD(PtyStartProcess) { return; } - const std::wstring filename(path_util::to_wstring(v8::String::Utf8Value(info[0]->ToString()))); - const SHORT cols = info[1]->Uint32Value(); - const SHORT rows = info[2]->Uint32Value(); - const bool debug = info[3]->ToBoolean()->IsTrue(); - const std::wstring pipeName(path_util::to_wstring(v8::String::Utf8Value(info[4]->ToString()))); + const std::wstring filename(path_util::to_wstring(Nan::Utf8String(info[0]))); + const SHORT cols = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + const SHORT rows = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + const bool debug = info[3]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->IsTrue(); + const std::wstring pipeName(path_util::to_wstring(Nan::Utf8String(info[4]))); // use environment 'Path' variable to determine location of // the relative path that we have recieved (e.g cmd.exe) @@ -204,20 +204,20 @@ static NAN_METHOD(PtyStartProcess) { if (SUCCEEDED(hr)) { // We were able to instantiate a conpty const int ptyId = InterlockedIncrement(&ptyCounter); - marshal->Set(Nan::New("pty").ToLocalChecked(), Nan::New(ptyId)); + Nan::Set(marshal, Nan::New("pty").ToLocalChecked(), Nan::New(ptyId)); ptyHandles.insert(ptyHandles.end(), new pty_baton(ptyId, hIn, hOut, hpc)); } else { Nan::ThrowError("Cannot launch conpty"); return; } - marshal->Set(Nan::New("fd").ToLocalChecked(), Nan::New(-1)); + Nan::Set(marshal, Nan::New("fd").ToLocalChecked(), Nan::New(-1)); { std::string coninPipeNameStr(inName.begin(), inName.end()); - marshal->Set(Nan::New("conin").ToLocalChecked(), Nan::New(coninPipeNameStr).ToLocalChecked()); + Nan::Set(marshal, Nan::New("conin").ToLocalChecked(), Nan::New(coninPipeNameStr).ToLocalChecked()); std::string conoutPipeNameStr(outName.begin(), outName.end()); - marshal->Set(Nan::New("conout").ToLocalChecked(), Nan::New(conoutPipeNameStr).ToLocalChecked()); + Nan::Set(marshal, Nan::New("conout").ToLocalChecked(), Nan::New(conoutPipeNameStr).ToLocalChecked()); } info.GetReturnValue().Set(marshal); } @@ -242,12 +242,12 @@ static void OnProcessExit(uv_async_t *async) { GetExitCodeProcess(baton->hShell, &exitCode); // Call function - v8::Handle args[1] = { + v8::Local args[1] = { Nan::New(exitCode) }; - v8::Handle local = Nan::New(baton->cb); - local->Call(Nan::GetCurrentContext()->Global(), 1, args); + Nan::AsyncResource asyncResource("node-pty.callback"); + baton->cb.Call(1, args, &asyncResource); // Clean up baton->cb.Reset(); } @@ -272,10 +272,10 @@ static NAN_METHOD(PtyConnect) { return; } - const int id = info[0]->Int32Value(); - const std::wstring cmdline(path_util::to_wstring(v8::String::Utf8Value(info[1]->ToString()))); - const std::wstring cwd(path_util::to_wstring(v8::String::Utf8Value(info[2]->ToString()))); - const v8::Handle envValues = info[3].As(); + const int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + const std::wstring cmdline(path_util::to_wstring(Nan::Utf8String(info[1]))); + const std::wstring cwd(path_util::to_wstring(Nan::Utf8String(info[2]))); + const v8::Local envValues = info[3].As(); const v8::Local exitCallback = v8::Local::Cast(info[4]); // Prepare command line @@ -291,7 +291,7 @@ static NAN_METHOD(PtyConnect) { if (!envValues.IsEmpty()) { std::wstringstream envBlock; for(uint32_t i = 0; i < envValues->Length(); i++) { - std::wstring envValue(path_util::to_wstring(v8::String::Utf8Value(envValues->Get(i)->ToString()))); + std::wstring envValue(path_util::to_wstring(Nan::Utf8String(Nan::Get(envValues, i).ToLocalChecked()))); envBlock << envValue << L'\0'; } envBlock << L'\0'; @@ -309,12 +309,12 @@ static NAN_METHOD(PtyConnect) { // Attach the pseudoconsole to the client application we're creating STARTUPINFOEXW siEx{0}; siEx.StartupInfo.cb = sizeof(STARTUPINFOEXW); - PSIZE_T size; - InitializeProcThreadAttributeList(NULL, 1, 0, size); - BYTE *attrList = new BYTE[*size]; + SIZE_T size = 0; + InitializeProcThreadAttributeList(NULL, 1, 0, &size); + BYTE *attrList = new BYTE[size]; siEx.lpAttributeList = reinterpret_cast(attrList); - fSuccess = InitializeProcThreadAttributeList(siEx.lpAttributeList, 1, 0, size); + fSuccess = InitializeProcThreadAttributeList(siEx.lpAttributeList, 1, 0, &size); if (!fSuccess) { return throwNanError(&info, "InitializeProcThreadAttributeList failed", true); } @@ -359,7 +359,7 @@ static NAN_METHOD(PtyConnect) { // Return v8::Local marshal = Nan::New(); - marshal->Set(Nan::New("pid").ToLocalChecked(), Nan::New(piClient.dwProcessId)); + Nan::Set(marshal, Nan::New("pid").ToLocalChecked(), Nan::New(piClient.dwProcessId)); info.GetReturnValue().Set(marshal); } @@ -374,9 +374,9 @@ static NAN_METHOD(PtyResize) { return; } - int id = info[0]->Int32Value(); - SHORT cols = info[1]->Uint32Value(); - SHORT rows = info[2]->Uint32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + SHORT cols = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + SHORT rows = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); const pty_baton* handle = get_pty_baton(id); @@ -404,7 +404,7 @@ static NAN_METHOD(PtyKill) { return; } - int id = info[0]->Int32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); const pty_baton* handle = get_pty_baton(id); @@ -428,7 +428,7 @@ static NAN_METHOD(PtyKill) { * Init */ -extern "C" void init(v8::Handle target) { +extern "C" void init(v8::Local target) { Nan::HandleScope scope; Nan::SetMethod(target, "startProcess", PtyStartProcess); Nan::SetMethod(target, "connect", PtyConnect); diff --git a/src/win/conpty_console_list.cc b/src/win/conpty_console_list.cc index 72102360e..be135ba02 100644 --- a/src/win/conpty_console_list.cc +++ b/src/win/conpty_console_list.cc @@ -12,7 +12,7 @@ static NAN_METHOD(ApiConsoleProcessList) { return; } - const SHORT pid = info[0]->Uint32Value(); + const SHORT pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (!FreeConsole()) { Nan::ThrowError("FreeConsole failed"); @@ -30,12 +30,12 @@ static NAN_METHOD(ApiConsoleProcessList) { v8::Local result = Nan::New(); for (DWORD i = 0; i < processCount; i++) { - result->Set(i, Nan::New(processList[i])); + Nan::Set(result, i, Nan::New(processList[i])); } info.GetReturnValue().Set(result); } -extern "C" void init(v8::Handle target) { +extern "C" void init(v8::Local target) { Nan::HandleScope scope; Nan::SetMethod(target, "getConsoleProcessList", ApiConsoleProcessList); }; diff --git a/src/win/path_util.cc b/src/win/path_util.cc index 4387d2550..4e69f3091 100644 --- a/src/win/path_util.cc +++ b/src/win/path_util.cc @@ -11,7 +11,7 @@ namespace path_util { -const wchar_t* to_wstring(const v8::String::Utf8Value& str) { +const wchar_t* to_wstring(const Nan::Utf8String& str) { const char *bytes = *str; unsigned int sizeOfStr = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, NULL, 0); wchar_t *output = new wchar_t[sizeOfStr]; diff --git a/src/win/path_util.h b/src/win/path_util.h index 2bfcabf19..8dd58d25e 100644 --- a/src/win/path_util.h +++ b/src/win/path_util.h @@ -13,7 +13,7 @@ namespace path_util { -const wchar_t* to_wstring(const v8::String::Utf8Value& str); +const wchar_t* to_wstring(const Nan::Utf8String& str); bool file_exists(std::wstring filename); std::wstring get_shell_path(std::wstring filename); diff --git a/src/win/winpty.cc b/src/win/winpty.cc index 1b5e6b350..614938a35 100644 --- a/src/win/winpty.cc +++ b/src/win/winpty.cc @@ -23,7 +23,7 @@ /** * Misc */ -extern "C" void init(v8::Handle); +extern "C" void init(v8::Local); #define WINPTY_DBG_VARIABLE TEXT("WINPTYDBG") @@ -80,7 +80,7 @@ static NAN_METHOD(PtyGetExitCode) { } DWORD exitCode = 0; - GetExitCodeProcess((HANDLE)info[0]->IntegerValue(), &exitCode); + GetExitCodeProcess((HANDLE)info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(), &exitCode); info.GetReturnValue().Set(Nan::New(exitCode)); } @@ -94,7 +94,7 @@ static NAN_METHOD(PtyGetProcessList) { return; } - int pid = info[0]->Int32Value(); + int pid = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); winpty_t *pc = get_pipe_handle(pid); if (pc == nullptr) { @@ -129,19 +129,19 @@ static NAN_METHOD(PtyStartProcess) { std::stringstream why; - const wchar_t *filename = path_util::to_wstring(v8::String::Utf8Value(info[0]->ToString())); - const wchar_t *cmdline = path_util::to_wstring(v8::String::Utf8Value(info[1]->ToString())); - const wchar_t *cwd = path_util::to_wstring(v8::String::Utf8Value(info[3]->ToString())); + const wchar_t *filename = path_util::to_wstring(Nan::Utf8String(info[0])); + const wchar_t *cmdline = path_util::to_wstring(Nan::Utf8String(info[1])); + const wchar_t *cwd = path_util::to_wstring(Nan::Utf8String(info[3])); // create environment block std::wstring env; - const v8::Handle envValues = v8::Handle::Cast(info[2]); + const v8::Local envValues = v8::Local::Cast(info[2]); if (!envValues.IsEmpty()) { std::wstringstream envBlock; for(uint32_t i = 0; i < envValues->Length(); i++) { - std::wstring envValue(path_util::to_wstring(v8::String::Utf8Value(envValues->Get(i)->ToString()))); + std::wstring envValue(path_util::to_wstring(Nan::Utf8String(Nan::Get(envValues, i).ToLocalChecked()))); envBlock << envValue << L'\0'; } @@ -165,9 +165,9 @@ static NAN_METHOD(PtyStartProcess) { goto cleanup; } - int cols = info[4]->Int32Value(); - int rows = info[5]->Int32Value(); - bool debug = info[6]->ToBoolean()->IsTrue(); + int cols = info[4]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int rows = info[5]->Int32Value(Nan::GetCurrentContext()).FromJust(); + bool debug = info[6]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->IsTrue(); // Enable/disable debugging SetEnvironmentVariable(WINPTY_DBG_VARIABLE, debug ? "1" : NULL); // NULL = deletes variable @@ -216,20 +216,20 @@ static NAN_METHOD(PtyStartProcess) { // Set return values v8::Local marshal = Nan::New(); - marshal->Set(Nan::New("innerPid").ToLocalChecked(), Nan::New((int)GetProcessId(handle))); - marshal->Set(Nan::New("innerPidHandle").ToLocalChecked(), Nan::New((int)handle)); - marshal->Set(Nan::New("pid").ToLocalChecked(), Nan::New((int)winpty_agent_process(pc))); - marshal->Set(Nan::New("pty").ToLocalChecked(), Nan::New(InterlockedIncrement(&ptyCounter))); - marshal->Set(Nan::New("fd").ToLocalChecked(), Nan::New(-1)); + Nan::Set(marshal, Nan::New("innerPid").ToLocalChecked(), Nan::New((int)GetProcessId(handle))); + Nan::Set(marshal, Nan::New("innerPidHandle").ToLocalChecked(), Nan::New((int)handle)); + Nan::Set(marshal, Nan::New("pid").ToLocalChecked(), Nan::New((int)winpty_agent_process(pc))); + Nan::Set(marshal, Nan::New("pty").ToLocalChecked(), Nan::New(InterlockedIncrement(&ptyCounter))); + Nan::Set(marshal, Nan::New("fd").ToLocalChecked(), Nan::New(-1)); { LPCWSTR coninPipeName = winpty_conin_name(pc); std::wstring coninPipeNameWStr(coninPipeName); std::string coninPipeNameStr(coninPipeNameWStr.begin(), coninPipeNameWStr.end()); - marshal->Set(Nan::New("conin").ToLocalChecked(), Nan::New(coninPipeNameStr).ToLocalChecked()); + Nan::Set(marshal, Nan::New("conin").ToLocalChecked(), Nan::New(coninPipeNameStr).ToLocalChecked()); LPCWSTR conoutPipeName = winpty_conout_name(pc); std::wstring conoutPipeNameWStr(conoutPipeName); std::string conoutPipeNameStr(conoutPipeNameWStr.begin(), conoutPipeNameWStr.end()); - marshal->Set(Nan::New("conout").ToLocalChecked(), Nan::New(conoutPipeNameStr).ToLocalChecked()); + Nan::Set(marshal, Nan::New("conout").ToLocalChecked(), Nan::New(conoutPipeNameStr).ToLocalChecked()); } info.GetReturnValue().Set(marshal); @@ -252,9 +252,9 @@ static NAN_METHOD(PtyResize) { return; } - int handle = info[0]->Int32Value(); - int cols = info[1]->Int32Value(); - int rows = info[2]->Int32Value(); + int handle = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int cols = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int rows = info[2]->Int32Value(Nan::GetCurrentContext()).FromJust(); winpty_t *pc = get_pipe_handle(handle); @@ -281,8 +281,8 @@ static NAN_METHOD(PtyKill) { return; } - int handle = info[0]->Int32Value(); - HANDLE innerPidHandle = (HANDLE)info[1]->Int32Value(); + int handle = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + HANDLE innerPidHandle = (HANDLE)info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); winpty_t *pc = get_pipe_handle(handle); if (pc == nullptr) { @@ -300,7 +300,7 @@ static NAN_METHOD(PtyKill) { * Init */ -extern "C" void init(v8::Handle target) { +extern "C" void init(v8::Local target) { Nan::HandleScope scope; Nan::SetMethod(target, "startProcess", PtyStartProcess); Nan::SetMethod(target, "resize", PtyResize); diff --git a/src/windowsPtyAgent.ts b/src/windowsPtyAgent.ts index 8584aaf56..217142903 100644 --- a/src/windowsPtyAgent.ts +++ b/src/windowsPtyAgent.ts @@ -115,7 +115,8 @@ export class WindowsPtyAgent { // TODO: Wait for ready event? if (this._useConpty) { - const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, this._$onProcessExit.bind(this)); + const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, c => this._$onProcessExit(c) +); this._innerPid = connect.pid; } }