node/test/addons-napi/test_fatal_exception/test_fatal_exception.c
Mathias Buus 29a04b7ed6
n-api: add napi_fatal_exception
Add function to trigger and uncaught exception.
Useful if an async callback throws an exception with
no way to recover.

PR-URL: https://github.com/nodejs/node/pull/19337
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-03-22 16:41:06 +00:00

27 lines
605 B
C

#include <node_api.h>
#include "../common.h"
napi_value Test(napi_env env, napi_callback_info info) {
napi_value err;
size_t argc = 1;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &err, NULL, NULL));
NAPI_CALL(env, napi_fatal_exception(env, err));
return NULL;
}
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("Test", Test),
};
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)