@@ -1155,8 +1155,11 @@ ExitCode SnapshotBuilder::CreateSnapshot(SnapshotData* out,
1155
1155
CHECK_EQ (index , SnapshotData::kNodeVMContextIndex );
1156
1156
index = creator->AddContext (base_context);
1157
1157
CHECK_EQ (index , SnapshotData::kNodeBaseContextIndex );
1158
- index = creator->AddContext (main_context,
1159
- {SerializeNodeContextInternalFields, env});
1158
+ index = creator->AddContext (
1159
+ main_context,
1160
+ v8::SerializeInternalFieldsCallback (SerializeNodeContextInternalFields,
1161
+ env),
1162
+ v8::SerializeContextDataCallback (SerializeNodeContextData, env));
1160
1163
CHECK_EQ (index , SnapshotData::kNodeMainContextIndex );
1161
1164
}
1162
1165
@@ -1255,6 +1258,17 @@ std::string SnapshotableObject::GetTypeName() const {
1255
1258
}
1256
1259
}
1257
1260
1261
+ void DeserializeNodeContextData (Local<Context> holder,
1262
+ int index,
1263
+ StartupData payload,
1264
+ void * callback_data) {
1265
+ DCHECK (index == ContextEmbedderIndex::kEnvironment ||
1266
+ index == ContextEmbedderIndex::kRealm ||
1267
+ index == ContextEmbedderIndex::kContextTag );
1268
+ // This is a no-op for now. We will reset all the pointers in
1269
+ // Environment::AssignToContext() via the realm constructor.
1270
+ }
1271
+
1258
1272
void DeserializeNodeInternalFields (Local<Object> holder,
1259
1273
int index,
1260
1274
StartupData payload,
@@ -1320,6 +1334,44 @@ void DeserializeNodeInternalFields(Local<Object> holder,
1320
1334
}
1321
1335
}
1322
1336
1337
+ StartupData SerializeNodeContextData (Local<Context> holder,
1338
+ int index,
1339
+ void * callback_data) {
1340
+ DCHECK (index == ContextEmbedderIndex::kEnvironment ||
1341
+ index == ContextEmbedderIndex::kContextifyContext ||
1342
+ index == ContextEmbedderIndex::kRealm ||
1343
+ index == ContextEmbedderIndex::kContextTag );
1344
+ void * data = holder->GetAlignedPointerFromEmbedderData (index );
1345
+ per_process::Debug (DebugCategory::MKSNAPSHOT,
1346
+ " Serialize context data, index=%d, holder=%p, ptr=%p\n " ,
1347
+ static_cast <int >(index ),
1348
+ *holder,
1349
+ data);
1350
+ // Serialization of contextify context is not yet supported.
1351
+ if (index == ContextEmbedderIndex::kContextifyContext ) {
1352
+ DCHECK_NULL (data);
1353
+ return {nullptr , 0 };
1354
+ }
1355
+
1356
+ // We need to use use new[] because V8 calls delete[] on the returned data.
1357
+ int size = sizeof (ContextEmbedderIndex);
1358
+ char * result = new char [size];
1359
+ ContextEmbedderIndex* index_data =
1360
+ reinterpret_cast <ContextEmbedderIndex*>(result);
1361
+ *index_data = static_cast <ContextEmbedderIndex>(index );
1362
+
1363
+ // For now we just reset all of them in Environment::AssignToContext()
1364
+ switch (index ) {
1365
+ case ContextEmbedderIndex::kEnvironment :
1366
+ case ContextEmbedderIndex::kContextifyContext :
1367
+ case ContextEmbedderIndex::kRealm :
1368
+ case ContextEmbedderIndex::kContextTag :
1369
+ return StartupData{result, size};
1370
+ default :
1371
+ UNREACHABLE ();
1372
+ }
1373
+ }
1374
+
1323
1375
StartupData SerializeNodeContextInternalFields (Local<Object> holder,
1324
1376
int index,
1325
1377
void * callback_data) {
0 commit comments