Skip to content

Commit 0897504

Browse files
committed
src: call Environment::Exit() for fatal exceptions
Call `Environment::Exit()` rather than the process-wide `exit()` function, since JS exceptions generally only affect the current JS engine instance. PR-URL: #25472 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 7ffa8ec commit 0897504

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/node_errors.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ TryCatchScope::~TryCatchScope() {
324324
if (HasCaught() && !HasTerminated() && mode_ == CatchMode::kFatal) {
325325
HandleScope scope(env_->isolate());
326326
ReportException(env_, Exception(), Message());
327-
exit(7);
327+
env_->Exit(7);
328328
}
329329
}
330330

@@ -711,7 +711,7 @@ void FatalException(Isolate* isolate,
711711
// Failed before the process._fatalException function was added!
712712
// this is probably pretty bad. Nothing to do but report and exit.
713713
ReportException(env, error, message);
714-
exit(6);
714+
env->Exit(6);
715715
} else {
716716
errors::TryCatchScope fatal_try_catch(env);
717717

@@ -727,7 +727,7 @@ void FatalException(Isolate* isolate,
727727
if (fatal_try_catch.HasCaught()) {
728728
// The fatal exception function threw, so we must exit
729729
ReportException(env, fatal_try_catch);
730-
exit(7);
730+
env->Exit(7);
731731

732732
} else if (caught.ToLocalChecked()->IsFalse()) {
733733
ReportException(env, error, message);
@@ -738,9 +738,9 @@ void FatalException(Isolate* isolate,
738738
Local<Value> code;
739739
if (!process_object->Get(env->context(), exit_code).ToLocal(&code) ||
740740
!code->IsInt32()) {
741-
exit(1);
741+
env->Exit(1);
742742
}
743-
exit(code.As<Int32>()->Value());
743+
env->Exit(code.As<Int32>()->Value());
744744
}
745745
}
746746
}

0 commit comments

Comments
 (0)