Merge pull request #26 from jimmythesaint82/node_12_changes
Implement some of the required fixes for Node.js 12
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "pcsclite.h"
|
||||
#include "cardreader.h"
|
||||
|
||||
void init_all(v8::Handle<v8::Object> target) {
|
||||
void init_all(v8::Local<v8::Object> target) {
|
||||
PCSCLite::init(target);
|
||||
CardReader::init(target);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using namespace node;
|
||||
|
||||
Nan::Persistent<Function> CardReader::constructor;
|
||||
|
||||
void CardReader::init(Handle<Object> target) {
|
||||
void CardReader::init(Local<Object> target) {
|
||||
|
||||
// Prepare constructor template
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
@@ -58,8 +58,10 @@ void CardReader::init(Handle<Object> 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> 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<String>(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<String>(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> 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<Function> cb = Local<Function>::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> context = Nan::GetCurrentContext();
|
||||
|
||||
DWORD disposition = info[0]->Uint32Value(context).FromJust();
|
||||
Local<Function> cb = Local<Function>::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<Object> buffer_data = info[0]->ToObject();
|
||||
uint32_t out_len = info[1]->Uint32Value();
|
||||
uint32_t protocol = info[2]->Uint32Value();
|
||||
Local<Context> context = Nan::GetCurrentContext();
|
||||
|
||||
Local<Object> buffer_data = Nan::To<Object>(info[0]).ToLocalChecked();
|
||||
uint32_t out_len = info[1]->Uint32Value(context).FromJust();
|
||||
uint32_t protocol = info[2]->Uint32Value(context).FromJust();
|
||||
|
||||
Local<Function> cb = Local<Function>::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<Object> in_buf = info[0]->ToObject();
|
||||
DWORD control_code = info[1]->Uint32Value();
|
||||
Local<Object> out_buf = info[2]->ToObject();
|
||||
Local<Context> context = Nan::GetCurrentContext();
|
||||
|
||||
Local<Object> in_buf = Nan::To<Object>(info[0]).ToLocalChecked();
|
||||
DWORD control_code = info[1]->Uint32Value(context).FromJust();
|
||||
Local<Object> out_buf = Nan::To<Object>(info[2]).ToLocalChecked();
|
||||
Local<Function> cb = Local<Function>::Cast(info[3]);
|
||||
|
||||
// This creates our work request, including the libuv struct.
|
||||
|
||||
@@ -87,7 +87,7 @@ class CardReader: public Nan::ObjectWrap {
|
||||
|
||||
public:
|
||||
|
||||
static void init(v8::Handle<v8::Object> target);
|
||||
static void init(v8::Local<v8::Object> 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<v8::Value> CreateBufferInstance(char* data, unsigned long size);
|
||||
static v8::Local<v8::Value> CreateBufferInstance(char* data, unsigned long size);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ using namespace node;
|
||||
|
||||
Nan::Persistent<Function> PCSCLite::constructor;
|
||||
|
||||
void PCSCLite::init(Handle<Object> target) {
|
||||
void PCSCLite::init(Local<Object> target) {
|
||||
|
||||
Local<Context> context = Nan::GetCurrentContext();
|
||||
|
||||
// Prepare constructor template
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
@@ -16,8 +18,9 @@ void PCSCLite::init(Handle<Object> target) {
|
||||
Nan::SetPrototypeTemplate(tpl, "start", Nan::New<FunctionTemplate>(Start));
|
||||
Nan::SetPrototypeTemplate(tpl, "close", Nan::New<FunctionTemplate>(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),
|
||||
|
||||
@@ -28,7 +28,7 @@ class PCSCLite: public Nan::ObjectWrap {
|
||||
|
||||
public:
|
||||
|
||||
static void init(v8::Handle<v8::Object> target);
|
||||
static void init(v8::Local<v8::Object> target);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user