File tree 3 files changed +26
-7
lines changed
3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -541,6 +541,19 @@ This API returns true if an exception is pending.
541
541
542
542
This API can be called even if there is a pending JavaScript exception.
543
543
544
+ #### napi_fatal_exception
545
+ <!-- YAML
546
+ added: TBA
547
+ -->
548
+ ```C
549
+ napi_fatal_exception(napi_env env);
550
+ ```
551
+
552
+ - `[in] env`: The environment that the API is invoked under.
553
+
554
+ Trigger an `uncaughtException` in JavaScript. Useful if an async
555
+ callback throws an exception with no way to recover.
556
+
544
557
### Fatal Errors
545
558
546
559
In the event of an unrecoverable error in a native module, a fatal error can be
Original file line number Diff line number Diff line change @@ -954,6 +954,16 @@ napi_status napi_get_last_error_info(napi_env env,
954
954
return napi_ok;
955
955
}
956
956
957
+ void napi_fatal_exception (napi_env env) {
958
+ if (!env->last_exception .IsEmpty ()) {
959
+ v8::Local<v8::Value> err = v8::Local<v8::Value>::New (
960
+ env->isolate , env->last_exception );
961
+ v8::Local<v8::Message> msg = v8::Exception::CreateMessage (
962
+ env->isolate , err);
963
+ node::FatalException (env->isolate , err, msg);
964
+ }
965
+ }
966
+
957
967
NAPI_NO_RETURN void napi_fatal_error (const char * location,
958
968
size_t location_len,
959
969
const char * message,
@@ -3353,13 +3363,7 @@ class Work : public node::AsyncResource {
3353
3363
// If there was an unhandled exception in the complete callback,
3354
3364
// report it as a fatal exception. (There is no JavaScript on the
3355
3365
// callstack that can possibly handle it.)
3356
- if (!env->last_exception .IsEmpty ()) {
3357
- v8::Local<v8::Value> err = v8::Local<v8::Value>::New (
3358
- env->isolate , env->last_exception );
3359
- v8::Local<v8::Message> msg = v8::Exception::CreateMessage (
3360
- env->isolate , err);
3361
- node::FatalException (env->isolate , err, msg);
3362
- }
3366
+ napi_fatal_exception (env);
3363
3367
}
3364
3368
}
3365
3369
Original file line number Diff line number Diff line change @@ -112,6 +112,8 @@ NAPI_EXTERN napi_status
112
112
napi_get_last_error_info (napi_env env ,
113
113
const napi_extended_error_info * * result );
114
114
115
+ NAPI_EXTERN void napi_fatal_exception (napi_env env );
116
+
115
117
NAPI_EXTERN NAPI_NO_RETURN void napi_fatal_error (const char * location ,
116
118
size_t location_len ,
117
119
const char * message ,
You can’t perform that action at this time.
0 commit comments