From b9195b6e47752322bc716bf4fba2177b3989a1d8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 27 Feb 2024 21:45:14 +0100 Subject: [PATCH] lib: account for cwd access from snapshot serialization cb Functions registered with `addSerializeCallback()` can access and call `process.cwd()`. b7d836e2c7f57 accounted for the fact that it is necessary to reset the cwd cache after the snapshot builder script has run, but did not account for possible accesses from serialization callbacks. To properly account for these, add a deserialization callback as well. As a related drive-by fix, also mention the execution order of callbacks in the documentation. Refs: https://github.com/nodejs/node/pull/49684 --- doc/api/v8.md | 4 ++++ lib/internal/bootstrap/switches/does_own_process_state.js | 6 ++++++ test/fixtures/snapshot/cwd.js | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/doc/api/v8.md b/doc/api/v8.md index 399cb1e82adf12..61ccbd8b9aa0f1 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -1021,6 +1021,8 @@ get serialized into a snapshot and exit. This can be used to release resources that should not or cannot be serialized or to convert user data into a form more suitable for serialization. +Callbacks are run in the order in which they are added. + ### `v8.startupSnapshot.addDeserializeCallback(callback[, data])`