From 4d012b248ee5ca41b5aaa8baeaab36621ab9d814 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 11 Jun 2021 11:28:27 +0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/42466 Reviewed-By: Darshan Sen Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Khaidi Chu Reviewed-By: Chengzhong Wu --- lib/internal/bootstrap/pre_execution.js | 8 ++++++++ lib/internal/options.js | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 8de57a56661..c306de7db63 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -13,6 +13,7 @@ const { const { getOptionValue, getEmbedderOptions, + refreshOptions, } = require('internal/options'); const { reconnectZeroFillToggle } = require('internal/buffer'); const { @@ -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(); @@ -86,6 +89,10 @@ function prepareMainThreadExecution(expandArgv1 = false) { initializeFrozenIntrinsics(); } +function refreshRuntimeOptions() { + refreshOptions(); +} + function patchProcessObject(expandArgv1) { const binding = internalBinding('process_methods'); binding.patchProcessObject(process); @@ -541,6 +548,7 @@ function loadPreloadModules() { } module.exports = { + refreshRuntimeOptions, patchProcessObject, setupCoverageHooks, setupWarningHandler, diff --git a/lib/internal/options.js b/lib/internal/options.js index 01b334d4ec5..4d92ad681a1 100644 --- a/lib/internal/options.js +++ b/lib/internal/options.js @@ -36,6 +36,11 @@ function getEmbedderOptions() { return embedderOptions; } +function refreshOptions() { + optionsMap = undefined; + aliasesMap = undefined; +} + function getOptionValue(optionName) { const options = getCLIOptionsFromBinding(); if (optionName.startsWith('--no-')) { @@ -68,5 +73,6 @@ module.exports = { }, getOptionValue, getAllowUnauthorized, - getEmbedderOptions + getEmbedderOptions, + refreshOptions };