11cb0ef41Sopenharmony_ci// For the purpose of this test we use libuv's threading library. When deciding 21cb0ef41Sopenharmony_ci// on a threading library for a new project it bears remembering that in the 31cb0ef41Sopenharmony_ci// future libuv may introduce API changes which may render it non-ABI-stable, 41cb0ef41Sopenharmony_ci// which, in turn, may affect the ABI stability of the project despite its use 51cb0ef41Sopenharmony_ci// of N-API. 61cb0ef41Sopenharmony_ci#include <uv.h> 71cb0ef41Sopenharmony_ci#include <node_api.h> 81cb0ef41Sopenharmony_ci#include "../../js-native-api/common.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cistatic uv_thread_t uv_thread; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cistatic void work_thread(void* data) { 131cb0ef41Sopenharmony_ci napi_fatal_error("work_thread", NAPI_AUTO_LENGTH, 141cb0ef41Sopenharmony_ci "foobar", NAPI_AUTO_LENGTH); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cistatic napi_value Test(napi_env env, napi_callback_info info) { 181cb0ef41Sopenharmony_ci napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH, 191cb0ef41Sopenharmony_ci "fatal message", NAPI_AUTO_LENGTH); 201cb0ef41Sopenharmony_ci return NULL; 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_cistatic napi_value TestThread(napi_env env, napi_callback_info info) { 241cb0ef41Sopenharmony_ci NODE_API_ASSERT(env, 251cb0ef41Sopenharmony_ci (uv_thread_create(&uv_thread, work_thread, NULL) == 0), 261cb0ef41Sopenharmony_ci "Thread creation"); 271cb0ef41Sopenharmony_ci return NULL; 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cistatic napi_value TestStringLength(napi_env env, napi_callback_info info) { 311cb0ef41Sopenharmony_ci napi_fatal_error("test_fatal::TestStringLength", 16, "fatal message", 13); 321cb0ef41Sopenharmony_ci return NULL; 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports) { 361cb0ef41Sopenharmony_ci napi_property_descriptor properties[] = { 371cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("Test", Test), 381cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("TestStringLength", TestStringLength), 391cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("TestThread", TestThread), 401cb0ef41Sopenharmony_ci }; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_define_properties( 431cb0ef41Sopenharmony_ci env, exports, sizeof(properties) / sizeof(*properties), properties)); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci return exports; 461cb0ef41Sopenharmony_ci} 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciNAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 49