nickdesaulniers / node-nanomsg

Node.js binding for nanomsg
MIT License
402 stars 70 forks source link

deprecation warning from Nan::Callback::call #209

Closed nickdesaulniers closed 5 years ago

nickdesaulniers commented 5 years ago

via npm install:

../src/node_nanomsg.cc: In member function ‘virtual void NanomsgDeviceWorker::HandleOKCallback()’:
../src/node_nanomsg.cc:233:27: warning: ‘v8::Local<v8::Value> Nan::Callback::Call(int, v8::Local<v8::Value>*) const’ is deprecated [-Wdeprecated-declarations]
     callback->Call(1, argv);
                           ^
In file included from ../src/poll_ctx.h:3:0,
                 from ../src/node_nanomsg.cc:7:
../node_modules/nan/nan.h:1740:3: note: declared here
   Call(int argc, v8::Local<v8::Value> argv[]) const {
   ^~~~
  CXX(target) Release/obj.target/node_nanomsg/src/poll_ctx.o
../src/poll_ctx.cc: In member function ‘void PollCtx::invoke_callback(int) const’:
../src/poll_ctx.cc:37:24: warning: ‘v8::Local<v8::Value> Nan::Callback::Call(int, v8::Local<v8::Value>*) const’ is deprecated [-Wdeprecated-declarations]
   callback.Call(1, argv);
                        ^
In file included from ../src/poll_ctx.h:3:0,
                 from ../src/poll_ctx.cc:2:
../node_modules/nan/nan.h:1740:3: note: declared here
   Call(int argc, v8::Local<v8::Value> argv[]) const {
   ^~~~

https://github.com/nodejs/nan/blob/master/doc/node_misc.md#api_nan_make_callback

nickdesaulniers commented 5 years ago

Looks like those interfaces are deprecated in favor of ones that additionally pass a Nan::AsyncResource.

https://github.com/nodejs/nan/blob/master/doc/callback.md#api_nan_callback https://github.com/nodejs/nan/blob/master/doc/node_misc.md#api_nan_make_callback

nickdesaulniers commented 5 years ago

so src/node_nanomsg.cc:233 is easy; we already subclass Nan::AsyncWorker, so just:

diff --git a/src/node_nanomsg.cc b/src/node_nanomsg.cc
index ab66db5..9b40b5e 100644
--- a/src/node_nanomsg.cc
+++ b/src/node_nanomsg.cc
@@ -230,7 +230,7 @@ public:

     Local<Value> argv[] = { Nan::New<Number>(err) };

-    callback->Call(1, argv);
+    callback->Call(1, argv, async_resource);
   };

 private:

is necessary. The change for poll_ctx.cc looks more involved, since we hand rolled a bit.