@@ -1096,20 +1096,29 @@ void AsyncHooks::Deserialize(Local<Context> context) {
10961096 async_ids_stack_.Deserialize (context);
10971097 fields_.Deserialize (context);
10981098 async_id_fields_.Deserialize (context);
1099+
1100+ Local<Array> js_execution_async_resources;
10991101 if (info_->js_execution_async_resources != 0 ) {
1100- Local<Array> arr = context->GetDataFromSnapshotOnce <Array>(
1101- info_->js_execution_async_resources )
1102- .ToLocalChecked ();
1103- js_execution_async_resources_.Reset (context->GetIsolate (), arr);
1102+ js_execution_async_resources =
1103+ context->GetDataFromSnapshotOnce <Array>(
1104+ info_->js_execution_async_resources ).ToLocalChecked ();
1105+ } else {
1106+ js_execution_async_resources = Array::New (context->GetIsolate ());
11041107 }
1108+ js_execution_async_resources_.Reset (
1109+ context->GetIsolate (), js_execution_async_resources);
11051110
1106- native_execution_async_resources_.resize (
1107- info_->native_execution_async_resources .size ());
1111+ // The native_execution_async_resources_ field requires v8::Local<> instances
1112+ // for async calls whose resources were on the stack as JS objects when they
1113+ // were entered. We cannot recreate this here; however, storing these values
1114+ // on the JS equivalent gives the same result, so we do that instead.
11081115 for (size_t i = 0 ; i < info_->native_execution_async_resources .size (); ++i) {
1116+ if (info_->native_execution_async_resources [i] == SIZE_MAX)
1117+ continue ;
11091118 Local<Object> obj = context->GetDataFromSnapshotOnce <Object>(
11101119 info_->native_execution_async_resources [i])
11111120 .ToLocalChecked ();
1112- native_execution_async_resources_[i]. Reset (context-> GetIsolate (), obj);
1121+ js_execution_async_resources-> Set (context, i, obj). Check ( );
11131122 }
11141123 info_ = nullptr ;
11151124}
@@ -1155,9 +1164,11 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
11551164 info.native_execution_async_resources .resize (
11561165 native_execution_async_resources_.size ());
11571166 for (size_t i = 0 ; i < native_execution_async_resources_.size (); i++) {
1158- info.native_execution_async_resources [i] = creator->AddData (
1159- context,
1160- native_execution_async_resources_[i].Get (context->GetIsolate ()));
1167+ info.native_execution_async_resources [i] =
1168+ native_execution_async_resources_[i].IsEmpty () ? SIZE_MAX :
1169+ creator->AddData (
1170+ context,
1171+ native_execution_async_resources_[i]);
11611172 }
11621173 CHECK_EQ (contexts_.size (), 1 );
11631174 CHECK_EQ (contexts_[0 ], env ()->context ());
0 commit comments