Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf32d43

Browse files
addaleaxmarco-ippolito
authored andcommitted
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 isnecessary to reset the cwd cache after the snapshot builder script hasrun, but did not account for possible accesses from serializationcallbacks. To properly account for these, add a deserializationcallback as well.As a related drive-by fix, also mention the execution order ofcallbacks in the documentation.Refs:#49684PR-URL:#51901Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>Reviewed-By: Michaël Zasso <targos@protonmail.com>Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent1edbc7d commitaf32d43

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

‎doc/api/v8.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ get serialized into a snapshot and exit. This can be used to release
10211021
resources that should not or cannot be serialized or to convert user data
10221022
into a form more suitable for serialization.
10231023

1024+
Callbacks are run in the order in which they are added.
1025+
10241026
###`v8.startupSnapshot.addDeserializeCallback(callback[, data])`
10251027

10261028
<!-- YAML
@@ -1040,6 +1042,8 @@ serialized into the snapshot, they can be used to re-initialize the state
10401042
of the application or to re-acquire resources that the application needs
10411043
when the application is restarted from the snapshot.
10421044

1045+
Callbacks are run in the order in which they are added.
1046+
10431047
###`v8.startupSnapshot.setDeserializeMainFunction(callback[, data])`
10441048

10451049
<!-- YAML

‎lib/internal/bootstrap/switches/does_own_process_state.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const credentials = internalBinding('credentials');
44
constrawMethods=internalBinding('process_methods');
55
const{
66
namespace:{
7+
addDeserializeCallback,
78
addSerializeCallback,
89
isBuildingSnapshot,
910
},
@@ -114,8 +115,13 @@ function wrapPosixCredentialSetters(credentials) {
114115
letcachedCwd='';
115116

116117
if(isBuildingSnapshot()){
118+
// Reset the cwd on both serialization and deserialization so it's fine
119+
// for process.cwd() to be accessed inside of serialization callbacks.
117120
addSerializeCallback(()=>{
118121
cachedCwd='';
122+
addDeserializeCallback(()=>{
123+
cachedCwd='';
124+
});
119125
});
120126
}
121127

‎test/fixtures/snapshot/cwd.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
const{
2+
addSerializeCallback,
23
setDeserializeMainFunction,
34
}=require('v8').startupSnapshot;
45

56
// To make sure the cwd is present in the cache
67
process.cwd();
78

9+
// Also access it from a serialization callback once
10+
addSerializeCallback(()=>{
11+
process.cwd();
12+
});
13+
814
setDeserializeMainFunction(()=>{
915
console.log(process.cwd());
1016
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp