Skip to content
Prev Previous commit
Next Next commit
leverage addSerializeCallback
  • Loading branch information
arcanis committed Sep 18, 2023
commit 851b29a2549fdd22af98a35496ee2cbe449fd49b
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ process.abort = unavailable('process.abort()');
process.chdir = unavailable('process.chdir()');
process.umask = wrappedUmask;
process.cwd = rawMethods.cwd;
process.cwd.resetCwdCache = () => {};

if (credentials.implementsPosixCredentials) {
process.initgroups = unavailable('process.initgroups()');
Expand Down
13 changes: 10 additions & 3 deletions lib/internal/bootstrap/switches/does_own_process_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

const credentials = internalBinding('credentials');
const rawMethods = internalBinding('process_methods');
const {
namespace: {
addSerializeCallback,
isBuildingSnapshot,
},
} = require('internal/v8/startup_snapshot');

process.abort = rawMethods.abort;
process.umask = wrappedUmask;
process.chdir = wrappedChdir;
process.cwd = wrappedCwd;
process.cwd.resetCwdCache = resetCwdCache;

if (credentials.implementsPosixCredentials) {
const wrapped = wrapPosixCredentialSetters(credentials);
Expand Down Expand Up @@ -108,8 +113,10 @@ function wrapPosixCredentialSetters(credentials) {
// directory is changed by `chdir`, it'll be updated.
let cachedCwd = '';

function resetCwdCache() {
cachedCwd = '';
if (isBuildingSnapshot()) {
addSerializeCallback(() => {
cachedCwd = '';
});
}

function wrappedChdir(directory) {
Expand Down
1 change: 0 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ function patchProcessObject(expandArgv1) {
process.exitCode = undefined;
process._exiting = false;
process.argv[0] = process.execPath;
process.cwd.resetCwdCache();

if (expandArgv1 && process.argv[1] &&
!StringPrototypeStartsWith(process.argv[1], '-')) {
Expand Down