@@ -162,14 +162,17 @@ bool AsyncHooks::pop_async_context(double async_id) {
162
162
}
163
163
164
164
void AsyncHooks::clear_async_id_stack () {
165
- Isolate* isolate = env ()->isolate ();
166
- HandleScope handle_scope (isolate);
167
- if (!js_execution_async_resources_.IsEmpty ()) {
168
- USE (PersistentToLocal::Strong (js_execution_async_resources_)
169
- ->Set (env ()->context (),
170
- env ()->length_string (),
171
- Integer::NewFromUnsigned (isolate, 0 )));
165
+ if (env ()->can_call_into_js ()) {
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 )));
173
+ }
172
174
}
175
+
173
176
native_execution_async_resources_.clear ();
174
177
native_execution_async_resources_.shrink_to_fit ();
175
178
@@ -1157,7 +1160,13 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
1157
1160
TRACE_EVENT0 (TRACING_CATEGORY_NODE1 (environment),
1158
1161
" RunAndClearNativeImmediates" );
1159
1162
HandleScope handle_scope (isolate_);
1160
- InternalCallbackScope cb_scope (this , Object::New (isolate_), { 0 , 0 });
1163
+ // In case the Isolate is no longer accessible just use an empty Local. This
1164
+ // is not an issue for InternalCallbackScope as this case is already handled
1165
+ // in its constructor but we avoid calls into v8 which can crash the process
1166
+ // in debug builds.
1167
+ Local<Object> obj =
1168
+ can_call_into_js () ? Object::New (isolate_) : Local<Object>();
1169
+ InternalCallbackScope cb_scope (this , obj, {0 , 0 });
1161
1170
1162
1171
size_t ref_count = 0 ;
1163
1172
0 commit comments