Skip to content

Commit e3683cb

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 970483f commit e3683cb

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 {
@@ -24,6 +25,8 @@ const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes;
2425
const assert = require('internal/assert');
2526

2627
function prepareMainThreadExecution(expandArgv1 = false) {
28+
refreshRuntimeOptions();
29+
2730
// TODO(joyeecheung): this is also necessary for workers when they deserialize
2831
// this toggle from the snapshot.
2932
reconnectZeroFillToggle();
@@ -84,6 +87,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
8487
initializeFrozenIntrinsics();
8588
}
8689

90+
function refreshRuntimeOptions() {
91+
refreshOptions();
92+
}
93+
8794
function patchProcessObject(expandArgv1) {
8895
const binding = internalBinding('process_methods');
8996
binding.patchProcessObject(process);
@@ -565,6 +572,7 @@ function loadPreloadModules() {
565572
}
566573

567574
module.exports = {
575+
refreshRuntimeOptions,
568576
patchProcessObject,
569577
setupCoverageHooks,
570578
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)