From 1666a39d050a5a8229b451aa75f6ab9477a7b433 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Tue, 7 Jan 2020 23:04:21 +0000 Subject: [PATCH 1/4] [Node12.x] Add Node 12.x Support --- binding.gyp | 1 + crypt3.cc | 14 +++++++++----- crypt3async.cc | 23 ++++++++++++++--------- package.json | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/binding.gyp b/binding.gyp index 68420a2..252e57b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -13,6 +13,7 @@ { "target_name": "crypt3async", "sources": [ "crypt3async.cc" ], + "include_dirs" : [ "ToString()); - v8::String::Utf8Value salt(info[1]->ToString()); + Nan::Utf8String key(info[0]); + Nan::Utf8String salt(info[1]); char* res = crypt(*key, *salt); if (res != NULL) { @@ -29,9 +29,13 @@ NAN_METHOD(Method) { } } -void init(Handle exports) { - exports->Set(Nan::New("crypt").ToLocalChecked(), - Nan::New(Method)->GetFunction()); + +void init(Local exports) { + Nan::Set( + exports, + Nan::New("crypt").ToLocalChecked(), + Nan::GetFunction(Nan::New(Method)).ToLocalChecked() + ); } NODE_MODULE(crypt3, init) diff --git a/crypt3async.cc b/crypt3async.cc index 83ba97d..f5de368 100644 --- a/crypt3async.cc +++ b/crypt3async.cc @@ -5,6 +5,7 @@ * Tested in node.js v4.4.2 LTS in Ubuntu Linux */ +#include #include #include #include @@ -67,22 +68,26 @@ namespace asyncAddon { */ static void WorkAsyncComplete(uv_work_t *req,int status) { Isolate * isolate = Isolate::GetCurrent(); - v8::HandleScope handleScope(isolate); + v8::HandleScope handle_scope(isolate); Work *work = static_cast(req->data); + Local context = isolate -> GetCurrentContext() ; + Local recv = Undefined( isolate ) ; + const int error = work->error; const char *result = work->result.c_str(); + if(error == 0) { Local argv[2] = { Undefined(isolate), - String::NewFromUtf8(isolate, result) + String::NewFromUtf8(isolate, result, v8::NewStringType::kNormal).ToLocalChecked() }; // https://stackoverflow.com/questions/13826803/calling-javascript-function-from-a-c-callback-in-v8/28554065#28554065 - Local::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 2, argv); + Local::New(isolate, work->callback)->Call(context, recv, 2, argv); } else { - Local argv[1] = { String::NewFromUtf8(isolate, result) }; + Local argv[1] = { String::NewFromUtf8(isolate, result, v8::NewStringType::kNormal).ToLocalChecked() }; // https://stackoverflow.com/questions/13826803/calling-javascript-function-from-a-c-callback-in-v8/28554065#28554065 - Local::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv); + Local::New(isolate, work->callback)->Call(context, recv, 1, argv); } work->callback.Reset(); @@ -99,20 +104,20 @@ namespace asyncAddon { work->request.data = work; if (args.Length() < 3) { - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))); + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments", v8::NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() ) { - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments"))); + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments", v8::NewStringType::kNormal).ToLocalChecked())); return; } - v8::String::Utf8Value v8key(args[0]->ToString()); + Nan::Utf8String v8key(args[0]); string key = std::string(*v8key); work->key = key; - v8::String::Utf8Value v8salt(args[1]->ToString()); + Nan::Utf8String v8salt(args[1]); string salt = std::string(*v8salt); work->salt = salt; diff --git a/package.json b/package.json index 8bc2027..16c3dd5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "hash" ], "dependencies": { - "nan": "^2.1.0" + "nan": "^2.14.0" }, "optionalDependencies": { "q": "^1.0.1" From 7fecad86492a134df32f74ec6fa96578714d5b4c Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Thu, 9 Jan 2020 10:06:22 +0000 Subject: [PATCH 2/4] [Package] Bump Version --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 16c3dd5..35a763f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypt3", - "version": "1.0.0", + "version": "1.1.0", "description": "Node.js crypt(3) bindings", "main": "src/index.js", "scripts": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/sendanor/node-crypt3.git" + "url": "https://github.com/ahmedbodi/node-crypt3.git" }, "keywords": [ "crypt", @@ -27,6 +27,7 @@ "q": "^1.0.1" }, "author": "Jaakko-Heikki Heusala ", + "maintainer": "Ahmed Bodiwala ", "license": "MIT", "gypfile": true } From 3b7c16bdbb3dc061ddd7852ea70b3bafd71d0152 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Thu, 9 Jan 2020 11:08:24 +0000 Subject: [PATCH 3/4] [CI] Test on Node Versions 4 through 12 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb608a1..7b49075 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ language: node_js node_js: - 4 - - "0.12" - - "0.10" + - 6 + - 8 + - 10 + - 12 addons: apt: sources: From 4937bb8b46f4358c16a58f8ccd9eb97f1bf8b9d9 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Thu, 9 Jan 2020 11:16:12 +0000 Subject: [PATCH 4/4] [CI] Test Against Node v13.6.0 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7b49075..6dd96a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ node_js: - 8 - 10 - 12 + - 13.6.0 addons: apt: sources: