Skip to content

Commit 8a297ba

Browse files
committed
bootstrap: refresh options in pre-execution
Refresh the options map during pre-execution to pave the way for user land snapshots which may need to access run-time options at snapshot-building time. The default embedded bootstrap snapshot is still prevented from accessing them at snapshot building time since it serves a wider audience and is ignorant of application states, while the user-land snapshots are meant to be application-specific and so it makes sense for them to access runtime states as long as the snapshotted-code works with re-initialized runtime states. PR-URL: #42466 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 1600869 commit 8a297ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/internal/bootstrap/pre_execution.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
const {
1515
getOptionValue,
1616
getEmbedderOptions,
17+
refreshOptions,
1718
} = require('internal/options');
1819
const { reconnectZeroFillToggle } = require('internal/buffer');
1920
const {
@@ -27,6 +28,8 @@ const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes;
2728
const assert = require('internal/assert');
2829

2930
function prepareMainThreadExecution(expandArgv1 = false) {
31+
refreshRuntimeOptions();
32+
3033
// TODO(joyeecheung): this is also necessary for workers when they deserialize
3134
// this toggle from the snapshot.
3235
reconnectZeroFillToggle();
@@ -87,6 +90,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
8790
initializeFrozenIntrinsics();
8891
}
8992

93+
function refreshRuntimeOptions() {
94+
refreshOptions();
95+
}
96+
9097
function patchProcessObject(expandArgv1) {
9198
const binding = internalBinding('process_methods');
9299
binding.patchProcessObject(process);
@@ -556,6 +563,7 @@ function loadPreloadModules() {
556563
}
557564

558565
module.exports = {
566+
refreshRuntimeOptions,
559567
patchProcessObject,
560568
setupCoverageHooks,
561569
setupWarningHandler,

lib/internal/options.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ function getEmbedderOptions() {
3636
return embedderOptions;
3737
}
3838

39+
function refreshOptions() {
40+
optionsMap = undefined;
41+
aliasesMap = undefined;
42+
}
43+
3944
function getOptionValue(optionName) {
4045
const options = getCLIOptionsFromBinding();
4146
if (optionName.startsWith('--no-')) {
@@ -68,5 +73,6 @@ module.exports = {
6873
},
6974
getOptionValue,
7075
getAllowUnauthorized,
71-
getEmbedderOptions
76+
getEmbedderOptions,
77+
refreshOptions
7278
};

0 commit comments

Comments
 (0)