| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent da8fa48 commit dcbf88f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1021,6 +1021,8 @@ get serialized into a snapshot and exit. This can be used to release | |||
| 1021 | 1021 | resources that should not or cannot be serialized or to convert user data | |
| 1022 | 1022 | into a form more suitable for serialization. | |
| 1023 | 1023 | ||
| 1024 | + Callbacks are run in the order in which they are added. | ||
| 1025 | + | ||
| 1024 | 1026 | ### `v8.startupSnapshot.addDeserializeCallback(callback[, data])` | |
| 1025 | 1027 | ||
| 1026 | 1028 | <!-- YAML | |
@@ -1040,6 +1042,8 @@ serialized into the snapshot, they can be used to re-initialize the state | |||
| 1040 | 1042 | of the application or to re-acquire resources that the application needs | |
| 1041 | 1043 | when the application is restarted from the snapshot. | |
| 1042 | 1044 | ||
| 1045 | + Callbacks are run in the order in which they are added. | ||
| 1046 | + | ||
| 1043 | 1047 | ### `v8.startupSnapshot.setDeserializeMainFunction(callback[, data])` | |
| 1044 | 1048 | ||
| 1045 | 1049 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const credentials = internalBinding('credentials'); | |||
| 4 | 4 | const rawMethods = internalBinding('process_methods'); | |
| 5 | 5 | const { | |
| 6 | 6 | namespace: { | |
| 7 | + addDeserializeCallback, | ||
| 7 | 8 | addSerializeCallback, | |
| 8 | 9 | isBuildingSnapshot, | |
| 9 | 10 | }, | |
@@ -114,8 +115,13 @@ function wrapPosixCredentialSetters(credentials) { | |||
| 114 | 115 | let cachedCwd = ''; | |
| 115 | 116 | ||
| 116 | 117 | 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. | ||
| 117 | 120 | addSerializeCallback(() => { | |
| 118 | 121 | cachedCwd = ''; | |
| 122 | + addDeserializeCallback(() => { | ||
| 123 | + cachedCwd = ''; | ||
| 124 | + }); | ||
| 119 | 125 | }); | |
| 120 | 126 | } | |
| 121 | 127 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,16 @@ | |||
| 1 | 1 | const { | |
| 2 | + addSerializeCallback, | ||
| 2 | 3 | setDeserializeMainFunction, | |
| 3 | 4 | } = require('v8').startupSnapshot; | |
| 4 | 5 | ||
| 5 | 6 | // To make sure the cwd is present in the cache | |
| 6 | 7 | process.cwd(); | |
| 7 | 8 | ||
| 9 | + // Also access it from a serialization callback once | ||
| 10 | + addSerializeCallback(() => { | ||
| 11 | + process.cwd(); | ||
| 12 | + }); | ||
| 13 | + | ||
| 8 | 14 | setDeserializeMainFunction(() => { | |
| 9 | 15 | console.log(process.cwd()); | |
| 10 | 16 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments