Skip to content

Commit 4a3a335

Browse files
committed
Upgrade to NAN 2 for Node 4 compatibility
1 parent 5892a55 commit 4a3a335

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

crypt3.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Node.js Crypt(3) implementation */
22

3-
#include <node.h>
43
#include <v8.h>
54
#include <errno.h>
65
#include <unistd.h> // for crypt if _XOPEN_SOURCE exists
@@ -9,29 +8,30 @@
98
using namespace v8;
109

1110
NAN_METHOD(Method) {
12-
NanScope();
11+
Nan::HandleScope scope;
1312

14-
if (args.Length() < 2) {
15-
return NanThrowTypeError("Wrong number of arguments");
13+
if (info.Length() < 2) {
14+
return Nan::ThrowTypeError("Wrong number of arguments");
1615
}
1716

18-
if (!args[0]->IsString() || !args[1]->IsString()) {
19-
return NanThrowTypeError("Wrong arguments");
17+
if (!info[0]->IsString() || !info[1]->IsString()) {
18+
return Nan::ThrowTypeError("Wrong arguments");
2019
}
2120

22-
v8::String::Utf8Value key(args[0]->ToString());
23-
v8::String::Utf8Value salt(args[1]->ToString());
21+
v8::String::Utf8Value key(info[0]->ToString());
22+
v8::String::Utf8Value salt(info[1]->ToString());
2423

2524
char* res = crypt(*key, *salt);
2625
if (res != NULL) {
27-
NanReturnValue(NanNew<String>(res));
26+
info.GetReturnValue().Set(Nan::New<String>(res).ToLocalChecked());
2827
} else {
29-
return NanThrowError(node::ErrnoException(errno, "crypt"));
28+
return Nan::ThrowError(Nan::NanErrnoException(errno, "crypt"));
3029
}
3130
}
3231

3332
void init(Handle<Object> exports) {
34-
exports->Set(NanNew<String>("crypt"), NanNew<FunctionTemplate>(Method)->GetFunction());
33+
exports->Set(Nan::New<String>("crypt").ToLocalChecked(),
34+
Nan::New<FunctionTemplate>(Method)->GetFunction());
3535
}
3636

3737
NODE_MODULE(crypt3, init)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"blowfish",
2121
"hash"
2222
],
23-
"dependencies": { "nan": "1 >=1.6.2" },
23+
"dependencies": { "nan": "^2.0.9" },
2424
"author": "Jaakko-Heikki Heusala <jheusala@iki.fi>",
2525
"license": "MIT",
2626
"gypfile": true

0 commit comments

Comments
 (0)