From e4e5137cbde9a558209ecdbd1c7fa9ab26ca375e Mon Sep 17 00:00:00 2001 From: Divyanshu Sharma <155464075+DivyanshuX9@users.noreply.github.com> Date: Sat, 30 May 2026 00:18:53 +0530 Subject: [PATCH] errors: handle V8 warnings in DisallowJavascriptExecutionScope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Defer non-critical warnings to the next event loop iteration when can_call_into_js() returns false. This prevents crashes when V8 emits warnings during REPL preview evaluation or other contexts where JavaScript execution is temporarily forbidden. When a warning is emitted inside DisallowJavascriptExecutionScope, ProcessEmitWarningGeneric cannot be called immediately. Instead, use env->SetImmediate() to queue the warning emission for after the scope exits. This preserves full warning formatting, deprecation codes, and --redirect-warnings routing. Signed-off-by: Divyanshu Sharma PR-URL: https://github.com/nodejs/node/pull/63491 Fixes: https://github.com/nodejs/node/issues/63473 Reviewed-By: René Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- src/node_errors.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index e5432453ac2..34fa4758bfa 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -1064,7 +1064,12 @@ void PerIsolateMessageListener(Local message, Local error) { filename, message->GetLineNumber(env->context()).FromMaybe(-1), msg); - USE(ProcessEmitWarningGeneric(env, warning, "V8")); + // Defer the warning to the next event loop iteration. This prevents + // crashes when V8 emits warnings during code evaluation with + // throwOnSideEffect. + env->SetImmediate([warning](Environment* env) { + ProcessEmitWarningGeneric(env, warning, "V8"); + }); break; } case Isolate::MessageErrorLevel::kMessageError: