From a4552536ced3b1fb71e45b516c0b1e0978f8adba Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 2 Jul 2019 16:19:00 +0200 Subject: [PATCH 01/33] WIP: node 12 support --- examples/setup.js | 19 ++++++- examples/wrapper.js | 2 +- src/node-zk.cpp | 136 ++++++++++++++++++++++++-------------------- 3 files changed, 92 insertions(+), 65 deletions(-) diff --git a/examples/setup.js b/examples/setup.js index 69437ff5..5f25f297 100644 --- a/examples/setup.js +++ b/examples/setup.js @@ -3,6 +3,15 @@ const notifier = require('./notifier.js'); const { createNode, persistentNode } = require('./createnode.js'); const noop = () => {}; +let timeoutId; + +function shutDown() { + clearTimeout(timeoutId); + process.exit(); +} + +process.on('SIGINT', shutDown); +process.on('SIGTERM', shutDown); function createNodes(paths) { const client = createClient(); @@ -23,8 +32,16 @@ function createNodes(paths) { }); }); - client.on('close', () => { + client.on('close', (...args) => { notifier.emit('close', `session closed, id=${client.client_id}`); + console.log('CLOSE ARGS', ...args); + console.log('WILL RECONNECT'); + + timeoutId = setTimeout(() => { + createNodes(paths) + .then(() => console.log('reconnected')) + .catch(e => console.log('failed', e)); + }, 5000); }); client.connect(noop); diff --git a/examples/wrapper.js b/examples/wrapper.js index 981a7f2f..5b79b07f 100644 --- a/examples/wrapper.js +++ b/examples/wrapper.js @@ -7,7 +7,7 @@ function createClient(timeoutMs = 5000) { const config = { connect: host, timeout: timeoutMs, - debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN, + debug_level: ZooKeeper.ZOO_LOG_LEVEL_DEBUG, host_order_deterministic: false, }; diff --git a/src/node-zk.cpp b/src/node-zk.cpp index a31d0d61..f362f01c 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -75,16 +75,16 @@ namespace zk { Nan::ThrowError(text); \ return; \ } - - + + #define RETURN_THIS(info) info.GetReturnValue().Set(info.This()) #define RETURN_VALUE(info, value) info.GetReturnValue().Set(value) - + #define LOCAL_STRING(str) Nan::New(str).ToLocalChecked() - -#define DECLARE_STRING(ev) static Nan::Persistent ev; -#define INITIALIZE_STRING(ev, str) ev.Reset(LOCAL_STRING(str)); - + +#define DECLARE_STRING(ev) static Nan::Persistent ev; +#define INITIALIZE_STRING(ev, str) ev.Reset(LOCAL_STRING(str)); + DECLARE_STRING (on_closed); DECLARE_STRING (on_connected); DECLARE_STRING (on_connecting); @@ -96,7 +96,7 @@ DECLARE_STRING (on_event_notwatching); #define DECLARE_SYMBOL(ev) DECLARE_STRING(ev) #define INITIALIZE_SYMBOL(ev) INITIALIZE_STRING(ev, #ev) - + DECLARE_SYMBOL (PRIVATE_PROP_ZK); DECLARE_SYMBOL (PRIVATE_PROP_HANDBACK); @@ -114,7 +114,7 @@ struct completion_data { class ZooKeeper: public Nan::ObjectWrap { public: - static void Initialize (v8::Handle target) { + static void Initialize (v8::Local target) { Nan::HandleScope scope; Local constructor_template = Nan::New(New); @@ -148,24 +148,29 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::SetAccessor(constructor_template->InstanceTemplate(), LOCAL_STRING("is_unrecoverable"), IsUnrecoverablePropertyGetter, 0, Local(), PROHIBITS_OVERWRITING, ReadOnly); - Local constructor = constructor_template->GetFunction(); + Local context = Nan::GetCurrentContext(); + MaybeLocal constructor_maybe = constructor_template->GetFunction(context); + Local constructor = constructor_maybe.ToLocalChecked(); //extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE; - Local acl_open = Nan::New(); + MaybeLocal acl_open_maybe = Nan::New(); + v8::Local acl_open = acl_open_maybe.ToLocalChecked(); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_OPEN_ACL_UNSAFE"), acl_open, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE; - Local acl_read = Nan::New(); + MaybeLocal acl_read_maybe = Nan::New(); + v8::Local acl_read = acl_read_maybe.ToLocalChecked(); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_READ), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_READ_ACL_UNSAFE"), acl_read, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL; - Local acl_creator = Nan::New(); + MaybeLocal acl_creator_maybe = Nan::New(); + v8::Local acl_creator = acl_creator_maybe.ToLocalChecked(); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("scheme"), LOCAL_STRING("auth"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("auth"), LOCAL_STRING(""), static_cast(ReadOnly | DontDelete)); @@ -258,6 +263,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void New(const Nan::FunctionCallbackInfo& info) { + LOG_DEBUG(("New: creating a new ZooKeeper")); ZooKeeper *zk = new ZooKeeper(); zk->Wrap(info.This()); @@ -267,6 +273,7 @@ class ZooKeeper: public Nan::ObjectWrap { void yield () { if (is_closed) { + LOG_DEBUG(("yield: was closed")); return; } @@ -395,7 +402,7 @@ class ZooKeeper: public Nan::ObjectWrap { // stop the current timer and skip re-initializing the timer uv_timer_stop(&zk_timer); } - + myid = *client_id; zhandle = zookeeper_init(hostPort, main_watcher, session_timeout, &myid, this, 0); if (!zhandle) { @@ -412,18 +419,19 @@ class ZooKeeper: public Nan::ObjectWrap { } static void Init(const Nan::FunctionCallbackInfo& info) { + Isolate* isolate = info.GetIsolate(); THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); - Local arg = info[0]->ToObject(); + Local arg = info[0]->ToObject(isolate); - int32_t debug_level = arg->Get(LOCAL_STRING("debug_level"))->Int32Value(); + int32_t debug_level = arg->Get(LOCAL_STRING("debug_level"))->Int32Value(Nan::GetCurrentContext()).FromJust(); zoo_set_debug_level(static_cast(debug_level)); - bool order = arg->Get(LOCAL_STRING("host_order_deterministic"))->ToBoolean()->BooleanValue(); + bool order = arg->Get(LOCAL_STRING("host_order_deterministic"))->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); zoo_deterministic_conn_order(order); // enable deterministic order - Nan::Utf8String _hostPort (arg->Get(LOCAL_STRING("connect"))->ToString()); - int32_t session_timeout = arg->Get(LOCAL_STRING("timeout"))->Int32Value(); + Nan::Utf8String _hostPort (arg->Get(LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + int32_t session_timeout = arg->Get(LOCAL_STRING("timeout"))->Int32Value(Nan::GetCurrentContext()).FromJust(); if (session_timeout == 0) { session_timeout = 20000; } @@ -434,11 +442,11 @@ class ZooKeeper: public Nan::ObjectWrap { v8::Local v8v_client_password = arg->Get(LOCAL_STRING("client_password")); bool id_and_password_defined = (!v8v_client_id->IsUndefined() && !v8v_client_password->IsUndefined()); bool id_and_password_undefined = (v8v_client_id->IsUndefined() && v8v_client_password->IsUndefined()); - THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), + THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), "ZK init: client id and password must either be both specified or unspecified"); if (id_and_password_defined) { - Nan::Utf8String password_check(v8v_client_password->ToString()); - THROW_IF_NOT (password_check.length() == 2 * ZOOKEEPER_PASSWORD_BYTE_COUNT, + Nan::Utf8String password_check(v8v_client_password->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + THROW_IF_NOT (password_check.length() == 2 * ZOOKEEPER_PASSWORD_BYTE_COUNT, "ZK init: password does not have correct length"); HexStringToPassword(v8v_client_password, local_client.passwd); StringToId(v8v_client_id, &local_client.client_id); @@ -495,7 +503,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void StringToId (v8::Local s, int64_t *id) { - Nan::Utf8String a(s->ToString()); + Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); sscanf(*a, "%llx", _LLP_CAST_ id); } @@ -511,7 +519,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void HexStringToPassword (v8::Local s, char *p) { - Nan::Utf8String a(s->ToString()); + Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); char *hex = *a; for (int i = 0; i < ZOOKEEPER_PASSWORD_BYTE_COUNT; ++i) { hexToUchar(hex, (unsigned char *)p+i); @@ -631,14 +639,15 @@ class ZooKeeper: public Nan::ObjectWrap { static void ACreate(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString()); - uint32_t flags = info[2]->Uint32Value(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Local _data = info[1]->ToObject(); + Isolate* isolate = info.GetIsolate(); + Local _data = info[1]->ToObject(isolate); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other - Nan::Utf8String _data (info[1]->ToString()); + Nan::Utf8String _data (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } } @@ -661,8 +670,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void ADelete(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); - uint32_t version = info[1]->Uint32Value(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -702,15 +711,15 @@ class ZooKeeper: public Nan::ObjectWrap { static void AExists(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); - bool watch = info[1]->ToBoolean()->BooleanValue(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); } static void AWExists(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_awexists(zk->zhandle, *_path, &watcher_fn, cbw, &stat_completion, cb)); } @@ -731,10 +740,10 @@ class ZooKeeper: public Nan::ObjectWrap { } static void Delete(const Nan::FunctionCallbackInfo& info) { - ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); + ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); - Nan::Utf8String _path (info[0]->ToString()); - uint32_t version = info[1]->Uint32Value(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); int ret = zoo_delete(zk->zhandle, *_path, version); RETURN_VALUE(info, Nan::New(ret)); @@ -743,8 +752,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); - bool watch = info[1]->ToBoolean()->BooleanValue(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); } @@ -757,7 +766,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGet(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_awget(zk->zhandle, *_path, &watcher_fn, cbw, &data_completion, cb)); } @@ -765,14 +774,15 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString()); - uint32_t version = info[2]->Uint32Value(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Local _data = info[1]->ToObject(); + Isolate* isolate = info.GetIsolate(); + Local _data = info[1]->ToObject(isolate); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other - Nan::Utf8String _data(info[1]->ToString()); + Nan::Utf8String _data(info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, *_data, _data.length(), version, &stat_completion, cb)); } } @@ -798,8 +808,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); - bool watch = info[1]->ToBoolean()->BooleanValue(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); } @@ -807,7 +817,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_awget_children(zk->zhandle, *_path, &watcher_fn, cbw, &strings_completion, cb)); } @@ -835,8 +845,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren2(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); - bool watch = info[1]->ToBoolean()->BooleanValue(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); } @@ -844,7 +854,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren2(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_awget_children2(zk->zhandle, *_path, &watcher_fn, cbw, &strings_stat_completion, cb)); } @@ -852,7 +862,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_aget_acl(zk->zhandle, *_path, &acl_completion, cb)); } @@ -860,8 +870,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString()); - uint32_t _version = info[1]->Uint32Value(); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t _version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); Local arr = Local::Cast(info[2]); struct ACL_vector *aclv = zk->createAclVector(arr); @@ -877,7 +887,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASync(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString()); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); METHOD_EPILOG(zoo_async(zk->zhandle, *_path, &string_completion, cb)); } @@ -885,8 +895,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AddAuth(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _scheme (info[0]->ToString()); - Nan::Utf8String _auth (info[1]->ToString()); + Nan::Utf8String _scheme (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _auth (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -915,7 +925,7 @@ class ZooKeeper: public Nan::ObjectWrap { return scope.Escape(arr); }; - struct ACL_vector *createAclVector (Handle arr) { + struct ACL_vector *createAclVector (Local arr) { Nan::HandleScope scope; struct ACL_vector *aclv = (struct ACL_vector *) malloc(sizeof(struct ACL_vector)); @@ -925,9 +935,9 @@ class ZooKeeper: public Nan::ObjectWrap { for (int i = 0, l = aclv->count; i < l; i++) { Local obj = Local::Cast(arr->Get(i)); - Nan::Utf8String _scheme (obj->Get(LOCAL_STRING("scheme"))->ToString()); - Nan::Utf8String _auth (obj->Get(LOCAL_STRING("auth"))->ToString()); - uint32_t _perms = obj->Get(LOCAL_STRING("perms"))->Uint32Value(); + Nan::Utf8String _scheme (obj->Get(LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _auth (obj->Get(LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t _perms = obj->Get(LOCAL_STRING("perms"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct Id id; struct ACL *acl = &aclv->data[i]; @@ -1010,19 +1020,19 @@ class ZooKeeper: public Nan::ObjectWrap { int rc = uv_poll_stop(zk_io); LOG_DEBUG(("zookeeper_close(%lp) uv_poll_stop result: %d", this, rc)); - uv_close((uv_handle_t*) zk_io, delete_on_close); + uv_close((uv_handle_t*) zk_io, delete_on_close); zk_io = NULL; } // Close the timer and finally Unref the ZooKeeper instance when it's done // Unrefing after is important to avoid memory being freed too early. - uv_close((uv_handle_t*) &zk_timer, timer_closed); + uv_close((uv_handle_t*) &zk_timer, timer_closed); Nan::HandleScope scope; DoEmitClose (Nan::New(on_closed), code); } } - + static void timer_closed(uv_handle_t* handle) { ZooKeeper *zk = static_cast(handle->data); zk->Unref(); @@ -1072,7 +1082,7 @@ class ZooKeeper: public Nan::ObjectWrap { } // namespace "zk" -extern "C" void init(Handle target) { +extern "C" void init(Local target) { INITIALIZE_STRING (zk::on_closed, "close"); INITIALIZE_STRING (zk::on_connected, "connect"); INITIALIZE_STRING (zk::on_connecting, "connecting"); From 38d98f8e4d3ef1b0b9dd280f938d2c410acbc1d4 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 2 Jul 2019 17:24:16 +0200 Subject: [PATCH 02/33] WIP: remove deprecated toboolean --- src/node-zk.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index f362f01c..dd507fe6 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -419,15 +419,14 @@ class ZooKeeper: public Nan::ObjectWrap { } static void Init(const Nan::FunctionCallbackInfo& info) { - Isolate* isolate = info.GetIsolate(); THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); - Local arg = info[0]->ToObject(isolate); + Local arg = Nan::To(info[0]).ToLocalChecked(); int32_t debug_level = arg->Get(LOCAL_STRING("debug_level"))->Int32Value(Nan::GetCurrentContext()).FromJust(); zoo_set_debug_level(static_cast(debug_level)); - bool order = arg->Get(LOCAL_STRING("host_order_deterministic"))->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); + bool order = Nan::To(arg->Get(LOCAL_STRING("host_order_deterministic"))).FromJust(); zoo_deterministic_conn_order(order); // enable deterministic order Nan::Utf8String _hostPort (arg->Get(LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); @@ -643,8 +642,7 @@ class ZooKeeper: public Nan::ObjectWrap { uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Isolate* isolate = info.GetIsolate(); - Local _data = info[1]->ToObject(isolate); + Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other Nan::Utf8String _data (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); @@ -712,7 +710,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); + bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); } @@ -753,7 +751,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); + bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); } @@ -778,8 +776,7 @@ class ZooKeeper: public Nan::ObjectWrap { uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Isolate* isolate = info.GetIsolate(); - Local _data = info[1]->ToObject(isolate); + Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other Nan::Utf8String _data(info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); @@ -809,7 +806,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); + bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); } @@ -846,7 +843,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - bool watch = info[1]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value(); + bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); } From 2a54cb401a2bf033e8a0cc72e812c5ccb127471c Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 10:00:31 +0200 Subject: [PATCH 03/33] WIP: node 12 support --- src/node-zk.cpp | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index dd507fe6..144ccb1f 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -418,27 +418,46 @@ class ZooKeeper: public Nan::ObjectWrap { return true; } + static v8::Local toLocalVal(Local arg, Local propertyName) { + v8::Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); + return val_local; + } + + static int32_t fromJustInt(Local arg, Local propertyName) { + v8::Local val_local = toLocalVal(arg, propertyName); + int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); + + return val; + } + + static bool fromJustBool(Local arg, Local propertyName) { + v8::Local val_local = toLocalVal(arg, propertyName); + bool val = Nan::To(val_local).FromJust(); + + return val; + } + static void Init(const Nan::FunctionCallbackInfo& info) { THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); Local arg = Nan::To(info[0]).ToLocalChecked(); - int32_t debug_level = arg->Get(LOCAL_STRING("debug_level"))->Int32Value(Nan::GetCurrentContext()).FromJust(); + int32_t debug_level = fromJustInt(arg, LOCAL_STRING("debug_level")); zoo_set_debug_level(static_cast(debug_level)); - bool order = Nan::To(arg->Get(LOCAL_STRING("host_order_deterministic"))).FromJust(); + bool order = fromJustBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order Nan::Utf8String _hostPort (arg->Get(LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - int32_t session_timeout = arg->Get(LOCAL_STRING("timeout"))->Int32Value(Nan::GetCurrentContext()).FromJust(); + int32_t session_timeout = fromJustInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; } clientid_t local_client; ZERO_MEM (local_client); - v8::Local v8v_client_id = arg->Get(LOCAL_STRING("client_id")); - v8::Local v8v_client_password = arg->Get(LOCAL_STRING("client_password")); + v8::Local v8v_client_id = toLocalVal(arg, LOCAL_STRING("client_id")); + v8::Local v8v_client_password = toLocalVal(arg, LOCAL_STRING("client_password")); bool id_and_password_defined = (!v8v_client_id->IsUndefined() && !v8v_client_password->IsUndefined()); bool id_and_password_undefined = (v8v_client_id->IsUndefined() && v8v_client_password->IsUndefined()); THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), @@ -930,11 +949,16 @@ class ZooKeeper: public Nan::ObjectWrap { aclv->data = (struct ACL *) calloc(aclv->count, sizeof(struct ACL)); for (int i = 0, l = aclv->count; i < l; i++) { - Local obj = Local::Cast(arr->Get(i)); + v8::Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); + Local obj = Local::Cast(obj_local); + + v8::Local scheme_local = toLocalVal(obj, LOCAL_STRING("scheme")); + v8::Local auth_local = toLocalVal(obj, LOCAL_STRING("auth")); + v8::Local perms_local = toLocalVal(obj, LOCAL_STRING("perm")); - Nan::Utf8String _scheme (obj->Get(LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - Nan::Utf8String _auth (obj->Get(LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - uint32_t _perms = obj->Get(LOCAL_STRING("perms"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); + Nan::Utf8String _scheme (scheme_local->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _auth (auth_local->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t _perms = perms_local->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct Id id; struct ACL *acl = &aclv->data[i]; From 851c4a29d3e7382a05d6348a64b6c9ab428c0fb6 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 11:29:04 +0200 Subject: [PATCH 04/33] WIP: node 12 support --- src/node-zk.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 144ccb1f..7228e8ad 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -148,29 +148,24 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::SetAccessor(constructor_template->InstanceTemplate(), LOCAL_STRING("is_unrecoverable"), IsUnrecoverablePropertyGetter, 0, Local(), PROHIBITS_OVERWRITING, ReadOnly); - Local context = Nan::GetCurrentContext(); - MaybeLocal constructor_maybe = constructor_template->GetFunction(context); - Local constructor = constructor_maybe.ToLocalChecked(); + Local constructor = constructor_template->GetFunction(Nan::GetCurrentContext()).ToLocalChecked(); //extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE; - MaybeLocal acl_open_maybe = Nan::New(); - v8::Local acl_open = acl_open_maybe.ToLocalChecked(); + v8::Local acl_open = Nan::New(); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_OPEN_ACL_UNSAFE"), acl_open, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE; - MaybeLocal acl_read_maybe = Nan::New(); - v8::Local acl_read = acl_read_maybe.ToLocalChecked(); + v8::Local acl_read = Nan::New(); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_READ), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_READ_ACL_UNSAFE"), acl_read, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL; - MaybeLocal acl_creator_maybe = Nan::New(); - v8::Local acl_creator = acl_creator_maybe.ToLocalChecked(); + v8::Local acl_creator = Nan::New(); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("scheme"), LOCAL_STRING("auth"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("auth"), LOCAL_STRING(""), static_cast(ReadOnly | DontDelete)); @@ -952,13 +947,9 @@ class ZooKeeper: public Nan::ObjectWrap { v8::Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); Local obj = Local::Cast(obj_local); - v8::Local scheme_local = toLocalVal(obj, LOCAL_STRING("scheme")); - v8::Local auth_local = toLocalVal(obj, LOCAL_STRING("auth")); - v8::Local perms_local = toLocalVal(obj, LOCAL_STRING("perm")); - - Nan::Utf8String _scheme (scheme_local->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - Nan::Utf8String _auth (auth_local->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - uint32_t _perms = perms_local->Uint32Value(Nan::GetCurrentContext()).FromJust(); + Nan::Utf8String _scheme (toLocalVal(obj, LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _auth (toLocalVal(obj, LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + uint32_t _perms = toLocalVal(obj, LOCAL_STRING("perm"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct Id id; struct ACL *acl = &aclv->data[i]; From 84bd87b6fbb0b9f9abe4d2849d0d3a25337f0f2d Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 17:40:50 +0200 Subject: [PATCH 05/33] WIP: remove warnings --- src/node-zk.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 7228e8ad..da550af0 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -151,21 +151,21 @@ class ZooKeeper: public Nan::ObjectWrap { Local constructor = constructor_template->GetFunction(Nan::GetCurrentContext()).ToLocalChecked(); //extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE; - v8::Local acl_open = Nan::New(); + Local acl_open = Nan::New(); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_open, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_OPEN_ACL_UNSAFE"), acl_open, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE; - v8::Local acl_read = Nan::New(); + Local acl_read = Nan::New(); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_READ), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("scheme"), LOCAL_STRING("world"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_read, LOCAL_STRING("auth"), LOCAL_STRING("anyone"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_READ_ACL_UNSAFE"), acl_read, static_cast(ReadOnly | DontDelete)); //extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL; - v8::Local acl_creator = Nan::New(); + Local acl_creator = Nan::New(); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("perms"), Nan::New(ZOO_PERM_ALL), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("scheme"), LOCAL_STRING("auth"), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("auth"), LOCAL_STRING(""), static_cast(ReadOnly | DontDelete)); @@ -806,7 +806,7 @@ class ZooKeeper: public Nan::ObjectWrap { if (strings != NULL) { Local ar = Nan::New((uint32_t)strings->count); for (uint32_t i = 0; i < (uint32_t)strings->count; ++i) { - ar->Set(i, LOCAL_STRING(strings->data[i])); + ar->Set(Nan::GetCurrentContext(), i, LOCAL_STRING(strings->data[i])); } argv[2] = ar; } else { @@ -841,7 +841,7 @@ class ZooKeeper: public Nan::ObjectWrap { if (strings != NULL) { Local ar = Nan::New((uint32_t)strings->count); for (uint32_t i = 0; i < (uint32_t)strings->count; ++i) { - ar->Set(i, LOCAL_STRING(strings->data[i])); + ar->Set(Nan::GetCurrentContext(), i, LOCAL_STRING(strings->data[i])); } argv[2] = ar; } else { @@ -930,7 +930,7 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(obj, LOCAL_STRING("scheme"), LOCAL_STRING(acl->id.scheme), ReadOnly); Nan::DefineOwnProperty(obj, LOCAL_STRING("auth"), LOCAL_STRING(acl->id.id), ReadOnly); - arr->Set(i, obj); + arr->Set(Nan::GetCurrentContext(), i, obj); } return scope.Escape(arr); From 26bb8d30c292022e7a3170e0595385908dbedacb Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 20:40:56 +0200 Subject: [PATCH 06/33] WIP: remove warnings for Set --- src/node-zk.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index da550af0..4fb151ec 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -254,7 +254,7 @@ class ZooKeeper: public Nan::ObjectWrap { NODE_DEFINE_CONSTANT(constructor, ZSESSIONMOVED); - target->Set(LOCAL_STRING("ZooKeeper"), constructor); + Nan::Set(target, LOCAL_STRING("ZooKeeper"), constructor); } static void New(const Nan::FunctionCallbackInfo& info) { @@ -806,7 +806,7 @@ class ZooKeeper: public Nan::ObjectWrap { if (strings != NULL) { Local ar = Nan::New((uint32_t)strings->count); for (uint32_t i = 0; i < (uint32_t)strings->count; ++i) { - ar->Set(Nan::GetCurrentContext(), i, LOCAL_STRING(strings->data[i])); + Nan::Set(ar, i, LOCAL_STRING(strings->data[i])); } argv[2] = ar; } else { @@ -841,7 +841,7 @@ class ZooKeeper: public Nan::ObjectWrap { if (strings != NULL) { Local ar = Nan::New((uint32_t)strings->count); for (uint32_t i = 0; i < (uint32_t)strings->count; ++i) { - ar->Set(Nan::GetCurrentContext(), i, LOCAL_STRING(strings->data[i])); + Nan::Set(ar, i, LOCAL_STRING(strings->data[i])); } argv[2] = ar; } else { @@ -930,7 +930,7 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(obj, LOCAL_STRING("scheme"), LOCAL_STRING(acl->id.scheme), ReadOnly); Nan::DefineOwnProperty(obj, LOCAL_STRING("auth"), LOCAL_STRING(acl->id.id), ReadOnly); - arr->Set(Nan::GetCurrentContext(), i, obj); + Nan::Set(arr, i, obj); } return scope.Escape(arr); From 1eac91a471806ca10b921f8ca2df8553318458b0 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 21:30:22 +0200 Subject: [PATCH 07/33] rollback js changes --- examples/setup.js | 19 +------------------ examples/wrapper.js | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/examples/setup.js b/examples/setup.js index 5f25f297..69437ff5 100644 --- a/examples/setup.js +++ b/examples/setup.js @@ -3,15 +3,6 @@ const notifier = require('./notifier.js'); const { createNode, persistentNode } = require('./createnode.js'); const noop = () => {}; -let timeoutId; - -function shutDown() { - clearTimeout(timeoutId); - process.exit(); -} - -process.on('SIGINT', shutDown); -process.on('SIGTERM', shutDown); function createNodes(paths) { const client = createClient(); @@ -32,16 +23,8 @@ function createNodes(paths) { }); }); - client.on('close', (...args) => { + client.on('close', () => { notifier.emit('close', `session closed, id=${client.client_id}`); - console.log('CLOSE ARGS', ...args); - console.log('WILL RECONNECT'); - - timeoutId = setTimeout(() => { - createNodes(paths) - .then(() => console.log('reconnected')) - .catch(e => console.log('failed', e)); - }, 5000); }); client.connect(noop); diff --git a/examples/wrapper.js b/examples/wrapper.js index 5b79b07f..981a7f2f 100644 --- a/examples/wrapper.js +++ b/examples/wrapper.js @@ -7,7 +7,7 @@ function createClient(timeoutMs = 5000) { const config = { connect: host, timeout: timeoutMs, - debug_level: ZooKeeper.ZOO_LOG_LEVEL_DEBUG, + debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN, host_order_deterministic: false, }; From ef0ae7745f7e72f0c68ee73e7a397bbbfdc264af Mon Sep 17 00:00:00 2001 From: davidvujic Date: Wed, 3 Jul 2019 22:10:24 +0200 Subject: [PATCH 08/33] WIP: remove warnings for Get --- src/node-zk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 4fb151ec..dfa1c6df 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -443,7 +443,7 @@ class ZooKeeper: public Nan::ObjectWrap { bool order = fromJustBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order - Nan::Utf8String _hostPort (arg->Get(LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _hostPort (toLocalVal(arg, LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); int32_t session_timeout = fromJustInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; From 064c902152087c67e4f8745275492223bd20cf77 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Thu, 4 Jul 2019 10:55:26 +0200 Subject: [PATCH 09/33] WIP: pass an Asyncresurce to the Call function --- src/node-zk.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index dfa1c6df..58e1dda7 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -588,11 +588,13 @@ class ZooKeeper: public Nan::ObjectWrap { argv[1] = LOCAL_STRING(zerror(rc)) #define CALLBACK_EPILOG() \ - callback->Call(sizeof(argv)/sizeof(argv[0]), argv); \ + Nan::AsyncResource resource("node-zk:CALLBACK_EPILOG"); \ + callback->Call(sizeof(argv)/sizeof(argv[0]), argv, &resource); \ delete callback #define WATCHER_CALLBACK_EPILOG() \ - callback->Call(sizeof(argv)/sizeof(argv[0]), argv); \ + Nan::AsyncResource resource("node-zk:WATCHER_CALLBACK_EPILOG"); \ + callback->Call(sizeof(argv)/sizeof(argv[0]), argv, &resource); \ #define A_METHOD_PROLOG(nargs) \ ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); \ From 33a01ee3148fb6f5530c4339132ea5e5cac70cd2 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Thu, 4 Jul 2019 11:20:52 +0200 Subject: [PATCH 10/33] WIP: from NODE_UNIXTIME_V8 to native Date --- src/node-zk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 58e1dda7..c7fb90a8 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -706,8 +706,8 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(o, LOCAL_STRING("version"), Nan::New(stat->version), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("cversion"), Nan::New(stat->cversion), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("aversion"), Nan::New(stat->aversion), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), NODE_UNIXTIME_V8(stat->ctime/1000.), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), NODE_UNIXTIME_V8(stat->mtime/1000.), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), v8::Date::New(Nan::GetCurrentContext(), stat->ctime/1000.).ToLocalChecked(), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), v8::Date::New(Nan::GetCurrentContext(), stat->mtime/1000.).ToLocalChecked(), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("ephemeralOwner"), idAsString(stat->ephemeralOwner), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("createdInThisSession"), Nan::New(myid.client_id == stat->ephemeralOwner), ReadOnly); return scope.Escape(o); From 796ca3adb1b39eb0625a2f64bd3174269980a59a Mon Sep 17 00:00:00 2001 From: davidvujic Date: Thu, 4 Jul 2019 11:28:57 +0200 Subject: [PATCH 11/33] WIP: from MakeCallback to AsyncResource --- src/node-zk.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index c7fb90a8..494c474f 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -571,7 +571,8 @@ class ZooKeeper: public Nan::ObjectWrap { argv[1] = thisObj; argv[2] = data; - Nan::MakeCallback(thisObj, "emit", 3, argv); + Nan::AsyncResource resource("node-zk:DoEmit"); + resource.runInAsyncScope(thisObj, "emit", 3, argv); } #define CALLBACK_PROLOG(info) \ From 8a93519bbf0d779ab11283b1a2105904bd9b01e6 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 5 Jul 2019 08:28:13 +0200 Subject: [PATCH 12/33] Add Node.js 12 to the travis build config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b215e717..78a50303 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - "10" - "8" + - "12" os: - linux - osx From ec266113a3adcee0fb02bec5dff841c7fec0c669 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 5 Jul 2019 09:48:35 +0200 Subject: [PATCH 13/33] WIP: remove redundant V8 namespace declarations --- src/node-zk.cpp | 112 ++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 494c474f..efcccc48 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -114,7 +114,7 @@ struct completion_data { class ZooKeeper: public Nan::ObjectWrap { public: - static void Initialize (v8::Local target) { + static void Initialize (Local target) { Nan::HandleScope scope; Local constructor_template = Nan::New(New); @@ -257,7 +257,7 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::Set(target, LOCAL_STRING("ZooKeeper"), constructor); } - static void New(const Nan::FunctionCallbackInfo& info) { + static void New(const Nan::FunctionCallbackInfo& info) { LOG_DEBUG(("New: creating a new ZooKeeper")); ZooKeeper *zk = new ZooKeeper(); @@ -413,26 +413,26 @@ class ZooKeeper: public Nan::ObjectWrap { return true; } - static v8::Local toLocalVal(Local arg, Local propertyName) { - v8::Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); + static Local toLocalVal(Local arg, Local propertyName) { + Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); return val_local; } static int32_t fromJustInt(Local arg, Local propertyName) { - v8::Local val_local = toLocalVal(arg, propertyName); + Local val_local = toLocalVal(arg, propertyName); int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); return val; } static bool fromJustBool(Local arg, Local propertyName) { - v8::Local val_local = toLocalVal(arg, propertyName); + Local val_local = toLocalVal(arg, propertyName); bool val = Nan::To(val_local).FromJust(); return val; } - static void Init(const Nan::FunctionCallbackInfo& info) { + static void Init(const Nan::FunctionCallbackInfo& info) { THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); Local arg = Nan::To(info[0]).ToLocalChecked(); @@ -443,7 +443,7 @@ class ZooKeeper: public Nan::ObjectWrap { bool order = fromJustBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order - Nan::Utf8String _hostPort (toLocalVal(arg, LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _hostPort (toLocalVal(arg, LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); int32_t session_timeout = fromJustInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; @@ -451,14 +451,14 @@ class ZooKeeper: public Nan::ObjectWrap { clientid_t local_client; ZERO_MEM (local_client); - v8::Local v8v_client_id = toLocalVal(arg, LOCAL_STRING("client_id")); - v8::Local v8v_client_password = toLocalVal(arg, LOCAL_STRING("client_password")); + Local v8v_client_id = toLocalVal(arg, LOCAL_STRING("client_id")); + Local v8v_client_password = toLocalVal(arg, LOCAL_STRING("client_password")); bool id_and_password_defined = (!v8v_client_id->IsUndefined() && !v8v_client_password->IsUndefined()); bool id_and_password_undefined = (v8v_client_id->IsUndefined() && v8v_client_password->IsUndefined()); THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), "ZK init: client id and password must either be both specified or unspecified"); if (id_and_password_defined) { - Nan::Utf8String password_check(v8v_client_password->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String password_check(v8v_client_password->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); THROW_IF_NOT (password_check.length() == 2 * ZOOKEEPER_PASSWORD_BYTE_COUNT, "ZK init: password does not have correct length"); HexStringToPassword(v8v_client_password, local_client.passwd); @@ -515,8 +515,8 @@ class ZooKeeper: public Nan::ObjectWrap { return scope.Escape(LOCAL_STRING(idbuff)); } - static void StringToId (v8::Local s, int64_t *id) { - Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + static void StringToId (Local s, int64_t *id) { + Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); sscanf(*a, "%llx", _LLP_CAST_ id); } @@ -531,8 +531,8 @@ class ZooKeeper: public Nan::ObjectWrap { return scope.Escape(LOCAL_STRING(buff)); } - static void HexStringToPassword (v8::Local s, char *p) { - Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + static void HexStringToPassword (Local s, char *p) { + Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); char *hex = *a; for (int i = 0; i < ZOOKEEPER_PASSWORD_BYTE_COUNT; ++i) { hexToUchar(hex, (unsigned char *)p+i); @@ -652,17 +652,17 @@ class ZooKeeper: public Nan::ObjectWrap { CALLBACK_EPILOG(); } - static void ACreate(const Nan::FunctionCallbackInfo& info) { + static void ACreate(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other - Nan::Utf8String _data (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _data (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } } @@ -683,9 +683,9 @@ class ZooKeeper: public Nan::ObjectWrap { free(d); } - static void ADelete(const Nan::FunctionCallbackInfo& info) { + static void ADelete(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); @@ -707,8 +707,8 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(o, LOCAL_STRING("version"), Nan::New(stat->version), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("cversion"), Nan::New(stat->cversion), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("aversion"), Nan::New(stat->aversion), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), v8::Date::New(Nan::GetCurrentContext(), stat->ctime/1000.).ToLocalChecked(), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), v8::Date::New(Nan::GetCurrentContext(), stat->mtime/1000.).ToLocalChecked(), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), Date::New(Nan::GetCurrentContext(), stat->ctime/1000.).ToLocalChecked(), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), Date::New(Nan::GetCurrentContext(), stat->mtime/1000.).ToLocalChecked(), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("ephemeralOwner"), idAsString(stat->ephemeralOwner), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("createdInThisSession"), Nan::New(myid.client_id == stat->ephemeralOwner), ReadOnly); return scope.Escape(o); @@ -723,18 +723,18 @@ class ZooKeeper: public Nan::ObjectWrap { CALLBACK_EPILOG(); } - static void AExists(const Nan::FunctionCallbackInfo& info) { + static void AExists(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); } - static void AWExists(const Nan::FunctionCallbackInfo& info) { + static void AWExists(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_awexists(zk->zhandle, *_path, &watcher_fn, cbw, &stat_completion, cb)); } @@ -754,20 +754,20 @@ class ZooKeeper: public Nan::ObjectWrap { CALLBACK_EPILOG(); } - static void Delete(const Nan::FunctionCallbackInfo& info) { + static void Delete(const Nan::FunctionCallbackInfo& info) { ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); int ret = zoo_delete(zk->zhandle, *_path, version); RETURN_VALUE(info, Nan::New(ret)); } - static void AGet(const Nan::FunctionCallbackInfo& info) { + static void AGet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); @@ -778,25 +778,25 @@ class ZooKeeper: public Nan::ObjectWrap { WATCHER_CALLBACK_EPILOG(); } - static void AWGet(const Nan::FunctionCallbackInfo& info) { + static void AWGet(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_awget(zk->zhandle, *_path, &watcher_fn, cbw, &data_completion, cb)); } - static void ASet(const Nan::FunctionCallbackInfo& info) { + static void ASet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other - Nan::Utf8String _data(info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _data(info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, *_data, _data.length(), version, &stat_completion, cb)); } } @@ -819,19 +819,19 @@ class ZooKeeper: public Nan::ObjectWrap { CALLBACK_EPILOG(); } - static void AGetChildren(const Nan::FunctionCallbackInfo& info) { + static void AGetChildren(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); } - static void AWGetChildren(const Nan::FunctionCallbackInfo& info) { + static void AWGetChildren(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_awget_children(zk->zhandle, *_path, &watcher_fn, cbw, &strings_completion, cb)); } @@ -856,35 +856,35 @@ class ZooKeeper: public Nan::ObjectWrap { CALLBACK_EPILOG(); } - static void AGetChildren2(const Nan::FunctionCallbackInfo& info) { + static void AGetChildren2(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); } - static void AWGetChildren2(const Nan::FunctionCallbackInfo& info) { + static void AWGetChildren2(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_awget_children2(zk->zhandle, *_path, &watcher_fn, cbw, &strings_stat_completion, cb)); } - static void AGetAcl(const Nan::FunctionCallbackInfo& info) { + static void AGetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_aget_acl(zk->zhandle, *_path, &acl_completion, cb)); } - static void ASetAcl(const Nan::FunctionCallbackInfo& info) { + static void ASetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t _version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); Local arr = Local::Cast(info[2]); @@ -898,19 +898,19 @@ class ZooKeeper: public Nan::ObjectWrap { METHOD_EPILOG(zoo_aset_acl(zk->zhandle, *_path, _version, aclv, void_completion, data)); } - static void ASync(const Nan::FunctionCallbackInfo& info) { + static void ASync(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); METHOD_EPILOG(zoo_async(zk->zhandle, *_path, &string_completion, cb)); } - static void AddAuth(const Nan::FunctionCallbackInfo& info) { + static void AddAuth(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _scheme (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - Nan::Utf8String _auth (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _scheme (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _auth (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -947,11 +947,11 @@ class ZooKeeper: public Nan::ObjectWrap { aclv->data = (struct ACL *) calloc(aclv->count, sizeof(struct ACL)); for (int i = 0, l = aclv->count; i < l; i++) { - v8::Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); + Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); Local obj = Local::Cast(obj_local); - Nan::Utf8String _scheme (toLocalVal(obj, LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); - Nan::Utf8String _auth (toLocalVal(obj, LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local())); + Nan::Utf8String _scheme (toLocalVal(obj, LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _auth (toLocalVal(obj, LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); uint32_t _perms = toLocalVal(obj, LOCAL_STRING("perm"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct Id id; @@ -1053,7 +1053,7 @@ class ZooKeeper: public Nan::ObjectWrap { zk->Unref(); } - static void Close(const Nan::FunctionCallbackInfo& info) { + static void Close(const Nan::FunctionCallbackInfo& info) { ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); zk->realClose(0); From 2b9974220e358a33f887182288fd8fd7398e4637 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 5 Jul 2019 10:48:34 +0200 Subject: [PATCH 14/33] fix: convert unix time to v8 date --- src/node-zk.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node-zk.cpp b/src/node-zk.cpp index efcccc48..f5dedbc8 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -432,6 +432,10 @@ class ZooKeeper: public Nan::ObjectWrap { return val; } + static Local convertUnixTimeToDate(double time) { + return v8::Date::New(v8::Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); + } + static void Init(const Nan::FunctionCallbackInfo& info) { THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); @@ -707,8 +711,8 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(o, LOCAL_STRING("version"), Nan::New(stat->version), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("cversion"), Nan::New(stat->cversion), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("aversion"), Nan::New(stat->aversion), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), Date::New(Nan::GetCurrentContext(), stat->ctime/1000.).ToLocalChecked(), ReadOnly); - Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), Date::New(Nan::GetCurrentContext(), stat->mtime/1000.).ToLocalChecked(), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("ctime"), convertUnixTimeToDate(stat->ctime), ReadOnly); + Nan::DefineOwnProperty(o, LOCAL_STRING("mtime"), convertUnixTimeToDate(stat->mtime), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("ephemeralOwner"), idAsString(stat->ephemeralOwner), ReadOnly); Nan::DefineOwnProperty(o, LOCAL_STRING("createdInThisSession"), Nan::New(myid.client_id == stat->ephemeralOwner), ReadOnly); return scope.Escape(o); From 4de73e34031b46eccab79d076a8a04888c815e20 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Thu, 11 Jul 2019 23:37:26 +0200 Subject: [PATCH 15/33] WIP: move converters to separate file --- src/converters.h | 31 ++++++++++++++++++++ src/node-zk.cpp | 74 +++++++++++++++++------------------------------- 2 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 src/converters.h diff --git a/src/converters.h b/src/converters.h new file mode 100644 index 00000000..a6b0b2fc --- /dev/null +++ b/src/converters.h @@ -0,0 +1,31 @@ +#include +#include "nan.h" + +using namespace v8; + +Local toLocalVal(Local arg, Local propertyName) { + Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); + return val_local; +} + +int32_t fromJustInt(Local arg, Local propertyName) { + Local val_local = toLocalVal(arg, propertyName); + int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); + + return val; +} + +bool fromJustBool(Local arg, Local propertyName) { + Local val_local = toLocalVal(arg, propertyName); + bool val = Nan::To(val_local).FromJust(); + + return val; +} + +Local convertUnixTimeToDate(double time) { + return Date::New(Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); +} + +Local toStr(Local val) { + return val->ToString(Nan::GetCurrentContext()).FromMaybe(Local()); +} diff --git a/src/node-zk.cpp b/src/node-zk.cpp index f5dedbc8..77ac3b0b 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -25,6 +25,7 @@ using namespace node; #include "nan.h" #include "zk_log.h" #include "buffer_compat.h" +#include "converters.h" #ifdef WIN32 #pragma comment (lib, "Ws2_32.lib") @@ -413,29 +414,6 @@ class ZooKeeper: public Nan::ObjectWrap { return true; } - static Local toLocalVal(Local arg, Local propertyName) { - Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); - return val_local; - } - - static int32_t fromJustInt(Local arg, Local propertyName) { - Local val_local = toLocalVal(arg, propertyName); - int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); - - return val; - } - - static bool fromJustBool(Local arg, Local propertyName) { - Local val_local = toLocalVal(arg, propertyName); - bool val = Nan::To(val_local).FromJust(); - - return val; - } - - static Local convertUnixTimeToDate(double time) { - return v8::Date::New(v8::Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); - } - static void Init(const Nan::FunctionCallbackInfo& info) { THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); @@ -447,7 +425,7 @@ class ZooKeeper: public Nan::ObjectWrap { bool order = fromJustBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order - Nan::Utf8String _hostPort (toLocalVal(arg, LOCAL_STRING("connect"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _hostPort (toStr(toLocalVal(arg, LOCAL_STRING("connect")))); int32_t session_timeout = fromJustInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; @@ -462,7 +440,7 @@ class ZooKeeper: public Nan::ObjectWrap { THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), "ZK init: client id and password must either be both specified or unspecified"); if (id_and_password_defined) { - Nan::Utf8String password_check(v8v_client_password->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String password_check(toStr(v8v_client_password)); THROW_IF_NOT (password_check.length() == 2 * ZOOKEEPER_PASSWORD_BYTE_COUNT, "ZK init: password does not have correct length"); HexStringToPassword(v8v_client_password, local_client.passwd); @@ -520,7 +498,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void StringToId (Local s, int64_t *id) { - Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String a(toStr(s)); sscanf(*a, "%llx", _LLP_CAST_ id); } @@ -536,7 +514,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void HexStringToPassword (Local s, char *p) { - Nan::Utf8String a(s->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String a(toStr(s)); char *hex = *a; for (int i = 0; i < ZOOKEEPER_PASSWORD_BYTE_COUNT; ++i) { hexToUchar(hex, (unsigned char *)p+i); @@ -659,14 +637,14 @@ class ZooKeeper: public Nan::ObjectWrap { static void ACreate(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other - Nan::Utf8String _data (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _data (toStr(info[1])); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } } @@ -689,7 +667,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ADelete(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); @@ -730,7 +708,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AExists(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); @@ -738,7 +716,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWExists(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_awexists(zk->zhandle, *_path, &watcher_fn, cbw, &stat_completion, cb)); } @@ -761,7 +739,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void Delete(const Nan::FunctionCallbackInfo& info) { ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); int ret = zoo_delete(zk->zhandle, *_path, version); @@ -771,7 +749,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); @@ -785,7 +763,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGet(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_awget(zk->zhandle, *_path, &watcher_fn, cbw, &data_completion, cb)); } @@ -793,14 +771,14 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer Local _data = Nan::To(info[1]).ToLocalChecked(); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other - Nan::Utf8String _data(info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _data(toStr(info[1])); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, *_data, _data.length(), version, &stat_completion, cb)); } } @@ -826,7 +804,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); @@ -835,7 +813,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_awget_children(zk->zhandle, *_path, &watcher_fn, cbw, &strings_completion, cb)); } @@ -863,7 +841,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren2(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); bool watch = Nan::To(info[1]).FromJust(); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); @@ -872,7 +850,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren2(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_awget_children2(zk->zhandle, *_path, &watcher_fn, cbw, &strings_stat_completion, cb)); } @@ -880,7 +858,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_aget_acl(zk->zhandle, *_path, &acl_completion, cb)); } @@ -888,7 +866,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); uint32_t _version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); Local arr = Local::Cast(info[2]); @@ -905,7 +883,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASync(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _path (toStr(info[0])); METHOD_EPILOG(zoo_async(zk->zhandle, *_path, &string_completion, cb)); } @@ -913,8 +891,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AddAuth(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _scheme (info[0]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); - Nan::Utf8String _auth (info[1]->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _scheme (toStr(info[0])); + Nan::Utf8String _auth (toStr(info[1])); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -954,8 +932,8 @@ class ZooKeeper: public Nan::ObjectWrap { Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); Local obj = Local::Cast(obj_local); - Nan::Utf8String _scheme (toLocalVal(obj, LOCAL_STRING("scheme"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); - Nan::Utf8String _auth (toLocalVal(obj, LOCAL_STRING("auth"))->ToString(Nan::GetCurrentContext()).FromMaybe(Local())); + Nan::Utf8String _scheme (toStr(toLocalVal(obj, LOCAL_STRING("scheme")))); + Nan::Utf8String _auth (toStr(toLocalVal(obj, LOCAL_STRING("auth")))); uint32_t _perms = toLocalVal(obj, LOCAL_STRING("perm"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); struct Id id; From c688ad7afe5e2527cb7ea798b24dd5099a2d6836 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Thu, 11 Jul 2019 23:39:27 +0200 Subject: [PATCH 16/33] WIP: move converters to separate file --- binding.gyp | 2 +- src/converters.h | 13 +++++++++++-- src/node-zk.cpp | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/binding.gyp b/binding.gyp index 2bdfbdf7..1105dacc 100644 --- a/binding.gyp +++ b/binding.gyp @@ -15,7 +15,7 @@ '/opt/local/include/zookeeper', ' toLocalObj(Local val) { + return Nan::To(val).ToLocalChecked(); +} + Local toLocalVal(Local arg, Local propertyName) { Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); return val_local; } -int32_t fromJustInt(Local arg, Local propertyName) { - Local val_local = toLocalVal(arg, propertyName); +int32_t fromJustInt(Local val_local) { int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); return val; } +int32_t fromJustInt(Local arg, Local propertyName) { + Local val_local = toLocalVal(arg, propertyName); + + return fromJustInt(val_local); +} + bool fromJustBool(Local arg, Local propertyName) { Local val_local = toLocalVal(arg, propertyName); bool val = Nan::To(val_local).FromJust(); diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 77ac3b0b..fd6bc4d4 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -417,7 +417,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void Init(const Nan::FunctionCallbackInfo& info) { THROW_IF_NOT(info.Length() >= 1, "Must pass ZK init object"); THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); - Local arg = Nan::To(info[0]).ToLocalChecked(); + Local arg = toLocalObj(info[0]); int32_t debug_level = fromJustInt(arg, LOCAL_STRING("debug_level")); zoo_set_debug_level(static_cast(debug_level)); @@ -641,7 +641,7 @@ class ZooKeeper: public Nan::ObjectWrap { uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Local _data = Nan::To(info[1]).ToLocalChecked(); + Local _data = toLocalObj(info[1]); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other Nan::Utf8String _data (toStr(info[1])); @@ -775,7 +775,7 @@ class ZooKeeper: public Nan::ObjectWrap { uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); if (Buffer::HasInstance(info[1])) { // buffer - Local _data = Nan::To(info[1]).ToLocalChecked(); + Local _data = toLocalObj(info[1]); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other Nan::Utf8String _data(toStr(info[1])); From 11198fc273c15a363fbff7e46d0bfad73e01f187 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 12 Jul 2019 12:03:44 +0200 Subject: [PATCH 17/33] WIP: add C++ converters unit tests --- .travis.yml | 2 ++ package.json | 3 ++- tests_cpp/README.md | 16 ++++++++++++++++ tests_cpp/binding.gyp | 19 +++++++++++++++++++ tests_cpp/converterstest.js | 27 +++++++++++++++++++++++++++ tests_cpp/node-converters.cpp | 26 ++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests_cpp/README.md create mode 100644 tests_cpp/binding.gyp create mode 100644 tests_cpp/converterstest.js create mode 100644 tests_cpp/node-converters.cpp diff --git a/.travis.yml b/.travis.yml index 78a50303..b0dee7a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ install: - npm install script: - npm test + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm run cpp-test; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run cpp-test; fi addons: apt: sources: diff --git a/package.json b/package.json index dbf0e2f4..41cdcb6f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,8 @@ "install": "node ./scripts/prepublish.js && npm run build", "lint": "eslint .", "integrationtest": "pushd tests_integration; source ./test; popd", - "test": "npm run lint && tape ./tests/**/*.js | tap-spec" + "test": "npm run lint && tape ./tests/**/*.js | tap-spec", + "cpp-test": "mkdir tests_cpp/build; pushd tests_cpp; node-gyp configure build; popd; tape ./tests_cpp/**/*.js | tap-spec" }, "engines": { "node": ">=8.9.4" diff --git a/tests_cpp/README.md b/tests_cpp/README.md new file mode 100644 index 00000000..36eaa4f9 --- /dev/null +++ b/tests_cpp/README.md @@ -0,0 +1,16 @@ +### Setup ### +1. `git clone https://github.com/google/googletest` +2. `cd googletest` +3. `mkdir build` +4. `cd build` +5. `cmake ..` +6. `make` +7. `make install` + +Note: step 7 may require a `sudo make install` + +### Run #### +(Mac OS X/Linux) +```bash +npm run cpp-test +``` diff --git a/tests_cpp/binding.gyp b/tests_cpp/binding.gyp new file mode 100644 index 00000000..a3639e24 --- /dev/null +++ b/tests_cpp/binding.gyp @@ -0,0 +1,19 @@ +{ + 'variables': { + 'platform': '<(OS)', + }, + "targets": [{ + "target_name": "converters", + "sources": ["node-converters.cpp"], + 'cflags': ['-Wall', '-O0'], + 'conditions': [ + ['OS=="mac"', { + 'xcode_settings': { + 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', + 'MACOSX_DEPLOYMENT_TARGET': ' { + t.plan(2); + const expected = 4711; + const res = converters.toStrTest(expected); + + t.deepEquals(res, `${expected}`); + t.deepEquals(typeof res, typeof ''); +}); + +test('Unix time is converted to date', (t) => { + t.plan(1); + const now = Date.now(); + + const d = new Date(now); + const expected = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}}`; + + const unixTime = Math.round(now / 1000); + const converted = converters.convertUnixTimeToDateTest(unixTime); + + const r = new Date(converted * 1000); + const res = `${r.getFullYear()}-${r.getMonth()}-${r.getDate()}}`; + + t.deepEquals(res, expected); +}); diff --git a/tests_cpp/node-converters.cpp b/tests_cpp/node-converters.cpp new file mode 100644 index 00000000..839426c7 --- /dev/null +++ b/tests_cpp/node-converters.cpp @@ -0,0 +1,26 @@ +#include "../src/converters.h" +#include +#include +using namespace v8; + +NAN_METHOD(convertUnixTimeToDateTest) { + Local arg = Nan::To(info[0]).ToLocalChecked(); + int32_t val = fromJustInt(arg); + + Local res = convertUnixTimeToDate(val); + + info.GetReturnValue().Set(res); +} + +NAN_METHOD(toStrTest) { + Local res = toStr(info[0]); + + info.GetReturnValue().Set(res); +} + +NAN_MODULE_INIT(Init) { + NAN_EXPORT(target, toStrTest); + NAN_EXPORT(target, convertUnixTimeToDateTest); +} + +NODE_MODULE(unit_tests, Init) From 4caf907a354e1be341e7197e9fca6b572a3b9180 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 12 Jul 2019 12:09:43 +0200 Subject: [PATCH 18/33] WIP: add C++ converters unit tests --- tests_cpp/converterstest.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests_cpp/converterstest.js b/tests_cpp/converterstest.js index 73a3143c..c2b93f1b 100644 --- a/tests_cpp/converterstest.js +++ b/tests_cpp/converterstest.js @@ -1,3 +1,4 @@ +/* eslint-disable import/no-extraneous-dependencies */ const test = require('tape'); const converters = require('./build/Release/converters.node'); From 80bf122a35305239b42a8289f2c5157e37fd371c Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 12 Jul 2019 12:17:32 +0200 Subject: [PATCH 19/33] WIP: add C++ converters unit tests --- tests_cpp/converterstest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests_cpp/converterstest.js b/tests_cpp/converterstest.js index c2b93f1b..40ea4711 100644 --- a/tests_cpp/converterstest.js +++ b/tests_cpp/converterstest.js @@ -1,4 +1,4 @@ -/* eslint-disable import/no-extraneous-dependencies */ +/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */ const test = require('tape'); const converters = require('./build/Release/converters.node'); From 8faffe16080bf340276b13a7a7f4e793d116db9a Mon Sep 17 00:00:00 2001 From: davidvujic Date: Fri, 12 Jul 2019 18:20:09 +0200 Subject: [PATCH 20/33] WIP: unit tests for C++ source files --- .travis.yml | 3 +- package.json | 3 +- tests_components/README.md | 9 +++++ tests_components/binding.gyp | 34 +++++++++++++++++++ .../converterstest.js | 0 .../wrappers}/node-converters.cpp | 2 +- tests_cpp/README.md | 16 --------- tests_cpp/binding.gyp | 19 ----------- 8 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 tests_components/README.md create mode 100644 tests_components/binding.gyp rename {tests_cpp => tests_components}/converterstest.js (100%) rename {tests_cpp => tests_components/wrappers}/node-converters.cpp (94%) delete mode 100644 tests_cpp/README.md delete mode 100644 tests_cpp/binding.gyp diff --git a/.travis.yml b/.travis.yml index b0dee7a4..54794788 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,7 @@ install: - npm install script: - npm test - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm run cpp-test; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run cpp-test; fi + - npm run cpp-test addons: apt: sources: diff --git a/package.json b/package.json index 41cdcb6f..388a4bdc 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,12 @@ "main": "lib/index", "scripts": { "build": "node-gyp configure build", + "build-components": "mkdir tests_components/build; cd tests_components; node-gyp configure build; cd ..", "install": "node ./scripts/prepublish.js && npm run build", "lint": "eslint .", "integrationtest": "pushd tests_integration; source ./test; popd", "test": "npm run lint && tape ./tests/**/*.js | tap-spec", - "cpp-test": "mkdir tests_cpp/build; pushd tests_cpp; node-gyp configure build; popd; tape ./tests_cpp/**/*.js | tap-spec" + "test-components": "npm run build-components && tape ./tests_components/**/*.js | tap-spec" }, "engines": { "node": ">=8.9.4" diff --git a/tests_components/README.md b/tests_components/README.md new file mode 100644 index 00000000..3ba5e430 --- /dev/null +++ b/tests_components/README.md @@ -0,0 +1,9 @@ +### Component unit tests ### + +Unit tests written in JavaScript, verifying functionality in C++ files that are included in the ZooKeeper wrapper `node-zk.cpp`. + +#### Run tests ##### +```bash +npm run test-converters +``` +The command will build C++ code to Native Node.js addons, to make it testable with JavaScript. The source files are included by C++ wrapper files with Addon features from the Nan library (the files are stored in the `wrappers` folder). diff --git a/tests_components/binding.gyp b/tests_components/binding.gyp new file mode 100644 index 00000000..7ae4c1ea --- /dev/null +++ b/tests_components/binding.gyp @@ -0,0 +1,34 @@ +{ + 'variables': { + 'platform': '<(OS)', + }, + "targets": [{ + "target_name": "converters", + "sources": ["wrappers/node-converters.cpp"], + 'cflags': ['-Wall', '-O0'], + 'conditions': [ + ['OS=="mac"', { + 'xcode_settings': { + 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', + 'MACOSX_DEPLOYMENT_TARGET': ' #include using namespace v8; diff --git a/tests_cpp/README.md b/tests_cpp/README.md deleted file mode 100644 index 36eaa4f9..00000000 --- a/tests_cpp/README.md +++ /dev/null @@ -1,16 +0,0 @@ -### Setup ### -1. `git clone https://github.com/google/googletest` -2. `cd googletest` -3. `mkdir build` -4. `cd build` -5. `cmake ..` -6. `make` -7. `make install` - -Note: step 7 may require a `sudo make install` - -### Run #### -(Mac OS X/Linux) -```bash -npm run cpp-test -``` diff --git a/tests_cpp/binding.gyp b/tests_cpp/binding.gyp deleted file mode 100644 index a3639e24..00000000 --- a/tests_cpp/binding.gyp +++ /dev/null @@ -1,19 +0,0 @@ -{ - 'variables': { - 'platform': '<(OS)', - }, - "targets": [{ - "target_name": "converters", - "sources": ["node-converters.cpp"], - 'cflags': ['-Wall', '-O0'], - 'conditions': [ - ['OS=="mac"', { - 'xcode_settings': { - 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': ' Date: Fri, 12 Jul 2019 18:24:51 +0200 Subject: [PATCH 21/33] fix: typo --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54794788..5a8351bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "10" - "8" + - "10" - "12" os: - linux @@ -14,7 +14,7 @@ install: - npm install script: - npm test - - npm run cpp-test + - npm run test-components addons: apt: sources: From cbde9e2f588f214d99f7b86ef2f7e2067c47a6ee Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 13 Jul 2019 22:50:24 +0200 Subject: [PATCH 22/33] fix: run component tests cross platform --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 388a4bdc..84c62679 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "main": "lib/index", "scripts": { "build": "node-gyp configure build", - "build-components": "mkdir tests_components/build; cd tests_components; node-gyp configure build; cd ..", + "build-components": "node-gyp configure build --directory=tests_components", "install": "node ./scripts/prepublish.js && npm run build", "lint": "eslint .", "integrationtest": "pushd tests_integration; source ./test; popd", From 1dea2a6d0c37915ac94bc862ee5d5bf782c5fe8c Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 13 Jul 2019 23:37:05 +0200 Subject: [PATCH 23/33] fix: custom eslint rules for test folder --- tests_components/.eslintrc.json | 9 +++++++++ tests_components/converterstest.js | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests_components/.eslintrc.json diff --git a/tests_components/.eslintrc.json b/tests_components/.eslintrc.json new file mode 100644 index 00000000..f4d42ef4 --- /dev/null +++ b/tests_components/.eslintrc.json @@ -0,0 +1,9 @@ +{ + "rules": { + "import/no-extraneous-dependencies": ["error", { + "devDependencies": true + }], + "import/no-unresolved": ["error", {}], + "no-console": 0 + } +} diff --git a/tests_components/converterstest.js b/tests_components/converterstest.js index 40ea4711..73a3143c 100644 --- a/tests_components/converterstest.js +++ b/tests_components/converterstest.js @@ -1,4 +1,3 @@ -/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */ const test = require('tape'); const converters = require('./build/Release/converters.node'); From 8a2460dcb56635abd9d08bce5876f6cfd51f506f Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 13 Jul 2019 23:53:04 +0200 Subject: [PATCH 24/33] added unit tests for converters --- tests_components/converterstest.js | 17 ++++++++++++++++ tests_components/wrappers/node-converters.cpp | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests_components/converterstest.js b/tests_components/converterstest.js index 73a3143c..1668e871 100644 --- a/tests_components/converterstest.js +++ b/tests_components/converterstest.js @@ -25,3 +25,20 @@ test('Unix time is converted to date', (t) => { t.deepEquals(res, expected); }); + +test('Object value is converted to bool', (t) => { + t.plan(2); + const expected = true; + const res = converters.fromJustBoolTest({ val: 'true' }); + + t.deepEquals(res, expected); + t.deepEquals(typeof res, typeof true); +}); + +test('Object value is converted to integer', (t) => { + t.plan(1); + const expected = 4711; + const res = converters.fromJustIntTest({ val: '4711' }); + + t.deepEquals(res, expected); +}); diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index af6f1b28..b51977fd 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -3,6 +3,24 @@ #include using namespace v8; +NAN_METHOD(fromJustIntTest) { + Local arg = Nan::To(info[0]).ToLocalChecked(); + Local key = Nan::New("val").ToLocalChecked(); + + int32_t res = fromJustInt(arg, key); + + info.GetReturnValue().Set(res); +} + +NAN_METHOD(fromJustBoolTest) { + Local arg = Nan::To(info[0]).ToLocalChecked(); + Local key = Nan::New("val").ToLocalChecked(); + + bool res = fromJustBool(arg, key); + + info.GetReturnValue().Set(res); +} + NAN_METHOD(convertUnixTimeToDateTest) { Local arg = Nan::To(info[0]).ToLocalChecked(); int32_t val = fromJustInt(arg); @@ -21,6 +39,8 @@ NAN_METHOD(toStrTest) { NAN_MODULE_INIT(Init) { NAN_EXPORT(target, toStrTest); NAN_EXPORT(target, convertUnixTimeToDateTest); + NAN_EXPORT(target, fromJustBoolTest); + NAN_EXPORT(target, fromJustIntTest); } NODE_MODULE(unit_tests, Init) From 9fe2ac992813169b77e6c2a2abeecbde48d988eb Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 00:12:53 +0200 Subject: [PATCH 25/33] refactor: use bool converter --- src/converters.h | 7 +++++-- src/node-zk.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/converters.h b/src/converters.h index 48861521..fe361ef8 100644 --- a/src/converters.h +++ b/src/converters.h @@ -24,11 +24,14 @@ int32_t fromJustInt(Local arg, Local propertyName) { return fromJustInt(val_local); } +bool fromJustBool(Local val_local) { + return Nan::To(val_local).FromJust(); +} + bool fromJustBool(Local arg, Local propertyName) { Local val_local = toLocalVal(arg, propertyName); - bool val = Nan::To(val_local).FromJust(); - return val; + return fromJustBool(val_local); } Local convertUnixTimeToDate(double time) { diff --git a/src/node-zk.cpp b/src/node-zk.cpp index fd6bc4d4..d38aafdb 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -709,7 +709,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = Nan::To(info[1]).FromJust(); + bool watch = fromJustBool(info[1]); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); } @@ -750,7 +750,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = Nan::To(info[1]).FromJust(); + bool watch = fromJustBool(info[1]); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); } @@ -805,7 +805,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = Nan::To(info[1]).FromJust(); + bool watch = fromJustBool(info[1]); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); } @@ -842,7 +842,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = Nan::To(info[1]).FromJust(); + bool watch = fromJustBool(info[1]); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); } From b1ae3a5e4eac0fcbb8688cd865548da24b8dcfb9 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 00:26:30 +0200 Subject: [PATCH 26/33] refactor: uint32 converter function --- src/converters.h | 4 ++++ src/node-zk.cpp | 12 ++++++------ tests_components/converterstest.js | 13 ++++++++++++- tests_components/wrappers/node-converters.cpp | 7 +++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/converters.h b/src/converters.h index fe361ef8..a0cb6727 100644 --- a/src/converters.h +++ b/src/converters.h @@ -41,3 +41,7 @@ Local convertUnixTimeToDate(double time) { Local toStr(Local val) { return val->ToString(Nan::GetCurrentContext()).FromMaybe(Local()); } + +uint32_t toUint(Local val) { + return val->Uint32Value(Nan::GetCurrentContext()).FromJust(); +} diff --git a/src/node-zk.cpp b/src/node-zk.cpp index d38aafdb..37ac295a 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -638,7 +638,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(4); Nan::Utf8String _path (toStr(info[0])); - uint32_t flags = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t flags = toUint(info[2]); if (Buffer::HasInstance(info[1])) { // buffer Local _data = toLocalObj(info[1]); @@ -668,7 +668,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ADelete(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t version = toUint(info[1]); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -740,7 +740,7 @@ class ZooKeeper: public Nan::ObjectWrap { ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); Nan::Utf8String _path (toStr(info[0])); - uint32_t version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t version = toUint(info[1]); int ret = zoo_delete(zk->zhandle, *_path, version); RETURN_VALUE(info, Nan::New(ret)); @@ -772,7 +772,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(4); Nan::Utf8String _path (toStr(info[0])); - uint32_t version = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t version = toUint(info[2]); if (Buffer::HasInstance(info[1])) { // buffer Local _data = toLocalObj(info[1]); @@ -867,7 +867,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(4); Nan::Utf8String _path (toStr(info[0])); - uint32_t _version = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t _version = toUint(info[1]); Local arr = Local::Cast(info[2]); struct ACL_vector *aclv = zk->createAclVector(arr); @@ -934,7 +934,7 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::Utf8String _scheme (toStr(toLocalVal(obj, LOCAL_STRING("scheme")))); Nan::Utf8String _auth (toStr(toLocalVal(obj, LOCAL_STRING("auth")))); - uint32_t _perms = toLocalVal(obj, LOCAL_STRING("perm"))->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t _perms = toUint(toLocalVal(obj, LOCAL_STRING("perm"))); struct Id id; struct ACL *acl = &aclv->data[i]; diff --git a/tests_components/converterstest.js b/tests_components/converterstest.js index 1668e871..52ada485 100644 --- a/tests_components/converterstest.js +++ b/tests_components/converterstest.js @@ -36,9 +36,20 @@ test('Object value is converted to bool', (t) => { }); test('Object value is converted to integer', (t) => { - t.plan(1); + t.plan(2); const expected = 4711; + const expectedNeg = -1; const res = converters.fromJustIntTest({ val: '4711' }); + const resNeg = converters.fromJustIntTest({ val: '-1' }); + + t.deepEquals(res, expected); + t.deepEquals(resNeg, expectedNeg); +}); + +test('Object value is converted to unsigned integer', (t) => { + t.plan(1); + const expected = 4711; + const res = converters.toUintTest('4711'); t.deepEquals(res, expected); }); diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index b51977fd..5d1354fb 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -3,6 +3,12 @@ #include using namespace v8; +NAN_METHOD(toUintTest) { + uint32_t res = toUint(info[0]); + + info.GetReturnValue().Set(res); +} + NAN_METHOD(fromJustIntTest) { Local arg = Nan::To(info[0]).ToLocalChecked(); Local key = Nan::New("val").ToLocalChecked(); @@ -41,6 +47,7 @@ NAN_MODULE_INIT(Init) { NAN_EXPORT(target, convertUnixTimeToDateTest); NAN_EXPORT(target, fromJustBoolTest); NAN_EXPORT(target, fromJustIntTest); + NAN_EXPORT(target, toUintTest); } NODE_MODULE(unit_tests, Init) From bfc833664a78cf05c0cfcf865e193cfb0201b692 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 00:32:59 +0200 Subject: [PATCH 27/33] refactor: rename converter functions --- src/converters.h | 12 ++++++------ src/node-zk.cpp | 14 +++++++------- tests_components/converterstest.js | 6 +++--- tests_components/wrappers/node-converters.cpp | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/converters.h b/src/converters.h index a0cb6727..5f49bfa5 100644 --- a/src/converters.h +++ b/src/converters.h @@ -12,26 +12,26 @@ Local toLocalVal(Local arg, Local propertyName) { return val_local; } -int32_t fromJustInt(Local val_local) { +int32_t toInt(Local val_local) { int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); return val; } -int32_t fromJustInt(Local arg, Local propertyName) { +int32_t toInt(Local arg, Local propertyName) { Local val_local = toLocalVal(arg, propertyName); - return fromJustInt(val_local); + return toInt(val_local); } -bool fromJustBool(Local val_local) { +bool toBool(Local val_local) { return Nan::To(val_local).FromJust(); } -bool fromJustBool(Local arg, Local propertyName) { +bool toBool(Local arg, Local propertyName) { Local val_local = toLocalVal(arg, propertyName); - return fromJustBool(val_local); + return toBool(val_local); } Local convertUnixTimeToDate(double time) { diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 37ac295a..d8ebb8bb 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -419,14 +419,14 @@ class ZooKeeper: public Nan::ObjectWrap { THROW_IF_NOT(info[0]->IsObject(), "Init argument must be an object"); Local arg = toLocalObj(info[0]); - int32_t debug_level = fromJustInt(arg, LOCAL_STRING("debug_level")); + int32_t debug_level = toInt(arg, LOCAL_STRING("debug_level")); zoo_set_debug_level(static_cast(debug_level)); - bool order = fromJustBool(arg, LOCAL_STRING("host_order_deterministic")); + bool order = toBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order Nan::Utf8String _hostPort (toStr(toLocalVal(arg, LOCAL_STRING("connect")))); - int32_t session_timeout = fromJustInt(arg, LOCAL_STRING("timeout")); + int32_t session_timeout = toInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; } @@ -709,7 +709,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = fromJustBool(info[1]); + bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); } @@ -750,7 +750,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = fromJustBool(info[1]); + bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); } @@ -805,7 +805,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = fromJustBool(info[1]); + bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); } @@ -842,7 +842,7 @@ class ZooKeeper: public Nan::ObjectWrap { A_METHOD_PROLOG(3); Nan::Utf8String _path (toStr(info[0])); - bool watch = fromJustBool(info[1]); + bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); } diff --git a/tests_components/converterstest.js b/tests_components/converterstest.js index 52ada485..3a22c430 100644 --- a/tests_components/converterstest.js +++ b/tests_components/converterstest.js @@ -29,7 +29,7 @@ test('Unix time is converted to date', (t) => { test('Object value is converted to bool', (t) => { t.plan(2); const expected = true; - const res = converters.fromJustBoolTest({ val: 'true' }); + const res = converters.toBoolTest({ val: 'true' }); t.deepEquals(res, expected); t.deepEquals(typeof res, typeof true); @@ -39,8 +39,8 @@ test('Object value is converted to integer', (t) => { t.plan(2); const expected = 4711; const expectedNeg = -1; - const res = converters.fromJustIntTest({ val: '4711' }); - const resNeg = converters.fromJustIntTest({ val: '-1' }); + const res = converters.toIntTest({ val: '4711' }); + const resNeg = converters.toIntTest({ val: '-1' }); t.deepEquals(res, expected); t.deepEquals(resNeg, expectedNeg); diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index 5d1354fb..38abe143 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -9,27 +9,27 @@ NAN_METHOD(toUintTest) { info.GetReturnValue().Set(res); } -NAN_METHOD(fromJustIntTest) { +NAN_METHOD(toIntTest) { Local arg = Nan::To(info[0]).ToLocalChecked(); Local key = Nan::New("val").ToLocalChecked(); - int32_t res = fromJustInt(arg, key); + int32_t res = toInt(arg, key); info.GetReturnValue().Set(res); } -NAN_METHOD(fromJustBoolTest) { +NAN_METHOD(toBoolTest) { Local arg = Nan::To(info[0]).ToLocalChecked(); Local key = Nan::New("val").ToLocalChecked(); - bool res = fromJustBool(arg, key); + bool res = toBool(arg, key); info.GetReturnValue().Set(res); } NAN_METHOD(convertUnixTimeToDateTest) { Local arg = Nan::To(info[0]).ToLocalChecked(); - int32_t val = fromJustInt(arg); + int32_t val = toInt(arg); Local res = convertUnixTimeToDate(val); @@ -45,8 +45,8 @@ NAN_METHOD(toStrTest) { NAN_MODULE_INIT(Init) { NAN_EXPORT(target, toStrTest); NAN_EXPORT(target, convertUnixTimeToDateTest); - NAN_EXPORT(target, fromJustBoolTest); - NAN_EXPORT(target, fromJustIntTest); + NAN_EXPORT(target, toBoolTest); + NAN_EXPORT(target, toIntTest); NAN_EXPORT(target, toUintTest); } From 6823321b24a9a63d7d9acce5216c70afa6c4c6c8 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 22:26:18 +0200 Subject: [PATCH 28/33] fix: file extension --- src/{converters.h => converters.hpp} | 0 src/node-zk.cpp | 2 +- tests_components/wrappers/node-converters.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{converters.h => converters.hpp} (100%) diff --git a/src/converters.h b/src/converters.hpp similarity index 100% rename from src/converters.h rename to src/converters.hpp diff --git a/src/node-zk.cpp b/src/node-zk.cpp index d8ebb8bb..bfb7fbfd 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -25,7 +25,7 @@ using namespace node; #include "nan.h" #include "zk_log.h" #include "buffer_compat.h" -#include "converters.h" +#include "converters.hpp" #ifdef WIN32 #pragma comment (lib, "Ws2_32.lib") diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index 38abe143..d1260137 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -1,4 +1,4 @@ -#include "../../src/converters.h" +#include "../../src/converters.hpp" #include #include using namespace v8; From 94a0d712b8c0cbf463797fa870a744e2521906c8 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 22:33:39 +0200 Subject: [PATCH 29/33] fix: converters within a namespace --- src/converters.hpp | 62 ++++++++++--------- src/node-zk.cpp | 5 +- tests_components/wrappers/node-converters.cpp | 1 + 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/converters.hpp b/src/converters.hpp index 5f49bfa5..55f4b6c5 100644 --- a/src/converters.hpp +++ b/src/converters.hpp @@ -3,45 +3,47 @@ using namespace v8; -Local toLocalObj(Local val) { - return Nan::To(val).ToLocalChecked(); -} +namespace nodezk { + Local toLocalObj(Local val) { + return Nan::To(val).ToLocalChecked(); + } -Local toLocalVal(Local arg, Local propertyName) { - Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); - return val_local; -} + Local toLocalVal(Local arg, Local propertyName) { + Local val_local = arg->Get(Nan::GetCurrentContext(), propertyName).ToLocalChecked(); + return val_local; + } -int32_t toInt(Local val_local) { - int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); + int32_t toInt(Local val_local) { + int32_t val = val_local->Int32Value(Nan::GetCurrentContext()).FromJust(); - return val; -} + return val; + } -int32_t toInt(Local arg, Local propertyName) { - Local val_local = toLocalVal(arg, propertyName); + int32_t toInt(Local arg, Local propertyName) { + Local val_local = toLocalVal(arg, propertyName); - return toInt(val_local); -} + return toInt(val_local); + } -bool toBool(Local val_local) { - return Nan::To(val_local).FromJust(); -} + bool toBool(Local val_local) { + return Nan::To(val_local).FromJust(); + } -bool toBool(Local arg, Local propertyName) { - Local val_local = toLocalVal(arg, propertyName); + bool toBool(Local arg, Local propertyName) { + Local val_local = toLocalVal(arg, propertyName); - return toBool(val_local); -} + return toBool(val_local); + } -Local convertUnixTimeToDate(double time) { - return Date::New(Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); -} + Local convertUnixTimeToDate(double time) { + return Date::New(Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); + } -Local toStr(Local val) { - return val->ToString(Nan::GetCurrentContext()).FromMaybe(Local()); -} + Local toStr(Local val) { + return val->ToString(Nan::GetCurrentContext()).FromMaybe(Local()); + } -uint32_t toUint(Local val) { - return val->Uint32Value(Nan::GetCurrentContext()).FromJust(); + uint32_t toUint(Local val) { + return val->Uint32Value(Nan::GetCurrentContext()).FromJust(); + } } diff --git a/src/node-zk.cpp b/src/node-zk.cpp index bfb7fbfd..e9bc9916 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -18,14 +18,15 @@ #include #include #include -using namespace v8; -using namespace node; #undef THREADED #include #include "nan.h" #include "zk_log.h" #include "buffer_compat.h" #include "converters.hpp" +using namespace v8; +using namespace node; +using namespace nodezk; #ifdef WIN32 #pragma comment (lib, "Ws2_32.lib") diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index d1260137..38f36a15 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -2,6 +2,7 @@ #include #include using namespace v8; +using namespace nodezk; NAN_METHOD(toUintTest) { uint32_t res = toUint(info[0]); From 40f979de6641609f6d067f16e4648ce63c8b246b Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sun, 14 Jul 2019 22:37:23 +0200 Subject: [PATCH 30/33] fix: clearer function name --- src/converters.hpp | 2 +- src/node-zk.cpp | 50 +++++++++---------- tests_components/wrappers/node-converters.cpp | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/converters.hpp b/src/converters.hpp index 55f4b6c5..d4c8a974 100644 --- a/src/converters.hpp +++ b/src/converters.hpp @@ -39,7 +39,7 @@ namespace nodezk { return Date::New(Isolate::GetCurrent()->GetCurrentContext(), time).ToLocalChecked(); } - Local toStr(Local val) { + Local toString(Local val) { return val->ToString(Nan::GetCurrentContext()).FromMaybe(Local()); } diff --git a/src/node-zk.cpp b/src/node-zk.cpp index e9bc9916..5e8b5a90 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -426,7 +426,7 @@ class ZooKeeper: public Nan::ObjectWrap { bool order = toBool(arg, LOCAL_STRING("host_order_deterministic")); zoo_deterministic_conn_order(order); // enable deterministic order - Nan::Utf8String _hostPort (toStr(toLocalVal(arg, LOCAL_STRING("connect")))); + Nan::Utf8String _hostPort (toString(toLocalVal(arg, LOCAL_STRING("connect")))); int32_t session_timeout = toInt(arg, LOCAL_STRING("timeout")); if (session_timeout == 0) { session_timeout = 20000; @@ -441,7 +441,7 @@ class ZooKeeper: public Nan::ObjectWrap { THROW_IF_NOT ((id_and_password_defined || id_and_password_undefined), "ZK init: client id and password must either be both specified or unspecified"); if (id_and_password_defined) { - Nan::Utf8String password_check(toStr(v8v_client_password)); + Nan::Utf8String password_check(toString(v8v_client_password)); THROW_IF_NOT (password_check.length() == 2 * ZOOKEEPER_PASSWORD_BYTE_COUNT, "ZK init: password does not have correct length"); HexStringToPassword(v8v_client_password, local_client.passwd); @@ -499,7 +499,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void StringToId (Local s, int64_t *id) { - Nan::Utf8String a(toStr(s)); + Nan::Utf8String a(toString(s)); sscanf(*a, "%llx", _LLP_CAST_ id); } @@ -515,7 +515,7 @@ class ZooKeeper: public Nan::ObjectWrap { } static void HexStringToPassword (Local s, char *p) { - Nan::Utf8String a(toStr(s)); + Nan::Utf8String a(toString(s)); char *hex = *a; for (int i = 0; i < ZOOKEEPER_PASSWORD_BYTE_COUNT; ++i) { hexToUchar(hex, (unsigned char *)p+i); @@ -638,14 +638,14 @@ class ZooKeeper: public Nan::ObjectWrap { static void ACreate(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); uint32_t flags = toUint(info[2]); if (Buffer::HasInstance(info[1])) { // buffer Local _data = toLocalObj(info[1]); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } else { // other - Nan::Utf8String _data (toStr(info[1])); + Nan::Utf8String _data (toString(info[1])); METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); } } @@ -668,7 +668,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ADelete(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); uint32_t version = toUint(info[1]); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); @@ -709,7 +709,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AExists(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aexists(zk->zhandle, *_path, watch, &stat_completion, cb)); @@ -717,7 +717,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWExists(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_awexists(zk->zhandle, *_path, &watcher_fn, cbw, &stat_completion, cb)); } @@ -740,7 +740,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void Delete(const Nan::FunctionCallbackInfo& info) { ZooKeeper *zk = ObjectWrap::Unwrap(info.This()); assert(zk); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); uint32_t version = toUint(info[1]); int ret = zoo_delete(zk->zhandle, *_path, version); @@ -750,7 +750,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget(zk->zhandle, *_path, watch, &data_completion, cb)); @@ -764,7 +764,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGet(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_awget(zk->zhandle, *_path, &watcher_fn, cbw, &data_completion, cb)); } @@ -772,14 +772,14 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASet(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); uint32_t version = toUint(info[2]); if (Buffer::HasInstance(info[1])) { // buffer Local _data = toLocalObj(info[1]); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), version, &stat_completion, cb)); } else { // other - Nan::Utf8String _data(toStr(info[1])); + Nan::Utf8String _data(toString(info[1])); METHOD_EPILOG(zoo_aset(zk->zhandle, *_path, *_data, _data.length(), version, &stat_completion, cb)); } } @@ -805,7 +805,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget_children(zk->zhandle, *_path, watch, &strings_completion, cb)); @@ -814,7 +814,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_awget_children(zk->zhandle, *_path, &watcher_fn, cbw, &strings_completion, cb)); } @@ -842,7 +842,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetChildren2(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); bool watch = toBool(info[1]); METHOD_EPILOG(zoo_aget_children2(zk->zhandle, *_path, watch, &strings_stat_completion, cb)); @@ -851,7 +851,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AWGetChildren2(const Nan::FunctionCallbackInfo& info) { AW_METHOD_PROLOG(3); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_awget_children2(zk->zhandle, *_path, &watcher_fn, cbw, &strings_stat_completion, cb)); } @@ -859,7 +859,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void AGetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_aget_acl(zk->zhandle, *_path, &acl_completion, cb)); } @@ -867,7 +867,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASetAcl(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(4); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); uint32_t _version = toUint(info[1]); Local arr = Local::Cast(info[2]); @@ -884,7 +884,7 @@ class ZooKeeper: public Nan::ObjectWrap { static void ASync(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(2); - Nan::Utf8String _path (toStr(info[0])); + Nan::Utf8String _path (toString(info[0])); METHOD_EPILOG(zoo_async(zk->zhandle, *_path, &string_completion, cb)); } @@ -892,8 +892,8 @@ class ZooKeeper: public Nan::ObjectWrap { static void AddAuth(const Nan::FunctionCallbackInfo& info) { A_METHOD_PROLOG(3); - Nan::Utf8String _scheme (toStr(info[0])); - Nan::Utf8String _auth (toStr(info[1])); + Nan::Utf8String _scheme (toString(info[0])); + Nan::Utf8String _auth (toString(info[1])); struct completion_data *data = (struct completion_data *) malloc(sizeof(struct completion_data)); data->cb = cb; @@ -933,8 +933,8 @@ class ZooKeeper: public Nan::ObjectWrap { Local obj_local = arr->Get(Nan::GetCurrentContext(), i).ToLocalChecked(); Local obj = Local::Cast(obj_local); - Nan::Utf8String _scheme (toStr(toLocalVal(obj, LOCAL_STRING("scheme")))); - Nan::Utf8String _auth (toStr(toLocalVal(obj, LOCAL_STRING("auth")))); + Nan::Utf8String _scheme (toString(toLocalVal(obj, LOCAL_STRING("scheme")))); + Nan::Utf8String _auth (toString(toLocalVal(obj, LOCAL_STRING("auth")))); uint32_t _perms = toUint(toLocalVal(obj, LOCAL_STRING("perm"))); struct Id id; diff --git a/tests_components/wrappers/node-converters.cpp b/tests_components/wrappers/node-converters.cpp index 38f36a15..6cf77214 100644 --- a/tests_components/wrappers/node-converters.cpp +++ b/tests_components/wrappers/node-converters.cpp @@ -38,7 +38,7 @@ NAN_METHOD(convertUnixTimeToDateTest) { } NAN_METHOD(toStrTest) { - Local res = toStr(info[0]); + Local res = toString(info[0]); info.GetReturnValue().Set(res); } From c80997cc35aee3e814b813445cf69648997a9972 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 16 Jul 2019 20:34:51 +0200 Subject: [PATCH 31/33] feat: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 84c62679..7bce47d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zookeeper", "description": "apache zookeeper client (zookeeper async API >= 3.4.0)", - "version": "4.1.1", + "version": "4.2.0", "author": "Yuri Finkelstein ", "license": "MIT", "contributors": [ From 3b5434774da76284035b6d6c59af03048538a5d0 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 16 Jul 2019 22:46:55 +0200 Subject: [PATCH 32/33] chore: Changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9940f12a..85a79612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +#### v 4.2.0 (2019-06-18) #### +* fix: Node.js 12 support +* fix: V8 and Nan deprecation warnings +* chore: reduce build output on Linux/Mac OS X. Pull request [183](https://github.com/yfinkelstein/node-zookeeper/pull/183) by @jbienkowski311 +* fix: deprecated getters and setters, pull request [181](https://github.com/yfinkelstein/node-zookeeper/pull/181) by @jbienkowski311 +* chore: pull request template, added by @jbienkowski311 +* chore: added integration test scripts + #### v 4.1.1 (2019-06-18) #### * feat: handle ZNOTHING return code from the ZooKeeper C library * fix: README typos From 767d541801d4bb70132a53aceb0aae974be8357b Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 16 Jul 2019 23:40:51 +0200 Subject: [PATCH 33/33] fix: typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a79612..d756c52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -#### v 4.2.0 (2019-06-18) #### +#### v 4.2.0 (2019-07-16) #### * fix: Node.js 12 support * fix: V8 and Nan deprecation warnings * chore: reduce build output on Linux/Mac OS X. Pull request [183](https://github.com/yfinkelstein/node-zookeeper/pull/183) by @jbienkowski311