@@ -68,10 +68,7 @@ inline AsyncHooks::AsyncHooks()
6868 : async_ids_stack_(env()->isolate(), 16 * 2),
6969 fields_(env()->isolate(), kFieldsCount),
7070 async_id_fields_(env()->isolate(), kUidFieldsCount) {
71- v8::Isolate* isolate = env ()->isolate ();
72- v8::HandleScope handle_scope (isolate);
73-
74- execution_async_resources_.Reset (isolate, v8::Array::New (isolate));
71+ clear_async_id_stack ();
7572
7673 // Always perform async_hooks checks, not just when async_hooks is enabled.
7774 // TODO(AndreasMadsen): Consider removing this for LTS releases.
@@ -117,7 +114,7 @@ inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
117114}
118115
119116inline v8::Local<v8::Array> AsyncHooks::execution_async_resources () {
120- return execution_async_resources_. Get ( env ()-> isolate () );
117+ return PersistentToLocal::Strong (execution_async_resources_ );
121118}
122119
123120inline v8::Local<v8::String> AsyncHooks::provider_string (int idx) {
@@ -155,7 +152,7 @@ inline void AsyncHooks::push_async_context(double async_id,
155152 async_id_fields_[kTriggerAsyncId ] = trigger_async_id;
156153
157154 auto resources = execution_async_resources ();
158- resources->Set (env ()->context (), offset, resource). Check ( );
155+ USE ( resources->Set (env ()->context (), offset, resource));
159156}
160157
161158// Remember to keep this code aligned with popAsyncContext() in JS.
@@ -189,14 +186,15 @@ inline bool AsyncHooks::pop_async_context(double async_id) {
189186 fields_[kStackLength ] = offset;
190187
191188 auto resources = execution_async_resources ();
192- resources->Delete (env ()->context (), offset). FromJust ( );
189+ USE ( resources->Delete (env ()->context (), offset));
193190
194191 return fields_[kStackLength ] > 0 ;
195192}
196193
197194// Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js.
198195inline void AsyncHooks::clear_async_id_stack () {
199196 auto isolate = env ()->isolate ();
197+ v8::HandleScope handle_scope (isolate);
200198 execution_async_resources_.Reset (isolate, v8::Array::New (isolate));
201199
202200 async_id_fields_[kExecutionAsyncId ] = 0 ;
0 commit comments