Skip to content

Commit 94357db

Browse files
committed
src: add more can_call_into_js() guards
This is in preparation for running native `SetImmediate()` callbacks during shutdown. PR-URL: #30666 Fixes: #30643 Refs: #30374 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d54432f commit 94357db

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
@@ -278,6 +278,9 @@ static void ReportFatalException(Environment* env,
278278
Local<Value> error,
279279
Local<Message> message,
280280
EnhanceFatalException enhance_stack) {
281+
if (!env->can_call_into_js())
282+
enhance_stack = EnhanceFatalException::kDontEnhance;
283+
281284
Isolate* isolate = env->isolate();
282285
CHECK(!error.IsEmpty());
283286
CHECK(!message.IsEmpty());
@@ -956,7 +959,7 @@ void TriggerUncaughtException(Isolate* isolate,
956959
}
957960

958961
MaybeLocal<Value> handled;
959-
{
962+
if (env->can_call_into_js()) {
960963
// We do not expect the global uncaught exception itself to throw any more
961964
// exceptions. If it does, exit the current Node.js instance.
962965
errors::TryCatchScope try_catch(env,

src/node_process_events.cc

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

0 commit comments

Comments
 (0)