| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e66eb37 commit cb1329a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -458,7 +458,13 @@ Environment* CreateEnvironment( | |||
| 458 | 458 | if (use_snapshot) { | |
| 459 | 459 | context = Context::FromSnapshot(isolate, | |
| 460 | 460 | SnapshotData::kNodeMainContextIndex, | |
| 461 | - {DeserializeNodeInternalFields, env}) | ||
| 461 | + v8::DeserializeInternalFieldsCallback( | ||
| 462 | + DeserializeNodeInternalFields, env), | ||
| 463 | + nullptr, | ||
| 464 | + MaybeLocal<Value>(), | ||
| 465 | + nullptr, | ||
| 466 | + v8::DeserializeContextDataCallback( | ||
| 467 | + DeserializeNodeContextData, env)) | ||
| 462 | 468 | .ToLocalChecked(); | |
| 463 | 469 | ||
| 464 | 470 | CHECK(!context.IsEmpty()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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,41 @@ 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 | + // This is unreachable for now. We will reset all the pointers in | ||
| 1266 | + // Environment::AssignToContext() via the realm constructor. | ||
| 1267 | + UNREACHABLE(); | ||
| 1268 | + } | ||
| 1269 | + | ||
| 1270 | + StartupData SerializeNodeContextData(Local<Context> holder, | ||
| 1271 | + int index, | ||
| 1272 | + void* callback_data) { | ||
| 1273 | + // For now we just reset all of them in Environment::AssignToContext(). | ||
| 1274 | + // We return empty data here to make sure that the embedder data serialized | ||
| 1275 | + // into the snapshot is reproducible and V8 doesn't have to try to serialize | ||
| 1276 | + // the pointer values that won't be useful during deserialization. | ||
| 1277 | + switch (index) { | ||
| 1278 | + case ContextEmbedderIndex::kEnvironment: | ||
| 1279 | + case ContextEmbedderIndex::kContextifyContext: | ||
| 1280 | + case ContextEmbedderIndex::kRealm: | ||
| 1281 | + case ContextEmbedderIndex::kContextTag: { | ||
| 1282 | + void* data = holder->GetAlignedPointerFromEmbedderData(index); | ||
| 1283 | + per_process::Debug( | ||
| 1284 | + DebugCategory::MKSNAPSHOT, | ||
| 1285 | + "Serialize context data, index=%d, holder=%p, ptr=%p\n", | ||
| 1286 | + static_cast<int>(index), | ||
| 1287 | + *holder, | ||
| 1288 | + data); | ||
| 1289 | + return {nullptr, 0}; | ||
| 1290 | + } | ||
| 1291 | + default: | ||
| 1292 | + UNREACHABLE(); | ||
| 1293 | + } | ||
| 1294 | + } | ||
| 1295 | + | ||
| 1258 | 1296 | void DeserializeNodeInternalFields(Local<Object> holder, | |
| 1259 | 1297 | int index, | |
| 1260 | 1298 | StartupData payload, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,10 +126,17 @@ class SnapshotableObject : public BaseObject { | |||
| 126 | 126 | v8::StartupData SerializeNodeContextInternalFields(v8::Local<v8::Object> holder, | |
| 127 | 127 | int index, | |
| 128 | 128 | void* env); | |
| 129 | + v8::StartupData SerializeNodeContextData(v8::Local<v8::Context> holder, | ||
| 130 | + int index, | ||
| 131 | + void* env); | ||
| 129 | 132 | void DeserializeNodeInternalFields(v8::Local<v8::Object> holder, | |
| 130 | 133 | int index, | |
| 131 | 134 | v8::StartupData payload, | |
| 132 | 135 | void* env); | |
| 136 | + void DeserializeNodeContextData(v8::Local<v8::Context> holder, | ||
| 137 | + int index, | ||
| 138 | + v8::StartupData payload, | ||
| 139 | + void* env); | ||
| 133 | 140 | void SerializeSnapshotableObjects(Realm* realm, | |
| 134 | 141 | v8::SnapshotCreator* creator, | |
| 135 | 142 | RealmSerializeInfo* info); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments