Skip to content

Commit

Permalink
src: improve fatal exception
Browse files Browse the repository at this point in the history
This is just some code cleanup.

PR-URL: #20294
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 4, 2018
1 parent 2ce4b7c commit e0d2bc5
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2388,39 +2388,30 @@ void FatalException(Isolate* isolate,
Local<Function> fatal_exception_function =
process_object->Get(fatal_exception_string).As<Function>();

int exit_code = 0;
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.
ReportException(env, error, message);
exit_code = 6;
}

if (exit_code == 0) {
exit(6);
} else {
TryCatch fatal_try_catch(isolate);

// Do not call FatalException when _fatalException handler throws
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 =
fatal_exception_function->Call(process_object, 1, &error);

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);
exit_code = 7;
}

if (exit_code == 0 && false == caught->BooleanValue()) {
exit(7);
} else if (caught->IsFalse()) {
ReportException(env, error, message);
exit_code = 1;
exit(1);
}
}

if (exit_code) {
exit(exit_code);
}
}


Expand Down

0 comments on commit e0d2bc5

Please sign in to comment.