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
10static uv_thread_t uv_thread;
11
12static void work_thread(void* data) {
13  napi_fatal_error("work_thread", NAPI_AUTO_LENGTH,
14      "foobar", NAPI_AUTO_LENGTH);
15}
16
17static 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
23static napi_value TestThread(napi_env env, napi_callback_info info) {
24  NODE_API_ASSERT(env,
25      (uv_thread_create(&uv_thread, work_thread, NULL) == 0),
26      "Thread creation");
27  return NULL;
28}
29
30static 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
35static napi_value Init(napi_env env, napi_value exports) {
36  napi_property_descriptor properties[] = {
37    DECLARE_NODE_API_PROPERTY("Test", Test),
38    DECLARE_NODE_API_PROPERTY("TestStringLength", TestStringLength),
39    DECLARE_NODE_API_PROPERTY("TestThread", TestThread),
40  };
41
42  NODE_API_CALL(env, napi_define_properties(
43      env, exports, sizeof(properties) / sizeof(*properties), properties));
44
45  return exports;
46}
47
48NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
49