From 9fc4b9b04ede2092b3e1f0c5716b481540951cd6 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 237a1b96922aef..8f5e8d8f1d7ec8 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -391,6 +391,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 ab3b736e07d8e9..4168759910cde5 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" @@ -1132,6 +1133,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) { @@ -1198,3 +1203,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)