diff --git a/fuse-bindings.cc b/fuse-bindings.cc index b2b133a..b84323c 100644 --- a/fuse-bindings.cc +++ b/fuse-bindings.cc @@ -15,6 +15,9 @@ using namespace v8; +#define LOCAL_STRING(s) Nan::New(s).ToLocalChecked() +#define LOOKUP_CALLBACK(map, name) map->Has(LOCAL_STRING(name)) ? new Nan::Callback(map->Get(LOCAL_STRING(name)).As()) : NULL + enum bindings_ops_t { OP_INIT = 0, OP_ERROR, @@ -51,8 +54,8 @@ enum bindings_ops_t { OP_DESTROY }; -static Persistent buffer_constructor; -static NanCallback *callback_constructor; +static Nan::Persistent buffer_constructor; +static Nan::Callback *callback_constructor; static struct stat empty_stat; struct bindings_t { @@ -72,41 +75,41 @@ struct bindings_t { uv_async_t async; // methods - NanCallback *ops_init; - NanCallback *ops_error; - NanCallback *ops_access; - NanCallback *ops_statfs; - NanCallback *ops_getattr; - NanCallback *ops_fgetattr; - NanCallback *ops_flush; - NanCallback *ops_fsync; - NanCallback *ops_fsyncdir; - NanCallback *ops_readdir; - NanCallback *ops_truncate; - NanCallback *ops_ftruncate; - NanCallback *ops_readlink; - NanCallback *ops_chown; - NanCallback *ops_chmod; - NanCallback *ops_mknod; - NanCallback *ops_setxattr; - NanCallback *ops_getxattr; - NanCallback *ops_open; - NanCallback *ops_opendir; - NanCallback *ops_read; - NanCallback *ops_write; - NanCallback *ops_release; - NanCallback *ops_releasedir; - NanCallback *ops_create; - NanCallback *ops_utimens; - NanCallback *ops_unlink; - NanCallback *ops_rename; - NanCallback *ops_link; - NanCallback *ops_symlink; - NanCallback *ops_mkdir; - NanCallback *ops_rmdir; - NanCallback *ops_destroy; + Nan::Callback *ops_init; + Nan::Callback *ops_error; + Nan::Callback *ops_access; + Nan::Callback *ops_statfs; + Nan::Callback *ops_getattr; + Nan::Callback *ops_fgetattr; + Nan::Callback *ops_flush; + Nan::Callback *ops_fsync; + Nan::Callback *ops_fsyncdir; + Nan::Callback *ops_readdir; + Nan::Callback *ops_truncate; + Nan::Callback *ops_ftruncate; + Nan::Callback *ops_readlink; + Nan::Callback *ops_chown; + Nan::Callback *ops_chmod; + Nan::Callback *ops_mknod; + Nan::Callback *ops_setxattr; + Nan::Callback *ops_getxattr; + Nan::Callback *ops_open; + Nan::Callback *ops_opendir; + Nan::Callback *ops_read; + Nan::Callback *ops_write; + Nan::Callback *ops_release; + Nan::Callback *ops_releasedir; + Nan::Callback *ops_create; + Nan::Callback *ops_utimens; + Nan::Callback *ops_unlink; + Nan::Callback *ops_rename; + Nan::Callback *ops_link; + Nan::Callback *ops_symlink; + Nan::Callback *ops_mkdir; + Nan::Callback *ops_rmdir; + Nan::Callback *ops_destroy; - NanCallback *callback; + Nan::Callback *callback; // method data bindings_ops_t op; @@ -151,18 +154,19 @@ static void bindings_unmount (char *path) { mutex_unlock(&mutex); } - -#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION && NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION) NAN_INLINE v8::Local bindings_buffer (char *data, size_t length) { - Local buf = NanNew(buffer_constructor)->NewInstance(0, NULL); - buf->Set(NanNew("length"), NanNew(length)); + Local buf = Nan::New(buffer_constructor)->NewInstance(0, NULL); + Local k = LOCAL_STRING("length"); + Local v = Nan::New(length); + buf->Set(k, v); buf->SetIndexedPropertiesToExternalArrayData((char *) data, kExternalUnsignedByteArray, length); return buf; } #else void noop (char *data, void *hint) {} NAN_INLINE v8::Local bindings_buffer (char *data, size_t length) { - return NanNewBufferHandle(data, length, noop, NULL); + return Nan::NewBuffer(data, length, noop, NULL).ToLocalChecked(); } #endif @@ -675,7 +679,7 @@ static thread_fn_rtn_t bindings_thread (void *data) { #ifndef _WIN32 NAN_INLINE static Local bindings_get_date (struct timespec *out) { int ms = (out->tv_nsec / 1000); - return NanNew(out->tv_sec * 1000 + ms); + return Nan::New(out->tv_sec * 1000 + ms).ToLocalChecked(); } NAN_INLINE static void bindings_set_date (struct timespec *out, Local date) { @@ -688,7 +692,7 @@ NAN_INLINE static void bindings_set_date (struct timespec *out, Local date } #else NAN_INLINE static Local bindings_get_date (time_t *out) { - return NanNew(*out * 1000.0); + return Nan::New(*out * 1000.0); } NAN_INLINE static void bindings_set_date (time_t *out, Local date) { @@ -699,91 +703,90 @@ NAN_INLINE static void bindings_set_date (time_t *out, Local date) { #endif NAN_INLINE static void bindings_set_stat (struct stat *stat, Local obj) { - if (obj->Has(NanNew("dev"))) stat->st_dev = obj->Get(NanNew("dev"))->NumberValue(); - if (obj->Has(NanNew("ino"))) stat->st_ino = obj->Get(NanNew("ino"))->NumberValue(); - if (obj->Has(NanNew("mode"))) stat->st_mode = obj->Get(NanNew("mode"))->Uint32Value(); - if (obj->Has(NanNew("nlink"))) stat->st_nlink = obj->Get(NanNew("nlink"))->NumberValue(); - if (obj->Has(NanNew("uid"))) stat->st_uid = obj->Get(NanNew("uid"))->NumberValue(); - if (obj->Has(NanNew("gid"))) stat->st_gid = obj->Get(NanNew("gid"))->NumberValue(); - if (obj->Has(NanNew("rdev"))) stat->st_rdev = obj->Get(NanNew("rdev"))->NumberValue(); - if (obj->Has(NanNew("size"))) stat->st_size = obj->Get(NanNew("size"))->NumberValue(); + if (obj->Has(LOCAL_STRING("dev"))) stat->st_dev = obj->Get(LOCAL_STRING("dev"))->NumberValue(); + if (obj->Has(LOCAL_STRING("ino"))) stat->st_ino = obj->Get(LOCAL_STRING("ino"))->NumberValue(); + if (obj->Has(LOCAL_STRING("mode"))) stat->st_mode = obj->Get(LOCAL_STRING("mode"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("nlink"))) stat->st_nlink = obj->Get(LOCAL_STRING("nlink"))->NumberValue(); + if (obj->Has(LOCAL_STRING("uid"))) stat->st_uid = obj->Get(LOCAL_STRING("uid"))->NumberValue(); + if (obj->Has(LOCAL_STRING("gid"))) stat->st_gid = obj->Get(LOCAL_STRING("gid"))->NumberValue(); + if (obj->Has(LOCAL_STRING("rdev"))) stat->st_rdev = obj->Get(LOCAL_STRING("rdev"))->NumberValue(); + if (obj->Has(LOCAL_STRING("size"))) stat->st_size = obj->Get(LOCAL_STRING("size"))->NumberValue(); #ifndef _WIN32 - if (obj->Has(NanNew("blocks"))) stat->st_blocks = obj->Get(NanNew("blocks"))->NumberValue(); - if (obj->Has(NanNew("blksize"))) stat->st_blksize = obj->Get(NanNew("blksize"))->NumberValue(); + if (obj->Has(LOCAL_STRING("blocks"))) stat->st_blocks = obj->Get(LOCAL_STRING("blocks"))->NumberValue(); + if (obj->Has(LOCAL_STRING("blksize"))) stat->st_blksize = obj->Get(LOCAL_STRING("blksize"))->NumberValue(); #endif #ifdef __APPLE__ - if (obj->Has(NanNew("mtime"))) bindings_set_date(&stat->st_mtimespec, obj->Get(NanNew("mtime")).As()); - if (obj->Has(NanNew("ctime"))) bindings_set_date(&stat->st_ctimespec, obj->Get(NanNew("ctime")).As()); - if (obj->Has(NanNew("atime"))) bindings_set_date(&stat->st_atimespec, obj->Get(NanNew("atime")).As()); + if (obj->Has(LOCAL_STRING("mtime"))) bindings_set_date(&stat->st_mtimespec, obj->Get(LOCAL_STRING("mtime")).As()); + if (obj->Has(LOCAL_STRING("ctime"))) bindings_set_date(&stat->st_ctimespec, obj->Get(LOCAL_STRING("ctime")).As()); + if (obj->Has(LOCAL_STRING("atime"))) bindings_set_date(&stat->st_atimespec, obj->Get(LOCAL_STRING("atime")).As()); #elif defined(_WIN32) - if (obj->Has(NanNew("mtime"))) bindings_set_date(&stat->st_mtime, obj->Get(NanNew("mtime")).As()); - if (obj->Has(NanNew("ctime"))) bindings_set_date(&stat->st_ctime, obj->Get(NanNew("ctime")).As()); - if (obj->Has(NanNew("atime"))) bindings_set_date(&stat->st_atime, obj->Get(NanNew("atime")).As()); + if (obj->Has(LOCAL_STRING("mtime"))) bindings_set_date(&stat->st_mtime, obj->Get(LOCAL_STRING("mtime")).As()); + if (obj->Has(LOCAL_STRING("ctime"))) bindings_set_date(&stat->st_ctime, obj->Get(LOCAL_STRING("ctime")).As()); + if (obj->Has(LOCAL_STRING("atime"))) bindings_set_date(&stat->st_atime, obj->Get(LOCAL_STRING("atime")).As()); #else - if (obj->Has(NanNew("mtime"))) bindings_set_date(&stat->st_mtim, obj->Get(NanNew("mtime")).As()); - if (obj->Has(NanNew("ctime"))) bindings_set_date(&stat->st_ctim, obj->Get(NanNew("ctime")).As()); - if (obj->Has(NanNew("atime"))) bindings_set_date(&stat->st_atim, obj->Get(NanNew("atime")).As()); + if (obj->Has(LOCAL_STRING("mtime"))) bindings_set_date(&stat->st_mtim, obj->Get(LOCAL_STRING("mtime")).As()); + if (obj->Has(LOCAL_STRING("ctime"))) bindings_set_date(&stat->st_ctim, obj->Get(LOCAL_STRING("ctime")).As()); + if (obj->Has(LOCAL_STRING("atime"))) bindings_set_date(&stat->st_atim, obj->Get(LOCAL_STRING("atime")).As()); #endif } NAN_INLINE static void bindings_set_statfs (struct statvfs *statfs, Local obj) { // from http://linux.die.net/man/2/stat - if (obj->Has(NanNew("bsize"))) statfs->f_bsize = obj->Get(NanNew("bsize"))->Uint32Value(); - if (obj->Has(NanNew("frsize"))) statfs->f_frsize = obj->Get(NanNew("frsize"))->Uint32Value(); - if (obj->Has(NanNew("blocks"))) statfs->f_blocks = obj->Get(NanNew("blocks"))->Uint32Value(); - if (obj->Has(NanNew("bfree"))) statfs->f_bfree = obj->Get(NanNew("bfree"))->Uint32Value(); - if (obj->Has(NanNew("bavail"))) statfs->f_bavail = obj->Get(NanNew("bavail"))->Uint32Value(); - if (obj->Has(NanNew("files"))) statfs->f_files = obj->Get(NanNew("files"))->Uint32Value(); - if (obj->Has(NanNew("ffree"))) statfs->f_ffree = obj->Get(NanNew("ffree"))->Uint32Value(); - if (obj->Has(NanNew("favail"))) statfs->f_favail = obj->Get(NanNew("favail"))->Uint32Value(); - if (obj->Has(NanNew("fsid"))) statfs->f_fsid = obj->Get(NanNew("fsid"))->Uint32Value(); - if (obj->Has(NanNew("flag"))) statfs->f_flag = obj->Get(NanNew("flag"))->Uint32Value(); - if (obj->Has(NanNew("namemax"))) statfs->f_namemax = obj->Get(NanNew("namemax"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("bsize"))) statfs->f_bsize = obj->Get(LOCAL_STRING("bsize"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("frsize"))) statfs->f_frsize = obj->Get(LOCAL_STRING("frsize"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("blocks"))) statfs->f_blocks = obj->Get(LOCAL_STRING("blocks"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("bfree"))) statfs->f_bfree = obj->Get(LOCAL_STRING("bfree"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("bavail"))) statfs->f_bavail = obj->Get(LOCAL_STRING("bavail"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("files"))) statfs->f_files = obj->Get(LOCAL_STRING("files"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("ffree"))) statfs->f_ffree = obj->Get(LOCAL_STRING("ffree"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("favail"))) statfs->f_favail = obj->Get(LOCAL_STRING("favail"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("fsid"))) statfs->f_fsid = obj->Get(LOCAL_STRING("fsid"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("flag"))) statfs->f_flag = obj->Get(LOCAL_STRING("flag"))->Uint32Value(); + if (obj->Has(LOCAL_STRING("namemax"))) statfs->f_namemax = obj->Get(LOCAL_STRING("namemax"))->Uint32Value(); } NAN_INLINE static void bindings_set_dirs (bindings_t *b, Local dirs) { + Nan::HandleScope scope; for (uint32_t i = 0; i < dirs->Length(); i++) { - NanUtf8String dir(dirs->Get(i)); + Nan::Utf8String dir(dirs->Get(i)); if (b->filler(b->data, *dir, &empty_stat, 0)) break; } } NAN_METHOD(OpCallback) { - NanScope(); - - bindings_t *b = bindings_mounted[args[0]->Uint32Value()]; - b->result = (args.Length() > 1 && args[1]->IsNumber()) ? args[1]->Uint32Value() : 0; + bindings_t *b = bindings_mounted[info[0]->Uint32Value()]; + b->result = (info.Length() > 1 && info[1]->IsNumber()) ? info[1]->Uint32Value() : 0; bindings_current = NULL; if (!b->result) { switch (b->op) { case OP_STATFS: { - if (args.Length() > 2 && args[2]->IsObject()) bindings_set_statfs((struct statvfs *) b->data, args[2].As()); + if (info.Length() > 2 && info[2]->IsObject()) bindings_set_statfs((struct statvfs *) b->data, info[2].As()); } break; case OP_GETATTR: case OP_FGETATTR: { - if (args.Length() > 2 && args[2]->IsObject()) bindings_set_stat((struct stat *) b->data, args[2].As()); + if (info.Length() > 2 && info[2]->IsObject()) bindings_set_stat((struct stat *) b->data, info[2].As()); } break; case OP_READDIR: { - if (args.Length() > 2 && args[2]->IsArray()) bindings_set_dirs(b, args[2].As()); + if (info.Length() > 2 && info[2]->IsArray()) bindings_set_dirs(b, info[2].As()); } break; case OP_CREATE: case OP_OPEN: case OP_OPENDIR: { - if (args.Length() > 2 && args[2]->IsNumber()) { - b->info->fh = args[2].As()->Uint32Value(); + if (info.Length() > 2 && info[2]->IsNumber()) { + b->info->fh = info[2].As()->Uint32Value(); } } break; case OP_READLINK: { - if (args.Length() > 2 && args[2]->IsString()) { - NanUtf8String path(args[2]); + if (info.Length() > 2 && info[2]->IsString()) { + Nan::Utf8String path(info[2]); strcpy((char *) b->data, *path); } } @@ -819,16 +822,15 @@ NAN_METHOD(OpCallback) { } semaphore_signal(&(b->semaphore)); - NanReturnUndefined(); } -NAN_INLINE static void bindings_call_op (bindings_t *b, NanCallback *fn, int argc, Local *argv) { +NAN_INLINE static void bindings_call_op (bindings_t *b, Nan::Callback *fn, int argc, Local *argv) { if (fn == NULL) semaphore_signal(&(b->semaphore)); else fn->Call(argc, argv); } static void bindings_dispatch (uv_async_t* handle, int status) { - NanScope(); + Nan::HandleScope scope; bindings_t *b = bindings_current = (bindings_t *) handle->data; Local callback = b->callback->GetFunction(); @@ -848,72 +850,72 @@ static void bindings_dispatch (uv_async_t* handle, int status) { return; case OP_STATFS: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_statfs, 2, tmp); } return; case OP_FGETATTR: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), callback}; bindings_call_op(b, b->ops_fgetattr, 3, tmp); } return; case OP_GETATTR: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_getattr, 2, tmp); } return; case OP_READDIR: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_readdir, 2, tmp); } return; case OP_CREATE: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_create, 3, tmp); } return; case OP_TRUNCATE: { - Local tmp[] = {NanNew(b->path), NanNew(b->length), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->length), callback}; bindings_call_op(b, b->ops_truncate, 3, tmp); } return; case OP_FTRUNCATE: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), NanNew(b->length), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), Nan::New(b->length), callback}; bindings_call_op(b, b->ops_ftruncate, 4, tmp); } return; case OP_ACCESS: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_access, 3, tmp); } return; case OP_OPEN: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_open, 3, tmp); } return; case OP_OPENDIR: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_opendir, 3, tmp); } return; case OP_WRITE: { Local tmp[] = { - NanNew(b->path), - NanNew(b->info->fh), + LOCAL_STRING(b->path), + Nan::New(b->info->fh), bindings_buffer((char *) b->data, b->length), - NanNew(b->length), - NanNew(b->offset), + Nan::New(b->length), // TODO: remove me + Nan::New(b->offset), callback }; bindings_call_op(b, b->ops_write, 6, tmp); @@ -922,11 +924,11 @@ static void bindings_dispatch (uv_async_t* handle, int status) { case OP_READ: { Local tmp[] = { - NanNew(b->path), - NanNew(b->info->fh), + LOCAL_STRING(b->path), + Nan::New(b->info->fh), bindings_buffer((char *) b->data, b->length), - NanNew(b->length), - NanNew(b->offset), + Nan::New(b->length), // TODO: remove me + Nan::New(b->offset), callback }; bindings_call_op(b, b->ops_read, 6, tmp); @@ -934,73 +936,73 @@ static void bindings_dispatch (uv_async_t* handle, int status) { return; case OP_RELEASE: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), callback}; bindings_call_op(b, b->ops_release, 3, tmp); } return; case OP_RELEASEDIR: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), callback}; bindings_call_op(b, b->ops_releasedir, 3, tmp); } return; case OP_UNLINK: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_unlink, 2, tmp); } return; case OP_RENAME: { - Local tmp[] = {NanNew(b->path), NanNew((char *) b->data), callback}; + Local tmp[] = {LOCAL_STRING(b->path), LOCAL_STRING((char *) b->data), callback}; bindings_call_op(b, b->ops_rename, 3, tmp); } return; case OP_LINK: { - Local tmp[] = {NanNew(b->path), NanNew((char *) b->data), callback}; + Local tmp[] = {LOCAL_STRING(b->path), LOCAL_STRING((char *) b->data), callback}; bindings_call_op(b, b->ops_link, 3, tmp); } return; case OP_SYMLINK: { - Local tmp[] = {NanNew(b->path), NanNew((char *) b->data), callback}; + Local tmp[] = {LOCAL_STRING(b->path), LOCAL_STRING((char *) b->data), callback}; bindings_call_op(b, b->ops_symlink, 3, tmp); } return; case OP_CHMOD: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_chmod, 3, tmp); } return; case OP_MKNOD: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), NanNew(b->dev), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), Nan::New(b->dev), callback}; bindings_call_op(b, b->ops_mknod, 4, tmp); } return; case OP_CHOWN: { - Local tmp[] = {NanNew(b->path), NanNew(b->uid), NanNew(b->gid), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->uid), Nan::New(b->gid), callback}; bindings_call_op(b, b->ops_chown, 4, tmp); } return; case OP_READLINK: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_readlink, 2, tmp); } return; case OP_SETXATTR: { Local tmp[] = { - NanNew(b->path), - NanNew(b->name), + LOCAL_STRING(b->path), + LOCAL_STRING(b->name), bindings_buffer((char *) b->data, b->length), - NanNew(b->length), - NanNew(b->offset), - NanNew(b->mode), + Nan::New(b->length), + Nan::New(b->offset), + Nan::New(b->mode), callback }; bindings_call_op(b, b->ops_setxattr, 7, tmp); @@ -1009,11 +1011,11 @@ static void bindings_dispatch (uv_async_t* handle, int status) { case OP_GETXATTR: { Local tmp[] = { - NanNew(b->path), - NanNew(b->name), + LOCAL_STRING(b->path), + LOCAL_STRING(b->name), bindings_buffer((char *) b->data, b->length), - NanNew(b->length), - NanNew(b->offset), + Nan::New(b->length), + Nan::New(b->offset), callback }; bindings_call_op(b, b->ops_getxattr, 6, tmp); @@ -1021,13 +1023,13 @@ static void bindings_dispatch (uv_async_t* handle, int status) { return; case OP_MKDIR: { - Local tmp[] = {NanNew(b->path), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_mkdir, 3, tmp); } return; case OP_RMDIR: { - Local tmp[] = {NanNew(b->path), callback}; + Local tmp[] = {LOCAL_STRING(b->path), callback}; bindings_call_op(b, b->ops_rmdir, 2, tmp); } return; @@ -1044,25 +1046,25 @@ static void bindings_dispatch (uv_async_t* handle, int status) { #else struct timespec *tv = (struct timespec *) b->data; #endif - Local tmp[] = {NanNew(b->path), bindings_get_date(tv), bindings_get_date(tv + 1), callback}; + Local tmp[] = {LOCAL_STRING(b->path), bindings_get_date(tv), bindings_get_date(tv + 1), callback}; bindings_call_op(b, b->ops_utimens, 4, tmp); } return; case OP_FLUSH: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), callback}; bindings_call_op(b, b->ops_flush, 3, tmp); } return; case OP_FSYNC: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_fsync, 4, tmp); } return; case OP_FSYNCDIR: { - Local tmp[] = {NanNew(b->path), NanNew(b->info->fh), NanNew(b->mode), callback}; + Local tmp[] = {LOCAL_STRING(b->path), Nan::New(b->info->fh), Nan::New(b->mode), callback}; bindings_call_op(b, b->ops_fsyncdir, 4, tmp); } return; @@ -1093,15 +1095,13 @@ static int bindings_alloc () { } NAN_METHOD(Mount) { - NanScope(); - - if (!args[0]->IsString()) return NanThrowError("mnt must be a string"); + if (!info[0]->IsString()) return Nan::ThrowError("mnt must be a string"); mutex_lock(&mutex); int index = bindings_alloc(); mutex_unlock(&mutex); - if (index == -1) return NanThrowError("You cannot mount more than 1024 filesystem in one process"); + if (index == -1) return Nan::ThrowError("You cannot mount more than 1024 filesystem in one process"); mutex_lock(&mutex); bindings_t *b = bindings_mounted[index]; @@ -1110,53 +1110,53 @@ NAN_METHOD(Mount) { memset(&empty_stat, 0, sizeof(empty_stat)); memset(b, 0, sizeof(bindings_t)); - NanUtf8String path(args[0]); - Local ops = args[1].As(); + Nan::Utf8String path(info[0]); + Local ops = info[1].As(); - b->ops_init = ops->Has(NanNew("init")) ? new NanCallback(ops->Get(NanNew("init")).As()) : NULL; - b->ops_error = ops->Has(NanNew("error")) ? new NanCallback(ops->Get(NanNew("error")).As()) : NULL; - b->ops_access = ops->Has(NanNew("access")) ? new NanCallback(ops->Get(NanNew("access")).As()) : NULL; - b->ops_statfs = ops->Has(NanNew("statfs")) ? new NanCallback(ops->Get(NanNew("statfs")).As()) : NULL; - b->ops_getattr = ops->Has(NanNew("getattr")) ? new NanCallback(ops->Get(NanNew("getattr")).As()) : NULL; - b->ops_fgetattr = ops->Has(NanNew("fgetattr")) ? new NanCallback(ops->Get(NanNew("fgetattr")).As()) : NULL; - b->ops_flush = ops->Has(NanNew("flush")) ? new NanCallback(ops->Get(NanNew("flush")).As()) : NULL; - b->ops_fsync = ops->Has(NanNew("fsync")) ? new NanCallback(ops->Get(NanNew("fsync")).As()) : NULL; - b->ops_fsyncdir = ops->Has(NanNew("fsyncdir")) ? new NanCallback(ops->Get(NanNew("fsyncdir")).As()) : NULL; - b->ops_readdir = ops->Has(NanNew("readdir")) ? new NanCallback(ops->Get(NanNew("readdir")).As()) : NULL; - b->ops_truncate = ops->Has(NanNew("truncate")) ? new NanCallback(ops->Get(NanNew("truncate")).As()) : NULL; - b->ops_ftruncate = ops->Has(NanNew("ftruncate")) ? new NanCallback(ops->Get(NanNew("ftruncate")).As()) : NULL; - b->ops_readlink = ops->Has(NanNew("readlink")) ? new NanCallback(ops->Get(NanNew("readlink")).As()) : NULL; - b->ops_chown = ops->Has(NanNew("chown")) ? new NanCallback(ops->Get(NanNew("chown")).As()) : NULL; - b->ops_chmod = ops->Has(NanNew("chmod")) ? new NanCallback(ops->Get(NanNew("chmod")).As()) : NULL; - b->ops_mknod = ops->Has(NanNew("mknod")) ? new NanCallback(ops->Get(NanNew("mknod")).As()) : NULL; - b->ops_setxattr = ops->Has(NanNew("setxattr")) ? new NanCallback(ops->Get(NanNew("setxattr")).As()) : NULL; - b->ops_getxattr = ops->Has(NanNew("getxattr")) ? new NanCallback(ops->Get(NanNew("getxattr")).As()) : NULL; - b->ops_open = ops->Has(NanNew("open")) ? new NanCallback(ops->Get(NanNew("open")).As()) : NULL; - b->ops_opendir = ops->Has(NanNew("opendir")) ? new NanCallback(ops->Get(NanNew("opendir")).As()) : NULL; - b->ops_read = ops->Has(NanNew("read")) ? new NanCallback(ops->Get(NanNew("read")).As()) : NULL; - b->ops_write = ops->Has(NanNew("write")) ? new NanCallback(ops->Get(NanNew("write")).As()) : NULL; - b->ops_release = ops->Has(NanNew("release")) ? new NanCallback(ops->Get(NanNew("release")).As()) : NULL; - b->ops_releasedir = ops->Has(NanNew("releasedir")) ? new NanCallback(ops->Get(NanNew("releasedir")).As()) : NULL; - b->ops_create = ops->Has(NanNew("create")) ? new NanCallback(ops->Get(NanNew("create")).As()) : NULL; - b->ops_utimens = ops->Has(NanNew("utimens")) ? new NanCallback(ops->Get(NanNew("utimens")).As()) : NULL; - b->ops_unlink = ops->Has(NanNew("unlink")) ? new NanCallback(ops->Get(NanNew("unlink")).As()) : NULL; - b->ops_rename = ops->Has(NanNew("rename")) ? new NanCallback(ops->Get(NanNew("rename")).As()) : NULL; - b->ops_link = ops->Has(NanNew("link")) ? new NanCallback(ops->Get(NanNew("link")).As()) : NULL; - b->ops_symlink = ops->Has(NanNew("symlink")) ? new NanCallback(ops->Get(NanNew("symlink")).As()) : NULL; - b->ops_mkdir = ops->Has(NanNew("mkdir")) ? new NanCallback(ops->Get(NanNew("mkdir")).As()) : NULL; - b->ops_rmdir = ops->Has(NanNew("rmdir")) ? new NanCallback(ops->Get(NanNew("rmdir")).As()) : NULL; - b->ops_destroy = ops->Has(NanNew("destroy")) ? new NanCallback(ops->Get(NanNew("destroy")).As()) : NULL; + b->ops_init = LOOKUP_CALLBACK(ops, "init"); + b->ops_error = LOOKUP_CALLBACK(ops, "error"); + b->ops_access = LOOKUP_CALLBACK(ops, "access"); + b->ops_statfs = LOOKUP_CALLBACK(ops, "statfs"); + b->ops_getattr = LOOKUP_CALLBACK(ops, "getattr"); + b->ops_fgetattr = LOOKUP_CALLBACK(ops, "fgetattr"); + b->ops_flush = LOOKUP_CALLBACK(ops, "flush"); + b->ops_fsync = LOOKUP_CALLBACK(ops, "fsync"); + b->ops_fsyncdir = LOOKUP_CALLBACK(ops, "fsyncdir"); + b->ops_readdir = LOOKUP_CALLBACK(ops, "readdir"); + b->ops_truncate = LOOKUP_CALLBACK(ops, "truncate"); + b->ops_ftruncate = LOOKUP_CALLBACK(ops, "ftruncate"); + b->ops_readlink = LOOKUP_CALLBACK(ops, "readlink"); + b->ops_chown = LOOKUP_CALLBACK(ops, "chown"); + b->ops_chmod = LOOKUP_CALLBACK(ops, "chmod"); + b->ops_mknod = LOOKUP_CALLBACK(ops, "mknod"); + b->ops_setxattr = LOOKUP_CALLBACK(ops, "setxattr"); + b->ops_getxattr = LOOKUP_CALLBACK(ops, "getxattr"); + b->ops_open = LOOKUP_CALLBACK(ops, "open"); + b->ops_opendir = LOOKUP_CALLBACK(ops, "opendir"); + b->ops_read = LOOKUP_CALLBACK(ops, "read"); + b->ops_write = LOOKUP_CALLBACK(ops, "write"); + b->ops_release = LOOKUP_CALLBACK(ops, "release"); + b->ops_releasedir = LOOKUP_CALLBACK(ops, "releasedir"); + b->ops_create = LOOKUP_CALLBACK(ops, "create"); + b->ops_utimens = LOOKUP_CALLBACK(ops, "utimens"); + b->ops_unlink = LOOKUP_CALLBACK(ops, "unlink"); + b->ops_rename = LOOKUP_CALLBACK(ops, "rename"); + b->ops_link = LOOKUP_CALLBACK(ops, "link"); + b->ops_symlink = LOOKUP_CALLBACK(ops, "symlink"); + b->ops_mkdir = LOOKUP_CALLBACK(ops, "mkdir"); + b->ops_rmdir = LOOKUP_CALLBACK(ops, "rmdir"); + b->ops_destroy = LOOKUP_CALLBACK(ops, "destroy"); - Local tmp[] = {NanNew(index), NanNew(OpCallback)->GetFunction()}; - b->callback = new NanCallback(callback_constructor->Call(2, tmp).As()); + Local tmp[] = {Nan::New(index), Nan::New(OpCallback)->GetFunction()}; + b->callback = new Nan::Callback(callback_constructor->Call(2, tmp).As()); strcpy(b->mnt, *path); strcpy(b->mntopts, "-o"); - Local options = ops->Get(NanNew("options")).As(); + Local options = ops->Get(LOCAL_STRING("options")).As(); if (options->IsArray()) { for (uint32_t i = 0; i < options->Length(); i++) { - NanUtf8String option(options->Get(i)); + Nan::Utf8String option(options->Get(i)); if (strcmp(b->mntopts, "-o")) strcat(b->mntopts, ","); strcat(b->mntopts, *option); } @@ -1167,14 +1167,12 @@ NAN_METHOD(Mount) { b->async.data = b; thread_create(&(b->thread), bindings_thread, b); - - NanReturnUndefined(); } -class UnmountWorker : public NanAsyncWorker { +class UnmountWorker : public Nan::AsyncWorker { public: - UnmountWorker(NanCallback *callback, char *path) - : NanAsyncWorker(callback), path(path) {} + UnmountWorker(Nan::Callback *callback, char *path) + : Nan::AsyncWorker(callback), path(path) {} ~UnmountWorker() {} void Execute () { @@ -1183,7 +1181,7 @@ class UnmountWorker : public NanAsyncWorker { } void HandleOKCallback () { - NanScope(); + Nan::HandleScope scope; callback->Call(0, NULL); } @@ -1192,49 +1190,39 @@ class UnmountWorker : public NanAsyncWorker { }; NAN_METHOD(SetCallback) { - NanScope(); - callback_constructor = new NanCallback(args[0].As()); - NanReturnUndefined(); + callback_constructor = new Nan::Callback(info[0].As()); } NAN_METHOD(SetBuffer) { - NanScope(); - NanAssignPersistent(buffer_constructor, args[0].As()); - NanReturnUndefined(); + buffer_constructor.Reset(info[0].As()); } NAN_METHOD(PopulateContext) { - NanScope(); - if (bindings_current == NULL) return NanThrowError("You have to call this inside a fuse operation"); + if (bindings_current == NULL) return Nan::ThrowError("You have to call this inside a fuse operation"); - Local ctx = args[0].As(); - ctx->Set(NanNew("uid"), NanNew(bindings_current->context_uid)); - ctx->Set(NanNew("gid"), NanNew(bindings_current->context_gid)); - ctx->Set(NanNew("pid"), NanNew(bindings_current->context_pid)); - - NanReturnUndefined(); + Local ctx = info[0].As(); + ctx->Set(LOCAL_STRING("uid"), Nan::New(bindings_current->context_uid)); + ctx->Set(LOCAL_STRING("gid"), Nan::New(bindings_current->context_gid)); + ctx->Set(LOCAL_STRING("pid"), Nan::New(bindings_current->context_pid)); } NAN_METHOD(Unmount) { - NanScope(); - - if (!args[0]->IsString()) return NanThrowError("mnt must be a string"); - NanUtf8String path(args[0]); - Local callback = args[1].As(); + if (!info[0]->IsString()) return Nan::ThrowError("mnt must be a string"); + Nan::Utf8String path(info[0]); + Local callback = info[1].As(); char *path_alloc = (char *) malloc(1024); strcpy(path_alloc, *path); - NanAsyncQueueWorker(new UnmountWorker(new NanCallback(callback), path_alloc)); - NanReturnUndefined(); + Nan::AsyncQueueWorker(new UnmountWorker(new Nan::Callback(callback), path_alloc)); } void Init(Handle exports) { - exports->Set(NanNew("setCallback"), NanNew(SetCallback)->GetFunction()); - exports->Set(NanNew("setBuffer"), NanNew(SetBuffer)->GetFunction()); - exports->Set(NanNew("mount"), NanNew(Mount)->GetFunction()); - exports->Set(NanNew("unmount"), NanNew(Unmount)->GetFunction()); - exports->Set(NanNew("populateContext"), NanNew(PopulateContext)->GetFunction()); + exports->Set(LOCAL_STRING("setCallback"), Nan::New(SetCallback)->GetFunction()); + exports->Set(LOCAL_STRING("setBuffer"), Nan::New(SetBuffer)->GetFunction()); + exports->Set(LOCAL_STRING("mount"), Nan::New(Mount)->GetFunction()); + exports->Set(LOCAL_STRING("unmount"), Nan::New(Unmount)->GetFunction()); + exports->Set(LOCAL_STRING("populateContext"), Nan::New(PopulateContext)->GetFunction()); } NODE_MODULE(fuse_bindings, Init) diff --git a/package.json b/package.json index 02e5820..ec6c1cb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "gypfile": true, "dependencies": { "bindings": "^1.2.1", - "nan": "^1.7.0", + "nan": "^2.0.9", "xtend": "^4.0.0" }, "devDependencies": {