From 376b3c4293203a6cc3fe8181ab11476ccf986e6a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 4 Mar 2022 02:01:07 +0800 Subject: [PATCH] src: include internal/options in the snapshot This patch enables internal/options to be included in the snapshot, so that when lazy loading the run time options, the modules only need to make sure that the options are queried lazily and do not have to lazy load the internal/options module together. We can still guarantee that no run time options are serialized into the state-independent bootstrap snapshot with the assertion inside GetCLIOptions(). PR-URL: https://github.com/nodejs/node/pull/42203 Refs: https://github.com/nodejs/node/issues/37476 Reviewed-By: Anna Henningsen Reviewed-By: Bradley Farias Reviewed-By: Colin Ihrig Reviewed-By: Darshan Sen Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel --- lib/internal/bootstrap/node.js | 1 + src/node_external_reference.h | 1 + src/node_options.cc | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 1393cc20f45db6..dfae7675e16a6a 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -380,6 +380,7 @@ require('fs'); require('v8'); require('vm'); require('url'); +require('internal/options'); function setupPrepareStackTrace() { const { diff --git a/src/node_external_reference.h b/src/node_external_reference.h index 347945a7496d5f..c57a01ff39c20e 100644 --- a/src/node_external_reference.h +++ b/src/node_external_reference.h @@ -67,6 +67,7 @@ class ExternalReferenceRegistry { V(heap_utils) \ V(messaging) \ V(native_module) \ + V(options) \ V(os) \ V(performance) \ V(process_methods) \ diff --git a/src/node_options.cc b/src/node_options.cc index 1a979f007b73e9..3192faaddaf471 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -3,6 +3,7 @@ #include "env-inl.h" #include "node_binding.h" +#include "node_external_reference.h" #include "node_internals.h" #include @@ -1124,6 +1125,10 @@ void Initialize(Local target, .Check(); } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(GetCLIOptions); + registry->Register(GetEmbedderOptions); +} } // namespace options_parser void HandleEnvOptions(std::shared_ptr env_options) { @@ -1190,3 +1195,5 @@ std::vector ParseNodeOptionsEnvVar( } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(options, + node::options_parser::RegisterExternalReferences)