@@ -163,14 +163,17 @@ bool AsyncHooks::pop_async_context(double async_id) {
163
163
}
164
164
165
165
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
+ }
173
175
}
176
+
174
177
native_execution_async_resources_.clear ();
175
178
native_execution_async_resources_.shrink_to_fit ();
176
179
@@ -1068,7 +1071,13 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
1068
1071
TRACE_EVENT0 (TRACING_CATEGORY_NODE1 (environment),
1069
1072
" RunAndClearNativeImmediates" );
1070
1073
HandleScope handle_scope (isolate_);
1071
- InternalCallbackScope cb_scope (this , Object::New (isolate_), { 0 , 0 });
1074
+ // In case the Isolate is no longer accessible just use an empty Local. This
1075
+ // is not an issue for InternalCallbackScope as this case is already handled
1076
+ // in its constructor but we avoid calls into v8 which can crash the process
1077
+ // in debug builds.
1078
+ Local<Object> obj =
1079
+ can_call_into_js () ? Object::New (isolate_) : Local<Object>();
1080
+ InternalCallbackScope cb_scope (this , obj, {0 , 0 });
1072
1081
1073
1082
size_t ref_count = 0 ;
1074
1083
0 commit comments