Skip to content

Commit 290317e

Browse files
committed
Make compatible with node-14 (and more?)
1 parent e3bdc28 commit 290317e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/binding.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ union any_blake2_state {
1616
};
1717

1818
#define BLAKE_FN_CAST(fn) \
19-
reinterpret_cast<uintptr_t (*)(void*, const uint8_t*, uint64_t)>(fn)
19+
((int (*)(void*, const uint8_t*, uint64_t))fn)
2020

2121
static Nan::Persistent<v8::FunctionTemplate> hash_constructor;
2222

2323
class Hash: public Nan::ObjectWrap {
2424
protected:
2525
bool initialized_;
26-
uintptr_t (*any_blake2_update)(void*, const uint8_t*, uint64_t);
27-
uintptr_t (*any_blake2_final)(void*, const uint8_t*, uint64_t);
26+
int (*any_blake2_update)(void*, const uint8_t*, uint64_t);
27+
int (*any_blake2_final)(void*, const uint8_t*, uint64_t);
2828
uint8_t outbytes;
2929
any_blake2_state state;
3030

@@ -40,7 +40,7 @@ class Hash: public Nan::ObjectWrap {
4040
Nan::SetPrototypeMethod(tpl, "copy", Copy);
4141
Nan::SetPrototypeMethod(tpl, "saveState", SaveState);
4242
Nan::SetPrototypeMethod(tpl, "restoreState", RestoreState);
43-
target->Set(Nan::New("Hash").ToLocalChecked(), tpl->GetFunction());
43+
Nan::Set(target, Nan::New("Hash").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
4444
}
4545

4646
static
@@ -70,10 +70,11 @@ class Hash: public Nan::ObjectWrap {
7070
}
7171

7272
if (info.Length() >= 3) {
73-
if (!info[2]->IsNumber()) {
73+
v8::Local<v8::Int32> dl;
74+
if (!info[2]->IsNumber() || !Nan::To<v8::Int32>(info[2]).ToLocal(&dl)) {
7475
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("digestLength must be a number").ToLocalChecked()));
7576
}
76-
digest_length = info[2]->IntegerValue();
77+
digest_length = dl->Value();
7778
}
7879
}
7980

@@ -190,7 +191,10 @@ class Hash: public Nan::ObjectWrap {
190191
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("Bad argument; need a Buffer").ToLocalChecked()));
191192
}
192193

193-
v8::Local<v8::Object> buffer_obj = info[0]->ToObject();
194+
v8::Local<v8::Object> buffer_obj;
195+
if (!Nan::To<v8::Object>(info[0]).ToLocal(&buffer_obj)) {
196+
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("Bad argument; need a Buffer").ToLocalChecked()));
197+
}
194198
const char *buffer_data = node::Buffer::Data(buffer_obj);
195199
size_t buffer_length = node::Buffer::Length(buffer_obj);
196200
obj->any_blake2_update(
@@ -284,7 +288,10 @@ class Hash: public Nan::ObjectWrap {
284288
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("Bad argument; need a Buffer").ToLocalChecked()));
285289
}
286290

287-
auto buffer_obj = info[0]->ToObject();
291+
v8::Local<v8::Object> buffer_obj;
292+
if (!Nan::To<v8::Object>(info[0]).ToLocal(&buffer_obj)) {
293+
return Nan::ThrowError(v8::Exception::TypeError(Nan::New<v8::String>("Bad argument; need a Buffer").ToLocalChecked()));
294+
}
288295
const auto buffer_data = node::Buffer::Data(buffer_obj);
289296
const auto buffer_length = node::Buffer::Length(buffer_obj);
290297
if (buffer_length != sizeof(any_blake2_state)) {

0 commit comments

Comments
 (0)