File: movable_callbacks.cc

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (23 lines) | stat: -rw-r--r-- 517 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "napi.h"

using namespace Napi;

Value createExternal(const CallbackInfo& info) {
  FunctionReference ref = Reference<Function>::New(info[0].As<Function>(), 1);
  auto ret = External<char>::New(
      info.Env(),
      nullptr,
      [ref = std::move(ref)](Napi::Env /*env*/, char* /*data*/) {
        ref.Call({});
      });

  return ret;
}

Object InitMovableCallbacks(Env env) {
  Object exports = Object::New(env);

  exports["createExternal"] = Function::New(env, createExternal);

  return exports;
}