Skip to content

Commit 8bb7d25

Browse files
committed
src: avoid using v8 on Isolate termination
1 parent 4e97ad7 commit 8bb7d25

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/env-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ inline bool TickInfo::has_rejection_to_warn() const {
172172
}
173173

174174
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
175-
if (UNLIKELY(!isolate->InContext())) return nullptr;
175+
if (UNLIKELY(!isolate->InContext() ||
176+
isolate->IsExecutionTerminating())) return nullptr;
176177
v8::HandleScope handle_scope(isolate);
177178
return GetCurrent(isolate->GetCurrentContext());
178179
}

src/env.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,17 @@ bool AsyncHooks::pop_async_context(double async_id) {
163163
}
164164

165165
void AsyncHooks::clear_async_id_stack() {
166-
Isolate* isolate = env()->isolate();
167-
HandleScope handle_scope(isolate);
168-
if (!js_execution_async_resources_.IsEmpty()) {
169-
USE(PersistentToLocal::Strong(js_execution_async_resources_)
170-
->Set(env()->context(),
171-
env()->length_string(),
172-
Integer::NewFromUnsigned(isolate, 0)));
166+
if (env()->can_call_into_js()) {
167+
Isolate* isolate = env()->isolate();
168+
HandleScope handle_scope(isolate);
169+
if (!js_execution_async_resources_.IsEmpty()) {
170+
USE(PersistentToLocal::Strong(js_execution_async_resources_)
171+
->Set(env()->context(),
172+
env()->length_string(),
173+
Integer::NewFromUnsigned(isolate, 0)));
174+
}
173175
}
176+
174177
native_execution_async_resources_.clear();
175178
native_execution_async_resources_.shrink_to_fit();
176179

@@ -1045,6 +1048,9 @@ void Environment::RunAndClearInterrupts() {
10451048
void Environment::RunAndClearNativeImmediates(bool only_refed) {
10461049
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment),
10471050
"RunAndClearNativeImmediates");
1051+
if (isolate_->IsExecutionTerminating())
1052+
return;
1053+
10481054
HandleScope handle_scope(isolate_);
10491055
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });
10501056

0 commit comments

Comments
 (0)