Skip to content

Commit 51230f7

Browse files
addaleaxMylesBorins
authored andcommitted
src: add more can_call_into_js() guards
This is in preparation for running native `SetImmediate()` callbacks during shutdown. Backport-PR-URL: #32301 PR-URL: #30666 Fixes: #30643 Refs: #30374 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7647bfe commit 51230f7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/env.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ void Environment::RegisterHandleCleanups() {
540540
}
541541

542542
void Environment::CleanupHandles() {
543+
Isolate::DisallowJavascriptExecutionScope disallow_js(isolate(),
544+
Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
545+
543546
for (ReqWrapBase* request : req_wrap_queue_)
544547
request->Cancel();
545548

@@ -674,7 +677,7 @@ void Environment::RunAndClearNativeImmediates() {
674677

675678
head->Call(this);
676679
if (UNLIKELY(try_catch.HasCaught())) {
677-
if (!try_catch.HasTerminated())
680+
if (!try_catch.HasTerminated() && can_call_into_js())
678681
errors::TriggerUncaughtException(isolate(), try_catch);
679682

680683
// We are done with the current callback. Move one iteration along,

src/node_errors.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ static void ReportFatalException(Environment* env,
270270
Local<Value> error,
271271
Local<Message> message,
272272
EnhanceFatalException enhance_stack) {
273+
if (!env->can_call_into_js())
274+
enhance_stack = EnhanceFatalException::kDontEnhance;
275+
273276
Isolate* isolate = env->isolate();
274277
CHECK(!error.IsEmpty());
275278
CHECK(!message.IsEmpty());
@@ -914,7 +917,7 @@ void TriggerUncaughtException(Isolate* isolate,
914917
}
915918

916919
MaybeLocal<Value> handled;
917-
{
920+
if (env->can_call_into_js()) {
918921
// We do not expect the global uncaught exception itself to throw any more
919922
// exceptions. If it does, exit the current Node.js instance.
920923
errors::TryCatchScope try_catch(env,

src/node_process_events.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
3535
const char* warning,
3636
const char* type,
3737
const char* code) {
38+
if (!env->can_call_into_js()) return Just(false);
39+
3840
HandleScope handle_scope(env->isolate());
3941
Context::Scope context_scope(env->context());
4042

0 commit comments

Comments
 (0)