File: test_fatal.c

package info (click to toggle)
nodejs 22.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 246,928 kB
  • sloc: cpp: 1,582,349; javascript: 582,017; ansic: 82,400; python: 60,561; sh: 4,009; makefile: 2,263; asm: 1,732; pascal: 1,565; perl: 248; lisp: 222; xml: 42
file content (48 lines) | stat: -rw-r--r-- 1,592 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// For the purpose of this test we use libuv's threading library. When deciding
// on a threading library for a new project it bears remembering that in the
// future libuv may introduce API changes which may render it non-ABI-stable,
// which, in turn, may affect the ABI stability of the project despite its use
// of N-API.
#include <uv.h>
#include <node_api.h>
#include "../../js-native-api/common.h"

static uv_thread_t uv_thread;

static void work_thread(void* data) {
  napi_fatal_error("work_thread", NAPI_AUTO_LENGTH,
      "foobar", NAPI_AUTO_LENGTH);
}

static napi_value Test(napi_env env, napi_callback_info info) {
  napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH,
                   "fatal message", NAPI_AUTO_LENGTH);
  return NULL;
}

static napi_value TestThread(napi_env env, napi_callback_info info) {
  NODE_API_ASSERT(env,
      (uv_thread_create(&uv_thread, work_thread, NULL) == 0),
      "Thread creation");
  return NULL;
}

static napi_value TestStringLength(napi_env env, napi_callback_info info) {
  napi_fatal_error("test_fatal::TestStringLength", 16, "fatal message", 13);
  return NULL;
}

static napi_value Init(napi_env env, napi_value exports) {
  napi_property_descriptor properties[] = {
    DECLARE_NODE_API_PROPERTY("Test", Test),
    DECLARE_NODE_API_PROPERTY("TestStringLength", TestStringLength),
    DECLARE_NODE_API_PROPERTY("TestThread", TestThread),
  };

  NODE_API_CALL(env, napi_define_properties(
      env, exports, sizeof(properties) / sizeof(*properties), properties));

  return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)