-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: account for cwd access from snapshot serialization cb
Functions registered with `addSerializeCallback()` can access and call `process.cwd()`. b7d836e 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: #49684 PR-URL: #51901 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
- Loading branch information
1 parent
da8fa48
commit dcbf88f
Showing
3 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
const { | ||
addSerializeCallback, | ||
setDeserializeMainFunction, | ||
} = require('v8').startupSnapshot; | ||
|
||
// To make sure the cwd is present in the cache | ||
process.cwd(); | ||
|
||
// Also access it from a serialization callback once | ||
addSerializeCallback(() => { | ||
process.cwd(); | ||
}); | ||
|
||
setDeserializeMainFunction(() => { | ||
console.log(process.cwd()); | ||
}); |