From 2ccd6e1693a2f2d131d262957252b07f5440b043 Mon Sep 17 00:00:00 2001 From: jimmythesaint82 Date: Fri, 21 Jun 2019 01:32:31 +0200 Subject: [PATCH] Node 12 fixes --- src/addon.cpp | 2 +- src/cardreader.cpp | 40 ++++++++++++++++++++++++++-------------- src/cardreader.h | 4 ++-- src/pcsclite.cpp | 9 ++++++--- src/pcsclite.h | 2 +- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/addon.cpp b/src/addon.cpp index 7addfa6..d158b25 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -1,7 +1,7 @@ #include "pcsclite.h" #include "cardreader.h" -void init_all(v8::Handle target) { +void init_all(v8::Local target) { PCSCLite::init(target); CardReader::init(target); } diff --git a/src/cardreader.cpp b/src/cardreader.cpp index 4b1506a..98c6016 100644 --- a/src/cardreader.cpp +++ b/src/cardreader.cpp @@ -6,7 +6,7 @@ using namespace node; Nan::Persistent CardReader::constructor; -void CardReader::init(Handle target) { +void CardReader::init(Local target) { // Prepare constructor template Local tpl = Nan::New(New); @@ -58,8 +58,10 @@ void CardReader::init(Handle target) { Nan::SetPrototypeTemplate(tpl, "SCARD_UNPOWER_CARD", Nan::New(SCARD_UNPOWER_CARD)); Nan::SetPrototypeTemplate(tpl, "SCARD_EJECT_CARD", Nan::New(SCARD_EJECT_CARD)); - constructor.Reset(tpl->GetFunction()); - target->Set(Nan::New("CardReader").ToLocalChecked(), tpl->GetFunction()); + Local context = Nan::GetCurrentContext(); + + constructor.Reset(tpl->GetFunction(context).ToLocalChecked()); + target->Set(Nan::New("CardReader").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } CardReader::CardReader(const std::string &reader_name): m_card_context(0), @@ -88,10 +90,11 @@ NAN_METHOD(CardReader::New) { Nan::HandleScope scope; - v8::String::Utf8Value reader_name(info[0]->ToString()); + Nan::Utf8String reader_name(Nan::To(info[0]).ToLocalChecked()); + CardReader* obj = new CardReader(*reader_name); obj->Wrap(info.Holder()); - obj->handle()->Set(Nan::New(name_symbol), info[0]->ToString()); + obj->handle()->Set(Nan::New(name_symbol), Nan::To(info[0]).ToLocalChecked()); obj->handle()->Set(Nan::New(connected_symbol), Nan::False()); info.GetReturnValue().Set(info.Holder()); @@ -133,9 +136,11 @@ NAN_METHOD(CardReader::Connect) { return Nan::ThrowError("Third argument must be a callback function"); } + Local context = Nan::GetCurrentContext(); + ConnectInput* ci = new ConnectInput(); - ci->share_mode = info[0]->Uint32Value(); - ci->pref_protocol = info[1]->Uint32Value(); + ci->share_mode = info[0]->Uint32Value(context).FromJust(); + ci->pref_protocol = info[1]->Uint32Value(context).FromJust(); Local cb = Local::Cast(info[2]); // This creates our work request, including the libuv struct. @@ -169,7 +174,9 @@ NAN_METHOD(CardReader::Disconnect) { return Nan::ThrowError("Second argument must be a callback function"); } - DWORD disposition = info[0]->Uint32Value(); + Local context = Nan::GetCurrentContext(); + + DWORD disposition = info[0]->Uint32Value(context).FromJust(); Local cb = Local::Cast(info[1]); // This creates our work request, including the libuv struct. @@ -215,9 +222,12 @@ NAN_METHOD(CardReader::Transmit) { return Nan::ThrowError("Fourth argument must be a callback function"); } - Local buffer_data = info[0]->ToObject(); - uint32_t out_len = info[1]->Uint32Value(); - uint32_t protocol = info[2]->Uint32Value(); + Local context = Nan::GetCurrentContext(); + + Local buffer_data = Nan::To(info[0]).ToLocalChecked(); + uint32_t out_len = info[1]->Uint32Value(context).FromJust(); + uint32_t protocol = info[2]->Uint32Value(context).FromJust(); + Local cb = Local::Cast(info[3]); // This creates our work request, including the libuv struct. @@ -270,9 +280,11 @@ NAN_METHOD(CardReader::Control) { return Nan::ThrowError("Fourth argument must be a callback function"); } - Local in_buf = info[0]->ToObject(); - DWORD control_code = info[1]->Uint32Value(); - Local out_buf = info[2]->ToObject(); + Local context = Nan::GetCurrentContext(); + + Local in_buf = Nan::To(info[0]).ToLocalChecked(); + DWORD control_code = info[1]->Uint32Value(context).FromJust(); + Local out_buf = Nan::To(info[2]).ToLocalChecked(); Local cb = Local::Cast(info[3]); // This creates our work request, including the libuv struct. diff --git a/src/cardreader.h b/src/cardreader.h index af9de03..e56777a 100644 --- a/src/cardreader.h +++ b/src/cardreader.h @@ -87,7 +87,7 @@ class CardReader: public Nan::ObjectWrap { public: - static void init(v8::Handle target); + static void init(v8::Local target); const SCARDHANDLE& GetHandler() const { return m_card_handle; }; @@ -120,7 +120,7 @@ class CardReader: public Nan::ObjectWrap { static void AfterTransmit(uv_work_t* req, int status); static void AfterControl(uv_work_t* req, int status); - static v8::Handle CreateBufferInstance(char* data, unsigned long size); + static v8::Local CreateBufferInstance(char* data, unsigned long size); private: diff --git a/src/pcsclite.cpp b/src/pcsclite.cpp index d0561d2..a35d0b4 100644 --- a/src/pcsclite.cpp +++ b/src/pcsclite.cpp @@ -6,7 +6,9 @@ using namespace node; Nan::Persistent PCSCLite::constructor; -void PCSCLite::init(Handle target) { +void PCSCLite::init(Local target) { + + Local context = Nan::GetCurrentContext(); // Prepare constructor template Local tpl = Nan::New(New); @@ -16,8 +18,9 @@ void PCSCLite::init(Handle target) { Nan::SetPrototypeTemplate(tpl, "start", Nan::New(Start)); Nan::SetPrototypeTemplate(tpl, "close", Nan::New(Close)); - constructor.Reset(tpl->GetFunction()); - target->Set(Nan::New("PCSCLite").ToLocalChecked(), tpl->GetFunction()); + + constructor.Reset(tpl->GetFunction(context).ToLocalChecked()); + target->Set(Nan::New("PCSCLite").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } PCSCLite::PCSCLite(): m_card_context(0), diff --git a/src/pcsclite.h b/src/pcsclite.h index ca6696a..4ef616b 100644 --- a/src/pcsclite.h +++ b/src/pcsclite.h @@ -28,7 +28,7 @@ class PCSCLite: public Nan::ObjectWrap { public: - static void init(v8::Handle target); + static void init(v8::Local target); private: