Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: add more can_call_into_js() guards
This is in preparation for running native `SetImmediate()`
callbacks during shutdown.
  • Loading branch information
addaleax committed Nov 26, 2019
commit 9d455b9a71562b5db528adb20fa0aa44b303832f
5 changes: 4 additions & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,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();

Expand Down Expand Up @@ -661,7 +664,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,
Expand Down
5 changes: 4 additions & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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());
Expand Down Expand Up @@ -956,7 +959,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,
Expand Down
2 changes: 2 additions & 0 deletions src/node_process_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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());

Expand Down