@@ -640,7 +640,7 @@ template <>
640
640
EnvSerializeInfo FileReader::Read () {
641
641
per_process::Debug (DebugCategory::MKSNAPSHOT, " Read<EnvSerializeInfo>()\n " );
642
642
EnvSerializeInfo result;
643
- result.bindings = ReadVector<PropInfo>();
643
+ result.native_objects = ReadVector<PropInfo>();
644
644
result.builtins = ReadVector<std::string>();
645
645
result.async_hooks = Read<AsyncHooks::SerializeInfo>();
646
646
result.tick_info = Read<TickInfo::SerializeInfo>();
@@ -663,7 +663,7 @@ size_t FileWriter::Write(const EnvSerializeInfo& data) {
663
663
}
664
664
665
665
// Use += here to ensure order of evaluation.
666
- size_t written_total = WriteVector<PropInfo>(data.bindings );
666
+ size_t written_total = WriteVector<PropInfo>(data.native_objects );
667
667
written_total += WriteVector<std::string>(data.builtins );
668
668
written_total += Write<AsyncHooks::SerializeInfo>(data.async_hooks );
669
669
written_total += Write<TickInfo::SerializeInfo>(data.tick_info );
@@ -1209,17 +1209,6 @@ const char* SnapshotableObject::GetTypeNameChars() const {
1209
1209
}
1210
1210
}
1211
1211
1212
- bool IsSnapshotableType (FastStringKey key) {
1213
- #define V (PropertyName, NativeTypeName ) \
1214
- if (key == NativeTypeName::type_name) { \
1215
- return true ; \
1216
- }
1217
- SERIALIZABLE_OBJECT_TYPES (V)
1218
- #undef V
1219
-
1220
- return false ;
1221
- }
1222
-
1223
1212
void DeserializeNodeInternalFields (Local<Object> holder,
1224
1213
int index,
1225
1214
StartupData payload,
@@ -1242,10 +1231,10 @@ void DeserializeNodeInternalFields(Local<Object> holder,
1242
1231
DCHECK_EQ (index , BaseObject::kEmbedderType );
1243
1232
1244
1233
Environment* env_ptr = static_cast <Environment*>(env);
1245
- const InternalFieldInfo * info =
1246
- reinterpret_cast <const InternalFieldInfo *>(payload.data );
1234
+ const InternalFieldInfoBase * info =
1235
+ reinterpret_cast <const InternalFieldInfoBase *>(payload.data );
1247
1236
// TODO(joyeecheung): we can add a constant kNodeEmbedderId to the
1248
- // beginning of every InternalFieldInfo to ensure that we don't
1237
+ // beginning of every InternalFieldInfoBase to ensure that we don't
1249
1238
// step on payloads that were not serialized by Node.js.
1250
1239
switch (info->type ) {
1251
1240
#define V (PropertyName, NativeTypeName ) \
@@ -1255,12 +1244,25 @@ void DeserializeNodeInternalFields(Local<Object> holder,
1255
1244
(*holder), \
1256
1245
NativeTypeName::type_name.c_str ()); \
1257
1246
env_ptr->EnqueueDeserializeRequest ( \
1258
- NativeTypeName::Deserialize, holder, index , info->Copy ()); \
1247
+ NativeTypeName::Deserialize, \
1248
+ holder, \
1249
+ index , \
1250
+ info->Copy <NativeTypeName::InternalFieldInfo>()); \
1259
1251
break ; \
1260
1252
}
1261
1253
SERIALIZABLE_OBJECT_TYPES (V)
1262
1254
#undef V
1263
- default : { UNREACHABLE (); }
1255
+ default : {
1256
+ // This should only be reachable during development when trying to
1257
+ // deserialize a snapshot blob built by a version of Node.js that
1258
+ // has more recognizable EmbedderObjectTypes than the deserializing
1259
+ // Node.js binary.
1260
+ fprintf (stderr,
1261
+ " Unknown embedder object type %" PRIu8 " , possibly caused by "
1262
+ " mismatched Node.js versions\n " ,
1263
+ static_cast <uint8_t >(info->type ));
1264
+ ABORT ();
1265
+ }
1264
1266
}
1265
1267
}
1266
1268
@@ -1293,17 +1295,17 @@ StartupData SerializeNodeContextInternalFields(Local<Object> holder,
1293
1295
static_cast <int >(index ),
1294
1296
*holder);
1295
1297
1296
- void * binding_ptr =
1298
+ void * native_ptr =
1297
1299
holder->GetAlignedPointerFromInternalField (BaseObject::kSlot );
1298
- per_process::Debug (DebugCategory::MKSNAPSHOT, " binding = %p\n " , binding_ptr );
1299
- DCHECK (static_cast <BaseObject*>(binding_ptr )->is_snapshotable ());
1300
- SnapshotableObject* obj = static_cast <SnapshotableObject*>(binding_ptr );
1300
+ per_process::Debug (DebugCategory::MKSNAPSHOT, " native = %p\n " , native_ptr );
1301
+ DCHECK (static_cast <BaseObject*>(native_ptr )->is_snapshotable ());
1302
+ SnapshotableObject* obj = static_cast <SnapshotableObject*>(native_ptr );
1301
1303
1302
1304
per_process::Debug (DebugCategory::MKSNAPSHOT,
1303
1305
" Object %p is %s, " ,
1304
1306
*holder,
1305
1307
obj->GetTypeNameChars ());
1306
- InternalFieldInfo * info = obj->Serialize (index );
1308
+ InternalFieldInfoBase * info = obj->Serialize (index );
1307
1309
1308
1310
per_process::Debug (DebugCategory::MKSNAPSHOT,
1309
1311
" payload size=%d\n " ,
@@ -1312,31 +1314,35 @@ StartupData SerializeNodeContextInternalFields(Local<Object> holder,
1312
1314
static_cast <int >(info->length )};
1313
1315
}
1314
1316
1315
- void SerializeBindingData (Environment* env,
1316
- SnapshotCreator* creator,
1317
- EnvSerializeInfo* info) {
1317
+ void SerializeSnapshotableObjects (Environment* env,
1318
+ SnapshotCreator* creator,
1319
+ EnvSerializeInfo* info) {
1318
1320
uint32_t i = 0 ;
1319
- env->ForEachBindingData ([&](FastStringKey key,
1320
- BaseObjectPtr<BaseObject> binding) {
1321
+ env->ForEachBaseObject ([&](BaseObject* obj) {
1322
+ // If there are any BaseObjects that are not snapshotable left
1323
+ // during context serialization, V8 would crash due to unregistered
1324
+ // global handles and print detailed information about them.
1325
+ if (!obj->is_snapshotable ()) {
1326
+ return ;
1327
+ }
1328
+ SnapshotableObject* ptr = static_cast <SnapshotableObject*>(obj);
1329
+
1330
+ const char * type_name = ptr->GetTypeNameChars ();
1321
1331
per_process::Debug (DebugCategory::MKSNAPSHOT,
1322
- " Serialize binding %i (%p), object=%p, type=%s\n " ,
1332
+ " Serialize snapshotable object %i (%p), "
1333
+ " object=%p, type=%s\n " ,
1323
1334
static_cast <int >(i),
1324
- binding. get () ,
1325
- *(binding ->object ()),
1326
- key. c_str () );
1335
+ ptr ,
1336
+ *(ptr ->object ()),
1337
+ type_name );
1327
1338
1328
- if (IsSnapshotableType (key )) {
1329
- SnapshotIndex index = creator->AddData (env->context (), binding ->object ());
1339
+ if (ptr-> PrepareForSerialization (env-> context (), creator )) {
1340
+ SnapshotIndex index = creator->AddData (env->context (), obj ->object ());
1330
1341
per_process::Debug (DebugCategory::MKSNAPSHOT,
1331
1342
" Serialized with index=%d\n " ,
1332
1343
static_cast <int >(index ));
1333
- info->bindings .push_back ({key.c_str (), i, index });
1334
- SnapshotableObject* ptr = static_cast <SnapshotableObject*>(binding.get ());
1335
- ptr->PrepareForSerialization (env->context (), creator);
1336
- } else {
1337
- UNREACHABLE ();
1344
+ info->native_objects .push_back ({type_name, i, index });
1338
1345
}
1339
-
1340
1346
i++;
1341
1347
});
1342
1348
}
0 commit comments