1

There's an old Node.js native addon that I need for my work, but no longer works for Node.js 12 and above because of deprecation of many native APIs. Out of dozens of errors, I have fixed all but one, which has to do with initializing and calling a callback function. The new API requires 4 arguments, while the old one had three. This is the broken code:

void node_mpg123_feed_after (uv_work_t *req) {
  Nan::HandleScope scope;
  feed_req *r = (feed_req *)req->data;

  Local<Value> argv[1];
  argv[0] = Nan::New<Integer>(r->rtn);

  Nan::TryCatch try_catch;

  Nan::New(r->callback)->Call(Nan::GetCurrentContext()->Global(), 1, argv); //Compilation error in this line

  // cleanup
  r->callback.Reset();
  delete r;

  if (try_catch.HasCaught()) {
    FatalException(try_catch);
  }
}

Specifically, note the new API, which uses 4 arguments, and contrast it with the old one, which needs only three. I can't figure out what parameters to put in, since essentially no tutorials exist on the internet for the new API, and the internet is filled with examples of the old broken one.

Can anyone point me in the right direction? The exact error message I am getting is error C2660: 'v8::Function::Call': function does not take 3 arguments in the line I marked with the comment above.

Ermir
  • 1,391
  • 11
  • 25
  • Oof, porting an 0.8 API to current. I haven't delved in this in a long time, but perhaps there's some useful nuggets here that might help? https://stackoverflow.com/questions/45900692/how-to-use-the-same-context-across-multiple-functions-in-v8-javascript – Joe Dec 24 '19 at 03:51
  • It’s not necessarily a 0.8 API, but it matches the signature of what worked up until node 10. Thanks for the link, I’ll check it out. – Ermir Dec 24 '19 at 04:22

1 Answers1

0

After going through the nan changelog reading the nan sources, I found a new way of calling callbacks. Specifically, the line:

Nan::New(r->callback)->Call(Nan::GetCurrentContext()->Global(), 1, argv);

becomes

Nan::Call(Nan::New(r->callback), Nan::GetCurrentContext()->Global(), 1, argv);
Ermir
  • 1,391
  • 11
  • 25