Repository: cossacklabs/themis (language: rust)

Issue:
Update jsthemis for Nodev1.0
Due to API changes in gyp, jsthemis is not building


Similar issues -> https://github.com/phusion/node-sha3/issues/32

```
➜  acra git:(vixentael/T696-acrawriter-fixes) ✗ npm install jsthemis

> jsthemis@0.10.0 install /Users/hdf/node_modules/jsthemis
> node-gyp rebuild

  CXX(target) Release/obj.target/jsthemis/addon.o
In file included from ../addon.cpp:18:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:839:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:171:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../addon.cpp:18:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:854:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:164:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../addon.cpp:18:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:869:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:157:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../addon.cpp:18:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:1478:31: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return scope.Escape(node::MakeCallback(
                              ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:171:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
4 warnings generated.
  CXX(target) Release/obj.target/jsthemis/secure_message.o
In file included from ../secure_message.cpp:20:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:839:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:171:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../secure_message.cpp:20:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:854:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:164:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../secure_message.cpp:20:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:869:18: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return node::MakeCallback(
                 ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:157:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
In file included from ../secure_message.cpp:20:
In file included from ../secure_message.hpp:20:
../../nan/nan.h:1478:31: warning: 'MakeCallback' is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations]
    return scope.Escape(node::MakeCallback(
                              ^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:171:1: note: 'MakeCallback' has been explicitly marked deprecated here
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
^
/Users/hdf/.node-gyp/10.8.0/include/node/node.h:88:20: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                   ^
../secure_message.cpp:58:39: error: no matching member function for call to 'NewInstance'
      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
                                ~~~~~~^~~~~~~~~~~
/Users/hdf/.node-gyp/10.8.0/include/node/v8.h:3956:44: note: candidate function not viable: requires single argument 'context', but 2 arguments were provided
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
                                           ^
/Users/hdf/.node-gyp/10.8.0/include/node/v8.h:3953:44: note: candidate function not viable: requires 3 arguments, but 2 were provided
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
                                           ^
4 warnings and 1 error generated.
make: *** [Release/obj.target/jsthemis/secure_message.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/Cellar/node/10.8.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hdf/node_modules/jsthemis
gyp ERR! node -v v10.8.0
gyp ERR! node-gyp -v v3.7.0
gyp ERR! not ok 
npm WARN enoent ENOENT: no such file or directory, open '/Users/hdf/package.json'
npm WARN hdf No description
npm WARN hdf No repository field.
npm WARN hdf No README data
npm WARN hdf No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@0.5.1 (node_modules/bluetooth-hci-socket):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for bluetooth-hci-socket@0.5.1: wanted {"os":"linux,android,win32","arch":"any"} (current: {"os":"darwin","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! jsthemis@0.10.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the jsthemis@0.10.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/hdf/.npm/_logs/2018-08-13T09_11_46_575Z-debug.log
```


Discussion / hints:

