1 // For the purpose of this test we use libuv's threading library. When deciding
2 // on a threading library for a new project it bears remembering that in the
3 // future libuv may introduce API changes which may render it non-ABI-stable,
4 // which, in turn, may affect the ABI stability of the project despite its use
5 // of N-API.
6 #include <uv.h>
7 #include <node_api.h>
8 #include "../../js-native-api/common.h"
9
10 static uv_thread_t uv_thread;
11
work_thread(void * data)12 static void work_thread(void* data) {
13 napi_fatal_error("work_thread", NAPI_AUTO_LENGTH,
14 "foobar", NAPI_AUTO_LENGTH);
15 }
16
Test(napi_env env,napi_callback_info info)17 static napi_value Test(napi_env env, napi_callback_info info) {
18 napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH,
19 "fatal message", NAPI_AUTO_LENGTH);
20 return NULL;
21 }
22
TestThread(napi_env env,napi_callback_info info)23 static napi_value TestThread(napi_env env, napi_callback_info info) {
24 NAPI_ASSERT(env,
25 (uv_thread_create(&uv_thread, work_thread, NULL) == 0),
26 "Thread creation");
27 return NULL;
28 }
29
TestStringLength(napi_env env,napi_callback_info info)30 static napi_value TestStringLength(napi_env env, napi_callback_info info) {
31 napi_fatal_error("test_fatal::TestStringLength", 16, "fatal message", 13);
32 return NULL;
33 }
34
Init(napi_env env,napi_value exports)35 static napi_value Init(napi_env env, napi_value exports) {
36 napi_property_descriptor properties[] = {
37 DECLARE_NAPI_PROPERTY("Test", Test),
38 DECLARE_NAPI_PROPERTY("TestStringLength", TestStringLength),
39 DECLARE_NAPI_PROPERTY("TestThread", TestThread),
40 };
41
42 NAPI_CALL(env, napi_define_properties(
43 env, exports, sizeof(properties) / sizeof(*properties), properties));
44
45 return exports;
46 }
47
48 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
49