@@ -1096,20 +1096,29 @@ void AsyncHooks::Deserialize(Local<Context> context) {
1096
1096
async_ids_stack_.Deserialize (context);
1097
1097
fields_.Deserialize (context);
1098
1098
async_id_fields_.Deserialize (context);
1099
+
1100
+ Local<Array> js_execution_async_resources;
1099
1101
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 ());
1104
1107
}
1108
+ js_execution_async_resources_.Reset (
1109
+ context->GetIsolate (), js_execution_async_resources);
1105
1110
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.
1108
1115
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 ;
1109
1118
Local<Object> obj = context->GetDataFromSnapshotOnce <Object>(
1110
1119
info_->native_execution_async_resources [i])
1111
1120
.ToLocalChecked ();
1112
- native_execution_async_resources_[i]. Reset (context-> GetIsolate (), obj);
1121
+ js_execution_async_resources-> Set (context, i, obj). Check ( );
1113
1122
}
1114
1123
info_ = nullptr ;
1115
1124
}
@@ -1155,9 +1164,11 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
1155
1164
info.native_execution_async_resources .resize (
1156
1165
native_execution_async_resources_.size ());
1157
1166
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]);
1161
1172
}
1162
1173
CHECK_EQ (contexts_.size (), 1 );
1163
1174
CHECK_EQ (contexts_[0 ], env ()->context ());
0 commit comments