• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, &recv, NULL));
13   NODE_API_ASSERT(env, argc >= 1, "Not enough arguments, expected 1.");
14 
15   napi_valuetype t;
16   NODE_API_CALL(env, napi_typeof(env, argv[0], &t));
17   NODE_API_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_pending_exception);
22 
23   return NULL;
24 }
25 
Init(napi_env env,napi_value exports)26 napi_value Init(napi_env env, napi_value exports) {
27   napi_property_descriptor properties[] = {
28     DECLARE_NODE_API_PROPERTY("Test", Test)
29   };
30 
31   NODE_API_CALL(env, napi_define_properties(
32       env, exports, sizeof(properties) / sizeof(*properties), properties));
33 
34   return exports;
35 }
36 
37 // Do not start using NAPI_MODULE_INIT() here, so that we can test
38 // compatibility of Workers with NAPI_MODULE().
39 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
40