diff --git a/binding.cc b/binding.cc index 6c783ec..a8ed199 100644 --- a/binding.cc +++ b/binding.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #if defined(__APPLE__) #include @@ -87,22 +88,24 @@ int set_utimes( #endif } -class UtimesWorker : public Nan::AsyncWorker { +class UtimesWorker : public Napi::AsyncWorker { public: UtimesWorker( - v8::Local &pathHandle, + Napi::Buffer &pathHandle, const uint8_t flags, const uint64_t btime, const uint64_t mtime, const uint64_t atime, - Nan::Callback *callback - ) : Nan::AsyncWorker(callback), + const Napi::Function &callback + ) : Napi::AsyncWorker(callback), + pathHandleRef(Napi::ObjectReference::New(pathHandle, 1)), + path(pathHandle.Data()), flags(flags), btime(btime), mtime(mtime), atime(atime) { - SaveToPersistent("pathHandle", pathHandle); - path = node::Buffer::Data(pathHandle); + // SaveToPersistent("pathHandle", pathHandle); + // path = pathHandle.Data(); } ~UtimesWorker() {} @@ -112,15 +115,18 @@ class UtimesWorker : public Nan::AsyncWorker { if (result > 0) result = -result; } - void HandleOKCallback () { - Nan::HandleScope scope; - v8::Local argv[] = { - Nan::New(result) - }; - callback->Call(1, argv, async_resource); + void OnOK () { + Napi::HandleScope scope(Env()); + + Callback().Call({ + Napi::Number::New(Env(), result) + }); + + pathHandleRef.Unref(); } private: + Napi::ObjectReference pathHandleRef; const char* path; const uint8_t flags; const uint64_t btime; @@ -129,44 +135,50 @@ class UtimesWorker : public Nan::AsyncWorker { int result; }; -NAN_METHOD(utimes) { +void utimes(const Napi::CallbackInfo& info) { if ( info.Length() != 6 || - !node::Buffer::HasInstance(info[0]) || - !info[1]->IsUint32() || - !info[2]->IsNumber() || - !info[3]->IsNumber() || - !info[4]->IsNumber() || - !info[5]->IsFunction() + !info[0].IsBuffer() || + !info[1].IsNumber() || + !info[2].IsNumber() || + !info[3].IsNumber() || + !info[4].IsNumber() || + !info[5].IsFunction() ) { - return Nan::ThrowError( - "bad arguments, expected: (" + throw Napi::Error::New(info.Env(), "bad arguments, expected: (" "buffer path, int flags, " "seconds btime, seconds mtime, seconds atime, " "function callback" ")" - ); + ); } - v8::Local pathHandle = info[0].As(); - const uint8_t flags = info[1]->Uint32Value(); - const uint64_t btime = info[2]->IntegerValue(); - const uint64_t mtime = info[3]->IntegerValue(); - const uint64_t atime = info[4]->IntegerValue(); - Nan::Callback *callback = new Nan::Callback(info[5].As()); - Nan::AsyncQueueWorker(new UtimesWorker( + + Napi::Buffer pathHandle = info[0].As>(); + const uint8_t flags = info[1].As().Uint32Value(); + const uint64_t btime = info[2].As().Int64Value(); + const uint64_t mtime = info[3].As().Int64Value(); + const uint64_t atime = info[4].As().Int64Value(); + Napi::Function callback = info[5].As(); + + UtimesWorker *worker = new UtimesWorker( pathHandle, flags, btime, mtime, atime, callback - )); + ); + worker->Queue(); } -NAN_MODULE_INIT(Init) { - NAN_EXPORT(target, utimes); +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports.Set( + Napi::String::New(env, "utimes"), + Napi::Function::New(env, utimes) + ); + return exports; } -NODE_MODULE(binding, Init) +NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) // S.D.G. diff --git a/binding.gyp b/binding.gyp index ad51e1f..5c756fa 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,11 +2,30 @@ "targets": [ { "target_name": "binding", + "cflags!": [ "-fno-exceptions" ], + "cflags_cc!": [ "-fno-exceptions" ], + "xcode_settings": { "GCC_ENABLE_CPP_EXCEPTIONS": "YES", + "CLANG_CXX_LIBRARY": "libc++", + "MACOSX_DEPLOYMENT_TARGET": "10.7", + }, + "msvs_settings": { + "VCCLCompilerTool": { "ExceptionHandling": 1 }, + }, "sources": [ "binding.cc" ], - "include_dirs": [ "