Skip to content

Commit

Permalink
src: avoid using v8 on Isolate termination
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Sep 16, 2022
1 parent 4e97ad7 commit 8bb7d25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ inline bool TickInfo::has_rejection_to_warn() const {
}

inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
if (UNLIKELY(!isolate->InContext())) return nullptr;
if (UNLIKELY(!isolate->InContext() ||
isolate->IsExecutionTerminating())) return nullptr;
v8::HandleScope handle_scope(isolate);
return GetCurrent(isolate->GetCurrentContext());
}
Expand Down
20 changes: 13 additions & 7 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ bool AsyncHooks::pop_async_context(double async_id) {
}

void AsyncHooks::clear_async_id_stack() {
Isolate* isolate = env()->isolate();
HandleScope handle_scope(isolate);
if (!js_execution_async_resources_.IsEmpty()) {
USE(PersistentToLocal::Strong(js_execution_async_resources_)
->Set(env()->context(),
env()->length_string(),
Integer::NewFromUnsigned(isolate, 0)));
if (env()->can_call_into_js()) {
Isolate* isolate = env()->isolate();
HandleScope handle_scope(isolate);
if (!js_execution_async_resources_.IsEmpty()) {
USE(PersistentToLocal::Strong(js_execution_async_resources_)
->Set(env()->context(),
env()->length_string(),
Integer::NewFromUnsigned(isolate, 0)));
}
}

native_execution_async_resources_.clear();
native_execution_async_resources_.shrink_to_fit();

Expand Down Expand Up @@ -1045,6 +1048,9 @@ void Environment::RunAndClearInterrupts() {
void Environment::RunAndClearNativeImmediates(bool only_refed) {
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment),
"RunAndClearNativeImmediates");
if (isolate_->IsExecutionTerminating())
return;

HandleScope handle_scope(isolate_);
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });

Expand Down

0 comments on commit 8bb7d25

Please sign in to comment.