Fix patch:
diff --git a/docs/examples/js/secure_cell.js b/docs/examples/js/secure_cell.js
index f1e8c50e5..417a5de3f 100644
--- a/docs/examples/js/secure_cell.js
+++ b/docs/examples/js/secure_cell.js
@@ -3,13 +3,13 @@ var addon = require('jsthemis');
 
 if(process.argv.length==5){
     command=process.argv[2];
-    password=new Buffer(process.argv[3]);
+    password=new Buffer.from(process.argv[3]);
 
     seal = new addon.SecureCellSeal(password);
     if(command=="enc"){
-	console.log(seal.encrypt(new Buffer(process.argv[4])).toString("base64"));
+	console.log(seal.encrypt(new Buffer.from(process.argv[4])).toString("base64"));
     }else if(command=="dec"){
-	console.log(seal.decrypt(new Buffer(process.argv[4], "base64")).toString());
+	console.log(seal.decrypt(new Buffer.from(process.argv[4], "base64")).toString());
     }else{
 	console.log("usage node secure_cell.js <enc/dec> <password> <message>");
     }
diff --git a/docs/examples/js/secure_comparator_client.js b/docs/examples/js/secure_comparator_client.js
index 9f91945fd..a7a46d990 100644
--- a/docs/examples/js/secure_comparator_client.js
+++ b/docs/examples/js/secure_comparator_client.js
@@ -1,7 +1,7 @@
 var net = require('net');
 var themis = require('jsthemis');
 
-comparator = new themis.SecureComparator(new Buffer("secret"));
+comparator = new themis.SecureComparator(new Buffer.from("secret"));
 
 var client = new net.Socket();
 client.connect(1337, '127.0.0.1', function() {
diff --git a/docs/examples/js/secure_comparator_server.js b/docs/examples/js/secure_comparator_server.js
index 9491ea920..3eb2a3477 100644
--- a/docs/examples/js/secure_comparator_server.js
+++ b/docs/examples/js/secure_comparator_server.js
@@ -3,7 +3,7 @@ var themis = require('jsthemis');
 
 var server = net.createServer(function(socket) {
 
-    comparator = new themis.SecureComparator(new Buffer("secret"));
+    comparator = new themis.SecureComparator(new Buffer.from("secret"));
   
     socket.on('data', function (data) {
 	d=comparator.proceedCompare(data);
diff --git a/docs/examples/js/secure_message.js b/docs/examples/js/secure_message.js
index 14a09c857..6d77a753c 100644
--- a/docs/examples/js/secure_message.js
+++ b/docs/examples/js/secure_message.js
@@ -5,11 +5,11 @@ if(process.argv.length==6){
     private_key=process.argv[3];
     peer_public_key=process.argv[4];
 
-    sm = new addon.SecureMessage(new Buffer(private_key, "base64"), new Buffer(peer_public_key, "base64"));
+    sm = new addon.SecureMessage(new Buffer.from(private_key, "base64"), new Buffer.from(peer_public_key, "base64"));
     if(command=="enc"){
-        console.log(sm.encrypt(new Buffer(process.argv[5])).toString("base64"));
+        console.log(sm.encrypt(new Buffer.from(process.argv[5])).toString("base64"));
     }else if(command=="dec"){
-	console.log(sm.decrypt(new Buffer(process.argv[5], "base64")).toString());
+	console.log(sm.decrypt(new Buffer.from(process.argv[5], "base64")).toString());
     }else{
         console.log("usage node secure_message.js <enc/dec> <private key> <peer public key> <message>");
     }
diff --git a/docs/examples/js/secure_session_client.js b/docs/examples/js/secure_session_client.js
index d85f68dec..680c110d5 100644
--- a/docs/examples/js/secure_session_client.js
+++ b/docs/examples/js/secure_session_client.js
@@ -1,12 +1,12 @@
 var net = require('net');
 var themis = require('jsthemis');
 
-session = new themis.SecureSession(new Buffer("client"), new Buffer("UkVDMgAAAC3DZR2qAEbvO092R/IKXBttnf9dVSU65R+Fb4eNoyxxlzn2n4GR","base64"), function(id){
+session = new themis.SecureSession(new Buffer.from("client"), new Buffer.from("UkVDMgAAAC3DZR2qAEbvO092R/IKXBttnf9dVSU65R+Fb4eNoyxxlzn2n4GR","base64"), function(id){
     if(id.toString()=="server".toString()){
-	return new Buffer("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
+	return new Buffer.from("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
     }
     else if(id.toString()=="client".toString())
-	return new Buffer("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s", "base64");
+	return new Buffer.from("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s", "base64");
 });
 
 retry_count=5;
@@ -25,7 +25,7 @@ client.on('data', function(data) {
 	if(d != undefined)
 	    console.log(d.toString());
 	if(retry_count--)
-	    client.write(session.wrap(new Buffer("Hello server!!!")));
+	    client.write(session.wrap(new Buffer.from("Hello server!!!")));
 	else
 	    client.destroy();
     }
diff --git a/docs/examples/js/secure_session_server.js b/docs/examples/js/secure_session_server.js
index ba7bccdab..2ad6d112e 100644
--- a/docs/examples/js/secure_session_server.js
+++ b/docs/examples/js/secure_session_server.js
@@ -3,11 +3,11 @@ var themis = require('jsthemis');
 
 var server = net.createServer(function(socket) {
 
-    session = new themis.SecureSession(new Buffer("server"), new Buffer("UkVDMgAAAC0U6AK7AAm6ha0cgHmovSTpZax01+icg9xwFlZAqqGWeGTqbHUt","base64"), function(id){
+    session = new themis.SecureSession(new Buffer.from("server"), new Buffer.from("UkVDMgAAAC0U6AK7AAm6ha0cgHmovSTpZax01+icg9xwFlZAqqGWeGTqbHUt","base64"), function(id){
 	if(id.toString()=="server".toString())
-	    return new Buffer("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
+	    return new Buffer.from("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
 	else if(id.toString()=="client".toString()){
-	    return new Buffer("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s","base64");
+	    return new Buffer.from("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s","base64");
 	}
     });
   
diff --git a/src/wrappers/themis/jsthemis/package.json b/src/wrappers/themis/jsthemis/package.json
index af202679a..e571029b1 100644
--- a/src/wrappers/themis/jsthemis/package.json
+++ b/src/wrappers/themis/jsthemis/package.json
@@ -1,6 +1,6 @@
 {
   "name": "jsthemis",
-  "version": "0.10.0",
+  "version": "0.10.1",
   "description": "Themis is a data security library, providing users with high-quality security services for secure messaging of any kinds and flexible data storage. Themis is aimed at modern developers, with high level OOP wrappers for Ruby, Python, PHP, Java / Android and iOS / OSX. It is designed with ease of use in mind, high security and cross-platform availability.",
   "main": "build/Release/jsthemis.node",
   "scripts": {
@@ -12,7 +12,7 @@
     "url": "https://www.cossacklabs.com/"
   },
   "dependencies": {
-    "nan": "^2.4.0"
+    "nan": "^2.8.0"
   },
   "license": " Apache-2.0",
   "gypfile": true
diff --git a/src/wrappers/themis/jsthemis/secure_cell_context_imprint.cpp b/src/wrappers/themis/jsthemis/secure_cell_context_imprint.cpp
index d74f201a5..f8c04cb40 100644
--- a/src/wrappers/themis/jsthemis/secure_cell_context_imprint.cpp
+++ b/src/wrappers/themis/jsthemis/secure_cell_context_imprint.cpp
@@ -50,7 +50,7 @@ namespace jsthemis {
       const int argc = 1;
       v8::Local<v8::Value> argv[argc] = { args[0]};
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_cell_seal.cpp b/src/wrappers/themis/jsthemis/secure_cell_seal.cpp
index fe3f69d86..e9034cc46 100644
--- a/src/wrappers/themis/jsthemis/secure_cell_seal.cpp
+++ b/src/wrappers/themis/jsthemis/secure_cell_seal.cpp
@@ -50,7 +50,7 @@ namespace jsthemis {
       const int argc = 1;
       v8::Local<v8::Value> argv[argc] = { args[0]};
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_cell_token_protect.cpp b/src/wrappers/themis/jsthemis/secure_cell_token_protect.cpp
index ba66bf0f4..12360ca31 100644
--- a/src/wrappers/themis/jsthemis/secure_cell_token_protect.cpp
+++ b/src/wrappers/themis/jsthemis/secure_cell_token_protect.cpp
@@ -50,7 +50,7 @@ namespace jsthemis {
       const int argc = 1;
       v8::Local<v8::Value> argv[argc] = { args[0]};
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_comparator.cpp b/src/wrappers/themis/jsthemis/secure_comparator.cpp
index 80d8c66ff..cd717deb1 100644
--- a/src/wrappers/themis/jsthemis/secure_comparator.cpp
+++ b/src/wrappers/themis/jsthemis/secure_comparator.cpp
@@ -68,7 +68,7 @@ namespace jsthemis {
       const int argc = 3;
       v8::Local<v8::Value> argv[argc] = { args[0], args[1], args[2]};
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_keygen.cpp b/src/wrappers/themis/jsthemis/secure_keygen.cpp
index 6673b9f47..5ef73a041 100644
--- a/src/wrappers/themis/jsthemis/secure_keygen.cpp
+++ b/src/wrappers/themis/jsthemis/secure_keygen.cpp
@@ -73,7 +73,7 @@ namespace jsthemis {
       const int argc = 2;
       v8::Local<v8::Value> argv[argc] = { args[0], args[1] };
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_message.cpp b/src/wrappers/themis/jsthemis/secure_message.cpp
index 3d68d8c64..024ecb9ac 100644
--- a/src/wrappers/themis/jsthemis/secure_message.cpp
+++ b/src/wrappers/themis/jsthemis/secure_message.cpp
@@ -55,7 +55,7 @@ namespace jsthemis {
       const int argc = 2;
       v8::Local<v8::Value> argv[argc] = { args[0], args[1] };
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 
diff --git a/src/wrappers/themis/jsthemis/secure_session.cpp b/src/wrappers/themis/jsthemis/secure_session.cpp
index b7753f1b7..e409601a6 100644
--- a/src/wrappers/themis/jsthemis/secure_session.cpp
+++ b/src/wrappers/themis/jsthemis/secure_session.cpp
@@ -76,7 +76,7 @@ namespace jsthemis {
       const int argc = 3;
       v8::Local<v8::Value> argv[argc] = { args[0], args[1], args[2]};
       v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
-      args.GetReturnValue().Set(cons->NewInstance(argc, argv));
+      args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
     }
   }
 


Test patch: