node/test/js-native-api/5_function_factory/binding.c
Gabriel Schulhof 938e11882b test: partition N-API tests
Partition test/addons-napi into test/js-native-api and test/node-api to
isolate the Node.js-agnostic portion of the N-API tests from the
Node.js-specific portion.

PR-URL: https://github.com/nodejs/node/pull/24557
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2018-12-04 13:58:17 -08:00

24 lines
625 B
C

#include <js_native_api.h>
#include "../common.h"
static napi_value MyFunction(napi_env env, napi_callback_info info) {
napi_value str;
NAPI_CALL(env, napi_create_string_utf8(env, "hello world", -1, &str));
return str;
}
static napi_value CreateFunction(napi_env env, napi_callback_info info) {
napi_value fn;
NAPI_CALL(env,
napi_create_function(env, "theFunction", -1, MyFunction, NULL, &fn));
return fn;
}
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env,
napi_create_function(env, "exports", -1, CreateFunction, NULL, &exports));
return exports;
}
EXTERN_C_END