From af32d433eed7f99d0ad8b657850a9dec6e9f681d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 29 Feb 2024 21:55:00 +0100 Subject: [PATCH] lib: account for cwd access from snapshot serialization cb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/51901 Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso Reviewed-By: Marco Ippolito --- 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])`