From cb3b3f6a9fb2d94525181c796623181692682974 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 28 Apr 2019 20:12:50 +0200 Subject: [PATCH] node 12 compat wip --- package.json | 2 +- src/win/conpty.cc | 39 +++++++++++++++++----------------- src/win/conpty_console_list.cc | 4 ++-- src/win/path_util.cc | 2 +- src/win/path_util.h | 2 +- src/win/winpty.cc | 34 ++++++++++++++--------------- src/windowsPtyAgent.ts | 5 ++++- 7 files changed, 45 insertions(+), 43 deletions(-) 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/win/conpty.cc b/src/win/conpty.cc index 1b5a74949..d512aa91b 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 @@ -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) @@ -242,12 +242,11 @@ 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); - + v8::Local local = Nan::New(baton->cb); + local->Call(Nan::GetCurrentContext(), Nan::Null(), 1, args); // Clean up baton->cb.Reset(); } @@ -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 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 +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'; @@ -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); @@ -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); @@ -428,7 +427,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..b2d3d996f 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"); @@ -35,7 +35,7 @@ static NAN_METHOD(ApiConsoleProcessList) { 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..089b3fee0 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(envValues->Get(i)))); 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 @@ -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..19dd8222a 100644 --- a/src/windowsPtyAgent.ts +++ b/src/windowsPtyAgent.ts @@ -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; } }