diff --git a/package.json b/package.json index 43ee21f..309154a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bluetooth-hci-socket", - "version": "0.5.2", + "version": "0.5.3", "description": "Bluetooth HCI socket binding for Node.js", "main": "index.js", "repository": { @@ -27,8 +27,8 @@ ], "dependencies": { "debug": "^2.2.0", - "nan": "^2.0.5", - "node-pre-gyp": "0.6.x" + "nan": "^2.14.1", + "node-pre-gyp": "^0.15.0" }, "optionalDependencies": { "usb": "^1.1.0" @@ -37,15 +37,15 @@ "jshint": "^2.8.0" }, "scripts": { - "preinstall": "npm install node-pre-gyp", - "install": "node-pre-gyp install --fallback-to-build", - "test": "jshint lib/*.js" + "preinstall": "npm install node-pre-gyp", + "install": "node-pre-gyp install --fallback-to-build", + "test": "jshint lib/*.js" }, "binary": { - "module_name": "binding", - "module_path": "./lib/binding/", - "host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/", - "package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz", - "remote_path": "{version}" + "module_name": "binding", + "module_path": "./lib/binding/", + "host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/", + "package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz", + "remote_path": "{version}" } } diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 469cda2..6b7a66d 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -28,6 +28,8 @@ #define ATT_CID 4 +using v8::Context; + enum { HCI_UP, HCI_INIT, @@ -126,7 +128,15 @@ NAN_MODULE_INIT(BluetoothHciSocket::Init) { Nan::SetPrototypeMethod(tmpl, "stop", Stop); Nan::SetPrototypeMethod(tmpl, "write", Write); - target->Set(Nan::New("BluetoothHciSocket").ToLocalChecked(), tmpl->GetFunction()); + + v8::Isolate* isolate = target->GetIsolate(); + v8::Local context = isolate->GetCurrentContext(); + + target->Set( + context, + Nan::New("BluetoothHciSocket").ToLocalChecked(), + tmpl->GetFunction( context ).ToLocalChecked() + ); } BluetoothHciSocket::BluetoothHciSocket() : @@ -267,13 +277,14 @@ void BluetoothHciSocket::emitErrnoError() { Nan::HandleScope scope; Local globalObj = Nan::GetCurrentContext()->Global(); - Local errorConstructor = Local::Cast(globalObj->Get(Nan::New("Error").ToLocalChecked())); + + Local errorConstructor = Local::Cast(globalObj->Get(Nan::GetCurrentContext(), Nan::New("Error").ToLocalChecked()).ToLocalChecked() ); Local constructorArgs[1] = { Nan::New(strerror(errno)).ToLocalChecked() }; - Local error = errorConstructor->NewInstance(1, constructorArgs); + Local error = errorConstructor->NewInstance(Nan::GetCurrentContext(), 1, constructorArgs).ToLocalChecked(); Local argv[2] = { Nan::New("error").ToLocalChecked(), @@ -393,7 +404,7 @@ NAN_METHOD(BluetoothHciSocket::BindRaw) { if (info.Length() > 0) { Local arg0 = info[0]; if (arg0->IsInt32() || arg0->IsUint32()) { - devId = arg0->IntegerValue(); + devId = arg0->IntegerValue( Nan::GetCurrentContext() ).ToChecked(); pDevId = &devId; } @@ -415,7 +426,7 @@ NAN_METHOD(BluetoothHciSocket::BindUser) { if (info.Length() > 0) { Local arg0 = info[0]; if (arg0->IsInt32() || arg0->IsUint32()) { - devId = arg0->IntegerValue(); + devId = arg0->IntegerValue( Nan::GetCurrentContext() ).ToChecked(); pDevId = &devId; } @@ -468,12 +479,12 @@ NAN_METHOD(BluetoothHciSocket::GetDeviceList) { bool devUp = dr->dev_opt & (1 << HCI_UP); if (dr != NULL) { v8::Local obj = Nan::New(); - obj->Set(Nan::New("devId").ToLocalChecked(), Nan::New(devId)); - obj->Set(Nan::New("devUp").ToLocalChecked(), Nan::New(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()); + obj->Set(obj, Nan::New("devUp").ToLocalChecked(), Nan::New(devUp)); + obj->Set(obj, Nan::New("devId").ToLocalChecked(), Nan::New(devId)); + obj->Set(obj, Nan::New("idVendor").ToLocalChecked(), Nan::Null()); + obj->Set(obj, Nan::New("idProduct").ToLocalChecked(), Nan::Null()); + obj->Set(obj, Nan::New("busNumber").ToLocalChecked(), Nan::Null()); + obj->Set(obj, Nan::New("deviceAddress").ToLocalChecked(), Nan::Null()); Nan::Set(deviceList, di++, obj); } } diff --git a/src/BluetoothHciSocket.h b/src/BluetoothHciSocket.h index 97e4244..6d1fd01 100644 --- a/src/BluetoothHciSocket.h +++ b/src/BluetoothHciSocket.h @@ -56,6 +56,7 @@ class BluetoothHciSocket : public node::ObjectWrap { std::map _l2sockets; uint8_t _address[6]; uint8_t _addressType; + //v8::Isolate* isolate; static Nan::Persistent constructor_template; };