| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 774c1cf commit bbc7105
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const credentials = internalBinding('credentials'); | |
| 4 | 4 | const rawMethods = internalBinding('process_methods'); | |
| 5 | + const { | ||
| 6 | + namespace: { | ||
| 7 | + addSerializeCallback, | ||
| 8 | + isBuildingSnapshot, | ||
| 9 | + }, | ||
| 10 | + } = require('internal/v8/startup_snapshot'); | ||
| 5 | 11 | ||
| 6 | 12 | process.abort = rawMethods.abort; | |
| 7 | 13 | process.umask = wrappedUmask; | |
@@ -107,6 +113,12 @@ function wrapPosixCredentialSetters(credentials) { | |||
| 107 | 113 | // directory is changed by `chdir`, it'll be updated. | |
| 108 | 114 | let cachedCwd = ''; | |
| 109 | 115 | ||
| 116 | + if (isBuildingSnapshot()) { | ||
| 117 | + addSerializeCallback(() => { | ||
| 118 | + cachedCwd = ''; | ||
| 119 | + }); | ||
| 120 | + } | ||
| 121 | + | ||
| 110 | 122 | function wrappedChdir(directory) { | |
| 111 | 123 | validateString(directory, 'directory'); | |
| 112 | 124 | rawMethods.chdir(directory); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + const { | ||
| 2 | + setDeserializeMainFunction, | ||
| 3 | + } = require('v8').startupSnapshot; | ||
| 4 | + | ||
| 5 | + // To make sure the cwd is present in the cache | ||
| 6 | + process.cwd(); | ||
| 7 | + | ||
| 8 | + setDeserializeMainFunction(() => { | ||
| 9 | + console.log(process.cwd()); | ||
| 10 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,47 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests that process.cwd() is accurate when | ||
| 4 | + // restoring state from a snapshot | ||
| 5 | + | ||
| 6 | + require('../common'); | ||
| 7 | + const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
| 8 | + const tmpdir = require('../common/tmpdir'); | ||
| 9 | + const fixtures = require('../common/fixtures'); | ||
| 10 | + const fs = require('fs'); | ||
| 11 | + | ||
| 12 | + tmpdir.refresh(); | ||
| 13 | + const blobPath = tmpdir.resolve('snapshot.blob'); | ||
| 14 | + const file = fixtures.path('snapshot', 'cwd.js'); | ||
| 15 | + | ||
| 16 | + const subdir = tmpdir.resolve('foo'); | ||
| 17 | + fs.mkdirSync(subdir); | ||
| 18 | + | ||
| 19 | + { | ||
| 20 | + // Create the snapshot. | ||
| 21 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 22 | + '--snapshot-blob', | ||
| 23 | + blobPath, | ||
| 24 | + '--build-snapshot', | ||
| 25 | + file, | ||
| 26 | + ], { | ||
| 27 | + cwd: tmpdir.path, | ||
| 28 | + encoding: 'utf8' | ||
| 29 | + }, { | ||
| 30 | + status: 0, | ||
| 31 | + }); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + { | ||
| 35 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 36 | + '--snapshot-blob', | ||
| 37 | + blobPath, | ||
| 38 | + file, | ||
| 39 | + ], { | ||
| 40 | + cwd: subdir, | ||
| 41 | + encoding: 'utf8' | ||
| 42 | + }, { | ||
| 43 | + status: 0, | ||
| 44 | + trim: true, | ||
| 45 | + stdout: subdir, | ||
| 46 | + }); | ||
| 47 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments