Skip to content

Commit

Permalink
node 12 compat wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Apr 28, 2019
1 parent bed37ce commit cb3b3f6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 43 deletions.
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
39 changes: 19 additions & 20 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 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 @@ -242,12 +242,11 @@ 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);

v8::Local<v8::Function> local = Nan::New(baton->cb);
local->Call(Nan::GetCurrentContext(), Nan::Null(), 1, args);
// Clean up
baton->cb.Reset();
}
Expand All @@ -272,10 +271,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 +290,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(envValues->Get(i))));
envBlock << envValue << L'\0';
}
envBlock << L'\0';
Expand Down Expand Up @@ -374,9 +373,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 +403,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 +427,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
4 changes: 2 additions & 2 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 @@ -35,7 +35,7 @@ static NAN_METHOD(ApiConsoleProcessList) {
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
34 changes: 17 additions & 17 deletions src/win/winpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Misc
*/
extern "C" void init(v8::Handle<v8::Object>);
extern "C" void init(v8::Local<v8::Object>);

#define WINPTY_DBG_VARIABLE TEXT("WINPTYDBG")

Expand Down Expand Up @@ -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<v8::Number>(exitCode));
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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<v8::Array> envValues = v8::Handle<v8::Array>::Cast(info[2]);
const v8::Local<v8::Array> envValues = v8::Local<v8::Array>::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(envValues->Get(i))));
envBlock << envValue << L'\0';
}

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

Expand All @@ -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) {
Expand All @@ -300,7 +300,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, "resize", PtyResize);
Expand Down
5 changes: 4 additions & 1 deletion src/windowsPtyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ 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 => {
console.warn('callback', c)
this._$onProcessExit(c)
});
this._innerPid = connect.pid;
}
}
Expand Down

0 comments on commit cb3b3f6

Please sign in to comment.