src: improve fatal exception

This is just some code cleanup.

PR-URL: https://github.com/nodejs/node/pull/20294
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-04-25 17:50:43 +02:00 committed by Anna Henningsen
parent 2b8512738a
commit b87ef189e9
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -2374,39 +2374,30 @@ void FatalException(Isolate* isolate,
Local<Function> fatal_exception_function = Local<Function> fatal_exception_function =
process_object->Get(fatal_exception_string).As<Function>(); process_object->Get(fatal_exception_string).As<Function>();
int exit_code = 0;
if (!fatal_exception_function->IsFunction()) { if (!fatal_exception_function->IsFunction()) {
// failed before the process._fatalException function was added! // Failed before the process._fatalException function was added!
// this is probably pretty bad. Nothing to do but report and exit. // this is probably pretty bad. Nothing to do but report and exit.
ReportException(env, error, message); ReportException(env, error, message);
exit_code = 6; exit(6);
} } else {
if (exit_code == 0) {
TryCatch fatal_try_catch(isolate); TryCatch fatal_try_catch(isolate);
// Do not call FatalException when _fatalException handler throws // Do not call FatalException when _fatalException handler throws
fatal_try_catch.SetVerbose(false); fatal_try_catch.SetVerbose(false);
// this will return true if the JS layer handled it, false otherwise // This will return true if the JS layer handled it, false otherwise
Local<Value> caught = Local<Value> caught =
fatal_exception_function->Call(process_object, 1, &error); fatal_exception_function->Call(process_object, 1, &error);
if (fatal_try_catch.HasCaught()) { if (fatal_try_catch.HasCaught()) {
// the fatal exception function threw, so we must exit // The fatal exception function threw, so we must exit
ReportException(env, fatal_try_catch); ReportException(env, fatal_try_catch);
exit_code = 7; exit(7);
} } else if (caught->IsFalse()) {
if (exit_code == 0 && false == caught->BooleanValue()) {
ReportException(env, error, message); ReportException(env, error, message);
exit_code = 1; exit(1);
} }
} }
if (exit_code) {
exit(exit_code);
}
} }