From 9b9e9753a6e676754a851369f723c1bbcf7783c6 Mon Sep 17 00:00:00 2001
From: Aarni Koskela <akx@iki.fi>
Date: Wed, 28 Aug 2019 13:30:51 +0300
Subject: [PATCH 3/6] Fix things up for Node 12, nan 2.14.x

---
 package.json               |  4 ++--
 src/BluetoothHciSocket.cpp | 29 ++++++++++-------------------
 2 files changed, 12 insertions(+), 21 deletions(-)

--- a/package.json
+++ b/package.json
@@ -27,8 +27,8 @@
   ],
   "dependencies": {
     "debug": "^3.1.0",
-    "nan": "^2.10.0",
-    "node-pre-gyp": "^0.11.0"
+    "nan": "^2.14.0",
+    "node-pre-gyp": "^0.13.0"
   },
   "optionalDependencies": {},
   "devDependencies": {
--- a/src/BluetoothHciSocket.cpp
+++ b/src/BluetoothHciSocket.cpp
@@ -129,7 +129,7 @@ NAN_MODULE_INIT(BluetoothHciSocket::Init
   Nan::SetPrototypeMethod(tmpl, "stop", Stop);
   Nan::SetPrototypeMethod(tmpl, "write", Write);
 
-  target->Set(Nan::New("BluetoothHciSocket").ToLocalChecked(), tmpl->GetFunction());
+  Nan::Set(target, Nan::New("BluetoothHciSocket").ToLocalChecked(), Nan::GetFunction(tmpl).ToLocalChecked());
 }
 
 BluetoothHciSocket::BluetoothHciSocket() :
@@ -267,16 +267,7 @@ void BluetoothHciSocket::write_(char* da
 }
 
 void BluetoothHciSocket::emitErrnoError() {
-  Nan::HandleScope scope;
-
-  Local<Object> globalObj = Nan::GetCurrentContext()->Global();
-  Local<Function> errorConstructor = Local<Function>::Cast(globalObj->Get(Nan::New("Error").ToLocalChecked()));
-
-  Local<Value> constructorArgs[1] = {
-    Nan::New(strerror(errno)).ToLocalChecked()
-  };
-
-  Local<Value> error = Nan::NewInstance(errorConstructor, 1, constructorArgs).ToLocalChecked();
+  v8::Local<v8::Value> error = Nan::ErrnoException(errno, NULL, strerror(errno));
 
   Local<Value> argv[2] = {
     Nan::New("error").ToLocalChecked(),
@@ -396,7 +387,7 @@ NAN_METHOD(BluetoothHciSocket::BindRaw)
   if (info.Length() > 0) {
     Local<Value> arg0 = info[0];
     if (arg0->IsInt32() || arg0->IsUint32()) {
-      devId = arg0->IntegerValue();
+      devId = Nan::To<int32_t>(arg0).FromJust();
 
       pDevId = &devId;
     }
@@ -418,7 +409,7 @@ NAN_METHOD(BluetoothHciSocket::BindUser)
   if (info.Length() > 0) {
     Local<Value> arg0 = info[0];
     if (arg0->IsInt32() || arg0->IsUint32()) {
-      devId = arg0->IntegerValue();
+      devId = Nan::To<int32_t>(arg0).FromJust();
 
       pDevId = &devId;
     }
@@ -471,12 +462,12 @@ NAN_METHOD(BluetoothHciSocket::GetDevice
       bool devUp = dr->dev_opt & (1 << HCI_UP);
       if (dr != NULL) {
         v8::Local<v8::Object> obj = Nan::New<v8::Object>();
-        obj->Set(Nan::New("devId").ToLocalChecked(), Nan::New<Number>(devId));
-        obj->Set(Nan::New("devUp").ToLocalChecked(), Nan::New<Boolean>(devUp));
-        obj->Set(Nan::New("idVendor").ToLocalChecked(), Nan::Null());
-        obj->Set(Nan::New("idProduct").ToLocalChecked(), Nan::Null());
-        obj->Set(Nan::New("busNumber").ToLocalChecked(), Nan::Null());
-        obj->Set(Nan::New("deviceAddress").ToLocalChecked(), Nan::Null());
+        Nan::Set(obj, Nan::New("devId").ToLocalChecked(), Nan::New<Number>(devId));
+        Nan::Set(obj, Nan::New("devUp").ToLocalChecked(), Nan::New<Boolean>(devUp));
+        Nan::Set(obj, Nan::New("idVendor").ToLocalChecked(), Nan::Null());
+        Nan::Set(obj, Nan::New("idProduct").ToLocalChecked(), Nan::Null());
+        Nan::Set(obj, Nan::New("busNumber").ToLocalChecked(), Nan::Null());
+        Nan::Set(obj, Nan::New("deviceAddress").ToLocalChecked(), Nan::Null());
         Nan::Set(deviceList, di++, obj);
       }
     }
