From 8310ff1a9c2e52266dac90da29297adae27ec1c1 Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Fri, 13 Nov 2015 21:32:32 +0300 Subject: [PATCH] Fix for latest nan and eccrypto Fixes #17 --- package.json | 6 +++--- src/worker.cc | 51 +++++++++++++++++++++++---------------------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 2f5bea6..e59b441 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,10 @@ "bn.js": "^3.0.1", "bs58": "^2.0.0", "buffer-equal": "~0.0.1", - "eccrypto": "^1.0.1", - "es6-promise": "^2.0.1", + "eccrypto": "^1.0.3", + "es6-promise": "^3.0.2", "hash.js": "^1.0.2", - "nan": "^1.4.1", + "nan": "^2.1.0", "object-assign": "^2.0.0", "sha.js": "^2.3.1", "webworkify": "^1.0.1" diff --git a/src/worker.cc b/src/worker.cc index 5f15f0e..8c4cf70 100644 --- a/src/worker.cc +++ b/src/worker.cc @@ -13,13 +13,13 @@ using v8::Number; static const uint64_t MAX_SAFE_INTEGER = 9007199254740991ULL; -class PowWorker : public NanAsyncWorker { +class PowWorker : public Nan::AsyncWorker { public: - PowWorker(NanCallback* callback, + PowWorker(Nan::Callback* callback, size_t pool_size, uint64_t target, uint8_t* initial_hash) - : NanAsyncWorker(callback), + : Nan::AsyncWorker(callback), pool_size(pool_size), target(target), initial_hash(initial_hash) {} @@ -40,17 +40,16 @@ class PowWorker : public NanAsyncWorker { // this function will be run inside the main event loop // so it is safe to use V8 again void HandleOKCallback () { - NanScope(); if (error) { Local argv[1]; if (error == -1) { - argv[0] = NanError("Max safe integer overflow"); + argv[0] = Nan::Error("Max safe integer overflow"); } else { - argv[0] = NanError("Internal error"); + argv[0] = Nan::Error("Internal error"); } callback->Call(1, argv); } else { - Local argv[] = {NanNull(), NanNew(nonce)}; + Local argv[] = {Nan::Null(), Nan::New(nonce)}; callback->Call(2, argv); } } @@ -64,39 +63,35 @@ class PowWorker : public NanAsyncWorker { }; NAN_METHOD(PowAsync) { - NanScope(); - - if (args.Length() != 4 || - !args[0]->IsNumber() || // pool_size - !args[1]->IsNumber() || // target - !node::Buffer::HasInstance(args[2]) || // initial_hash - !args[3]->IsFunction()) { // cb - return NanThrowError("Bad input"); + if (info.Length() != 4 || + !info[0]->IsNumber() || // pool_size + !info[1]->IsNumber() || // target + !node::Buffer::HasInstance(info[2]) || // initial_hash + !info[3]->IsFunction()) { // cb + return Nan::ThrowError("Bad input"); } - size_t pool_size = args[0]->Uint32Value(); - uint64_t target = args[1]->IntegerValue(); - char* buf = node::Buffer::Data(args[2]); - size_t length = node::Buffer::Length(args[2]); + size_t pool_size = info[0]->Uint32Value(); + uint64_t target = info[1]->IntegerValue(); + char* buf = node::Buffer::Data(info[2]); + size_t length = node::Buffer::Length(info[2]); if (pool_size < 1 || pool_size > MAX_POOL_SIZE || buf == NULL || length != HASH_SIZE) { - return NanThrowError("Bad input"); + return Nan::ThrowError("Bad input"); } - // TODO(Kagami): Do we need to process `std::bad_alloc`? uint8_t* initial_hash = new uint8_t[length]; memcpy(initial_hash, buf, length); - NanCallback* callback = new NanCallback(args[3].As()); - NanAsyncQueueWorker(new PowWorker(callback, pool_size, target, initial_hash)); - NanReturnUndefined(); + Nan::Callback* callback = new Nan::Callback(info[3].As()); + Nan::AsyncQueueWorker( + new PowWorker(callback, pool_size, target, initial_hash)); } -void InitAll(Handle exports) { - exports->Set( - NanNew("powAsync"), - NanNew(PowAsync)->GetFunction()); +NAN_MODULE_INIT(InitAll) { + Nan::Set(target, Nan::New("powAsync").ToLocalChecked(), + Nan::GetFunction(Nan::New(PowAsync)).ToLocalChecked()); } NODE_MODULE(worker, InitAll)