| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 955454b commit bfc5236
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1262,18 +1262,30 @@ void DeserializeNodeContextData(Local<Context> holder, | |||
| 1262 | 1262 | int index, | |
| 1263 | 1263 | StartupData payload, | |
| 1264 | 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(); | ||
| 1265 | + // We will reset all the pointers in Environment::AssignToContext() | ||
| 1266 | + // via the realm constructor. | ||
| 1267 | + switch (index) { | ||
| 1268 | + case ContextEmbedderIndex::kEnvironment: | ||
| 1269 | + case ContextEmbedderIndex::kContextifyContext: | ||
| 1270 | + case ContextEmbedderIndex::kRealm: | ||
| 1271 | + case ContextEmbedderIndex::kContextTag: { | ||
| 1272 | + uint64_t index_64; | ||
| 1273 | + int size = sizeof(index_64); | ||
| 1274 | + CHECK_EQ(payload.raw_size, size); | ||
| 1275 | + memcpy(&index_64, payload.data, payload.raw_size); | ||
| 1276 | + CHECK_EQ(index_64, static_cast<uint64_t>(index)); | ||
| 1277 | + break; | ||
| 1278 | + } | ||
| 1279 | + default: | ||
| 1280 | + UNREACHABLE(); | ||
| 1281 | + } | ||
| 1268 | 1282 | } | |
| 1269 | 1283 | ||
| 1270 | 1284 | StartupData SerializeNodeContextData(Local<Context> holder, | |
| 1271 | 1285 | int index, | |
| 1272 | 1286 | 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. | ||
| 1287 | + // For pointer values, we need to return some non-empty data so that V8 | ||
| 1288 | + // does not serialize them verbatim, making the snapshot unreproducible. | ||
| 1277 | 1289 | switch (index) { | |
| 1278 | 1290 | case ContextEmbedderIndex::kEnvironment: | |
| 1279 | 1291 | case ContextEmbedderIndex::kContextifyContext: | |
@@ -1286,7 +1298,13 @@ StartupData SerializeNodeContextData(Local<Context> holder, | |||
| 1286 | 1298 | static_cast<int>(index), | |
| 1287 | 1299 | *holder, | |
| 1288 | 1300 | data); | |
| 1289 | - return {nullptr, 0}; | ||
| 1301 | + // We use uint64_t to avoid padding. | ||
| 1302 | + uint64_t index_64 = static_cast<uint64_t>(index); | ||
| 1303 | + // It must be allocated with new[] because V8 will call delete[] on it. | ||
| 1304 | + size_t size = sizeof(index_64); | ||
| 1305 | + char* startup_data = new char[size]; | ||
| 1306 | + memcpy(startup_data, &index_64, size); | ||
| 1307 | + return {startup_data, static_cast<int>(size)}; | ||
| 1290 | 1308 | } | |
| 1291 | 1309 | default: | |
| 1292 | 1310 | UNREACHABLE(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments