mirror of https://github.com/nodejs/node.git
34 lines
891 B
C++
34 lines
891 B
C++
#include <node_api.h>
|
|
#include "../common.h"
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
napi_value MakeCallback(napi_env env, napi_callback_info info) {
|
|
size_t argc = 2;
|
|
napi_value args[2];
|
|
// NOLINTNEXTLINE (readability/null_usage)
|
|
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
|
|
|
|
napi_value recv = args[0];
|
|
napi_value func = args[1];
|
|
|
|
napi_make_callback(env, nullptr /* async_context */,
|
|
recv, func, 0 /* argc */, nullptr /* argv */, nullptr /* result */);
|
|
|
|
return recv;
|
|
}
|
|
|
|
napi_value Init(napi_env env, napi_value exports) {
|
|
napi_value fn;
|
|
NAPI_CALL(env, napi_create_function(
|
|
// NOLINTNEXTLINE (readability/null_usage)
|
|
env, NULL, NAPI_AUTO_LENGTH, MakeCallback, NULL, &fn));
|
|
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
|
|
return exports;
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|