src: add more can_call_into_js() guards

This is in preparation for running native `SetImmediate()`
callbacks during shutdown.

Backport-PR-URL: https://github.com/nodejs/node/pull/32301
PR-URL: https://github.com/nodejs/node/pull/30666
Fixes: https://github.com/nodejs/node/issues/30643
Refs: https://github.com/nodejs/node/pull/30374
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen authored and Myles Borins committed 2020-04-01 17:36:48 -04:00
1 parent 7647bfe3fc
commit 51230f71ff
3 files changed
+10 -2

No files matched your search

+4 -1
View File
@@ -540,6 +540,9 @@ void Environment::RegisterHandleCleanups() {
}
void Environment::CleanupHandles() {
Isolate::DisallowJavascriptExecutionScope disallow_js(isolate(),
Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
for (ReqWrapBase* request : req_wrap_queue_)
request->Cancel();
@@ -674,7 +677,7 @@ void Environment::RunAndClearNativeImmediates() {
head->Call(this);
if (UNLIKELY(try_catch.HasCaught())) {
if (!try_catch.HasTerminated())
if (!try_catch.HasTerminated() && can_call_into_js())
errors::TriggerUncaughtException(isolate(), try_catch);
// We are done with the current callback. Move one iteration along,
+4 -1
View File
@@ -270,6 +270,9 @@ static void ReportFatalException(Environment* env,
Local<Value> error,
Local<Message> message,
EnhanceFatalException enhance_stack) {
if (!env->can_call_into_js())
enhance_stack = EnhanceFatalException::kDontEnhance;
Isolate* isolate = env->isolate();
CHECK(!error.IsEmpty());
CHECK(!message.IsEmpty());
@@ -914,7 +917,7 @@ void TriggerUncaughtException(Isolate* isolate,
}
MaybeLocal<Value> handled;
{
if (env->can_call_into_js()) {
// We do not expect the global uncaught exception itself to throw any more
// exceptions. If it does, exit the current Node.js instance.
errors::TryCatchScope try_catch(env,
+2
View File
@@ -35,6 +35,8 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
const char* warning,
const char* type,
const char* code) {
if (!env->can_call_into_js()) return Just(false);
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());