diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index cb6867125860e1..6380506b72ee1b 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -510,11 +510,9 @@ return NativeModule._source.hasOwnProperty(id); }; - const EXPOSE_INTERNALS = process.execArgv.some(function(arg) { - return arg.match(/^--expose[-_]internals$/); - }); + const config = process.binding('config'); - if (EXPOSE_INTERNALS) { + if (config.exposeInternals) { NativeModule.nonInternalExists = NativeModule.exists; NativeModule.isInternal = function(id) { diff --git a/src/node.cc b/src/node.cc index 2acb63e7b37206..84a883845d916b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -214,6 +214,12 @@ bool config_preserve_symlinks = false; // Set in node.cc by ParseArgs when --redirect-warnings= is used. std::string config_warning_file; // NOLINT(runtime/string) +// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is +// used. +// Used in node_config.cc to set a constant on process.binding('config') +// that is used by lib/internal/bootstrap_node.js +bool config_expose_internals = false; + bool v8_initialized = false; // process-relative uptime base, initialized at start-up @@ -3787,7 +3793,7 @@ static void ParseArgs(int* argc, #endif } else if (strcmp(arg, "--expose-internals") == 0 || strcmp(arg, "--expose_internals") == 0) { - // consumed in js + config_expose_internals = true; } else if (strcmp(arg, "--") == 0) { index += 1; break; diff --git a/src/node_config.cc b/src/node_config.cc index 5c9c51585baf3a..3c082d61943a7c 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -58,6 +58,9 @@ void InitConfig(Local target, .ToLocalChecked(); target->DefineOwnProperty(env->context(), name, value).FromJust(); } + + if (config_expose_internals) + READONLY_BOOLEAN_PROPERTY("exposeInternals"); } // InitConfig } // namespace node diff --git a/src/node_internals.h b/src/node_internals.h index 0ee694a2284707..fa219b96cdb4a9 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -65,6 +65,12 @@ extern std::string openssl_config; // that is used by lib/module.js extern bool config_preserve_symlinks; +// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is +// used. +// Used in node_config.cc to set a constant on process.binding('config') +// that is used by lib/internal/bootstrap_node.js +extern bool config_expose_internals; + // Set in node.cc by ParseArgs when --redirect-warnings= is used. // Used to redirect warning output to a file rather than sending // it to stderr. diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index 02ddfd87c363fc..ab48e36881268c 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -3,5 +3,9 @@ require('../common'); const assert = require('assert'); +const config = process.binding('config'); + +console.log(config, process.argv); assert.strictEqual(typeof require('internal/freelist').FreeList, 'function'); +assert.strictEqual(config.exposeInternals, true);