Skip to content
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

Node 12 support #288

Merged
merged 6 commits into from
May 9, 2019
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prepublish": "npm run tsc"
},
"dependencies": {
"nan": "2.12.1"
"nan": "^2.13.2"
},
"devDependencies": {
"@types/mocha": "^5.0.0",
Expand Down
48 changes: 20 additions & 28 deletions src/unix/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<v8::Integer>(i))->ToString());
Nan::Utf8String arg(Nan::Get(argv_, i).ToLocalChecked());
argv[i+1] = strdup(*arg);
}

Expand All @@ -173,26 +173,26 @@ NAN_METHOD(PtyFork) {
char **env = new char*[envc+1];
env[envc] = NULL;
for (; i < envc; i++) {
v8::String::Utf8Value pair(env_->Get(Nan::New<v8::Integer>(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;

// termios
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -700,18 +700,10 @@ pty_forkpty(int *amaster,

NAN_MODULE_INIT(init) {
Nan::HandleScope scope;
Nan::Set(target,
Nan::New<v8::String>("fork").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyFork)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("open").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyOpen)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("resize").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyResize)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("process").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(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)
10 changes: 4 additions & 6 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -276,11 +275,10 @@ export class UnixTerminal extends Terminal {
*/
class PipeSocket extends net.Socket {
constructor(fd: number) {
const tty = (<any>process).binding('tty_wrap');
const guessHandleType = tty.guessHandleType;
tty.guessHandleType = () => 'PIPE';
const { Pipe, constants } = (<any>process).binding('pipe_wrap'); // tslint:disable-line
// @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275
super({ fd: <any>fd });
tty.guessHandleType = guessHandleType;
const handle = new Pipe(constants.SOCKET);
handle.open(fd);
super(<any>{ handle });
}
}
58 changes: 29 additions & 29 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <strsafe.h>
#include "path_util.h"

extern "C" void init(v8::Handle<v8::Object>);
extern "C" void init(v8::Local<v8::Object>);

// Taken from the RS5 Windows SDK, but redefined here in case we're targeting <= 17134
#ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
Expand All @@ -40,7 +40,7 @@ struct pty_baton {

HANDLE hShell;
HANDLE hWait;
Nan::Persistent<v8::Function> cb;
Nan::Callback cb;
uv_async_t async;
uv_thread_t tid;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<v8::String>("pty").ToLocalChecked(), Nan::New<v8::Number>(ptyId));
Nan::Set(marshal, Nan::New<v8::String>("pty").ToLocalChecked(), Nan::New<v8::Number>(ptyId));
ptyHandles.insert(ptyHandles.end(), new pty_baton(ptyId, hIn, hOut, hpc));
} else {
Nan::ThrowError("Cannot launch conpty");
return;
}

marshal->Set(Nan::New<v8::String>("fd").ToLocalChecked(), Nan::New<v8::Number>(-1));
Nan::Set(marshal, Nan::New<v8::String>("fd").ToLocalChecked(), Nan::New<v8::Number>(-1));
{
std::string coninPipeNameStr(inName.begin(), inName.end());
marshal->Set(Nan::New<v8::String>("conin").ToLocalChecked(), Nan::New<v8::String>(coninPipeNameStr).ToLocalChecked());
Nan::Set(marshal, Nan::New<v8::String>("conin").ToLocalChecked(), Nan::New<v8::String>(coninPipeNameStr).ToLocalChecked());

std::string conoutPipeNameStr(outName.begin(), outName.end());
marshal->Set(Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(conoutPipeNameStr).ToLocalChecked());
Nan::Set(marshal, Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(conoutPipeNameStr).ToLocalChecked());
}
info.GetReturnValue().Set(marshal);
}
Expand All @@ -242,12 +242,12 @@ static void OnProcessExit(uv_async_t *async) {
GetExitCodeProcess(baton->hShell, &exitCode);

// Call function
v8::Handle<v8::Value> args[1] = {
v8::Local<v8::Value> args[1] = {
Nan::New<v8::Number>(exitCode)
};
v8::Handle<v8::Function> 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();
}
Expand All @@ -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<v8::Array> envValues = info[3].As<v8::Array>();
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<v8::Array> envValues = info[3].As<v8::Array>();
const v8::Local<v8::Function> exitCallback = v8::Local<v8::Function>::Cast(info[4]);

// Prepare command line
Expand All @@ -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';
Expand All @@ -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<PPROC_THREAD_ATTRIBUTE_LIST>(attrList);

fSuccess = InitializeProcThreadAttributeList(siEx.lpAttributeList, 1, 0, size);
fSuccess = InitializeProcThreadAttributeList(siEx.lpAttributeList, 1, 0, &size);
if (!fSuccess) {
return throwNanError(&info, "InitializeProcThreadAttributeList failed", true);
}
Expand Down Expand Up @@ -359,7 +359,7 @@ static NAN_METHOD(PtyConnect) {

// Return
v8::Local<v8::Object> marshal = Nan::New<v8::Object>();
marshal->Set(Nan::New<v8::String>("pid").ToLocalChecked(), Nan::New<v8::Number>(piClient.dwProcessId));
Nan::Set(marshal, Nan::New<v8::String>("pid").ToLocalChecked(), Nan::New<v8::Number>(piClient.dwProcessId));
info.GetReturnValue().Set(marshal);
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -428,7 +428,7 @@ static NAN_METHOD(PtyKill) {
* Init
*/

extern "C" void init(v8::Handle<v8::Object> target) {
extern "C" void init(v8::Local<v8::Object> target) {
Nan::HandleScope scope;
Nan::SetMethod(target, "startProcess", PtyStartProcess);
Nan::SetMethod(target, "connect", PtyConnect);
Expand Down
6 changes: 3 additions & 3 deletions src/win/conpty_console_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -30,12 +30,12 @@ static NAN_METHOD(ApiConsoleProcessList) {

v8::Local<v8::Array> result = Nan::New<v8::Array>();
for (DWORD i = 0; i < processCount; i++) {
result->Set(i, Nan::New<v8::Number>(processList[i]));
Nan::Set(result, i, Nan::New<v8::Number>(processList[i]));
}
info.GetReturnValue().Set(result);
}

extern "C" void init(v8::Handle<v8::Object> target) {
extern "C" void init(v8::Local<v8::Object> target) {
Nan::HandleScope scope;
Nan::SetMethod(target, "getConsoleProcessList", ApiConsoleProcessList);
};
Expand Down
2 changes: 1 addition & 1 deletion src/win/path_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/win/path_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading