Skip to content

Commit

Permalink
bootstrap: refresh options in pre-execution
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joyeecheung authored and juanarbol committed May 31, 2022
1 parent 139a8eb commit 8970167
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
const {
getOptionValue,
getEmbedderOptions,
refreshOptions,
} = require('internal/options');
const { reconnectZeroFillToggle } = require('internal/buffer');
const {
Expand All @@ -26,6 +27,8 @@ const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes;
const assert = require('internal/assert');

function prepareMainThreadExecution(expandArgv1 = false) {
refreshRuntimeOptions();

// TODO(joyeecheung): this is also necessary for workers when they deserialize
// this toggle from the snapshot.
reconnectZeroFillToggle();
Expand Down Expand Up @@ -86,6 +89,10 @@ function prepareMainThreadExecution(expandArgv1 = false) {
initializeFrozenIntrinsics();
}

function refreshRuntimeOptions() {
refreshOptions();
}

function patchProcessObject(expandArgv1) {
const binding = internalBinding('process_methods');
binding.patchProcessObject(process);
Expand Down Expand Up @@ -541,6 +548,7 @@ function loadPreloadModules() {
}

module.exports = {
refreshRuntimeOptions,
patchProcessObject,
setupCoverageHooks,
setupWarningHandler,
Expand Down
8 changes: 7 additions & 1 deletion lib/internal/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function getEmbedderOptions() {
return embedderOptions;
}

function refreshOptions() {
optionsMap = undefined;
aliasesMap = undefined;
}

function getOptionValue(optionName) {
const options = getCLIOptionsFromBinding();
if (optionName.startsWith('--no-')) {
Expand Down Expand Up @@ -68,5 +73,6 @@ module.exports = {
},
getOptionValue,
getAllowUnauthorized,
getEmbedderOptions
getEmbedderOptions,
refreshOptions
};

0 comments on commit 8970167

Please sign in to comment.