Skip to content

Commit 8970167

Browse files
joyeecheungjuanarbol
authored andcommitted
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 <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 139a8eb commit 8970167

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/internal/bootstrap/pre_execution.js

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
const {
1414
getOptionValue,
1515
getEmbedderOptions,
16+
refreshOptions,
1617
} = require('internal/options');
1718
const { reconnectZeroFillToggle } = require('internal/buffer');
1819
const {
@@ -26,6 +27,8 @@ const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes;
2627
const assert = require('internal/assert');
2728

2829
function prepareMainThreadExecution(expandArgv1 = false) {
30+
refreshRuntimeOptions();
31+
2932
// TODO(joyeecheung): this is also necessary for workers when they deserialize
3033
// this toggle from the snapshot.
3134
reconnectZeroFillToggle();
@@ -86,6 +89,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
8689
initializeFrozenIntrinsics();
8790
}
8891

92+
function refreshRuntimeOptions() {
93+
refreshOptions();
94+
}
95+
8996
function patchProcessObject(expandArgv1) {
9097
const binding = internalBinding('process_methods');
9198
binding.patchProcessObject(process);
@@ -541,6 +548,7 @@ function loadPreloadModules() {
541548
}
542549

543550
module.exports = {
551+
refreshRuntimeOptions,
544552
patchProcessObject,
545553
setupCoverageHooks,
546554
setupWarningHandler,

lib/internal/options.js

+7-1
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)