From ed5a2dfef019e2d499689306bacf68d9711774f2 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 239f5258620c04..5c7f67d7541032 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -338,6 +338,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 b8b6d85f39e4ed..35ee54d223176a 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" #if HAVE_OPENSSL #include "openssl/opensslv.h" @@ -1133,6 +1134,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) { @@ -1199,3 +1204,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)