1 #include <stdio.h>
2 #include <node_api.h>
3 #include <assert.h>
4 #include "../../js-native-api/common.h"
5
Test(napi_env env,napi_callback_info info)6 napi_value Test(napi_env env, napi_callback_info info) {
7 size_t argc = 1;
8 napi_value recv;
9 napi_value argv[1];
10 napi_status status;
11
12 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &recv, NULL));
13 NAPI_ASSERT(env, argc >= 1, "Not enough arguments, expected 1.");
14
15 napi_valuetype t;
16 NAPI_CALL(env, napi_typeof(env, argv[0], &t));
17 NAPI_ASSERT(env, t == napi_function,
18 "Wrong first argument, function expected.");
19
20 status = napi_call_function(env, recv, argv[0], 0, NULL, NULL);
21 assert(status == napi_ok);
22 status = napi_call_function(env, recv, argv[0], 0, NULL, NULL);
23 assert(status == napi_pending_exception);
24
25 return NULL;
26 }
27
Init(napi_env env,napi_value exports)28 napi_value Init(napi_env env, napi_value exports) {
29 napi_property_descriptor properties[] = {
30 DECLARE_NAPI_PROPERTY("Test", Test)
31 };
32
33 NAPI_CALL(env, napi_define_properties(
34 env, exports, sizeof(properties) / sizeof(*properties), properties));
35
36 return exports;
37 }
38
39 // Do not start using NAPI_MODULE_INIT() here, so that we can test
40 // compatibility of Workers with NAPI_MODULE().
41 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
42