Skip to content

Commit d746bca

Browse files
committed
src: use option parser for expose_internals
bootstrap_node.js was directly parsing process.execArgv to see if internals should be exposed, even though the argv was already parsed by node. This is unusual and unnecessary, change it to set the option value from the parser onto the process object, as is done for the other CLI options.
1 parent fd374bf commit d746bca

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

lib/internal/bootstrap_node.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,9 @@
508508
return NativeModule._source.hasOwnProperty(id);
509509
};
510510

511-
const EXPOSE_INTERNALS = process.execArgv.some(function(arg) {
512-
return arg.match(/^--expose[-_]internals$/);
513-
});
511+
const config = process.binding('config');
514512

515-
if (EXPOSE_INTERNALS) {
513+
if (config.exposeInternals) {
516514
NativeModule.nonInternalExists = NativeModule.exists;
517515

518516
NativeModule.isInternal = function(id) {

src/node.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ bool config_preserve_symlinks = false;
215215
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
216216
std::string config_warning_file; // NOLINT(runtime/string)
217217

218+
// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
219+
// used.
220+
// Used in node_config.cc to set a constant on process.binding('config')
221+
// that is used by lib/internal/bootstrap_node.js
222+
bool config_expose_internals = false;
223+
218224
bool v8_initialized = false;
219225

220226
// process-relative uptime base, initialized at start-up
@@ -3786,7 +3792,7 @@ static void ParseArgs(int* argc,
37863792
#endif
37873793
} else if (strcmp(arg, "--expose-internals") == 0 ||
37883794
strcmp(arg, "--expose_internals") == 0) {
3789-
// consumed in js
3795+
config_expose_internals = true;
37903796
} else if (strcmp(arg, "--") == 0) {
37913797
index += 1;
37923798
break;

src/node_config.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void InitConfig(Local<Object> target,
5858
.ToLocalChecked();
5959
target->DefineOwnProperty(env->context(), name, value).FromJust();
6060
}
61+
62+
if (config_expose_internals)
63+
READONLY_BOOLEAN_PROPERTY("exposeInternals");
6164
} // InitConfig
6265

6366
} // namespace node

src/node_internals.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ extern std::string openssl_config;
6565
// that is used by lib/module.js
6666
extern bool config_preserve_symlinks;
6767

68+
// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
69+
// used.
70+
// Used in node_config.cc to set a constant on process.binding('config')
71+
// that is used by lib/internal/bootstrap_node.js
72+
extern bool config_expose_internals;
73+
6874
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
6975
// Used to redirect warning output to a file rather than sending
7076
// it to stderr.

test/parallel/test-internal-modules-expose.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33

44
require('../common');
55
const assert = require('assert');
6+
const config = process.binding('config');
7+
8+
console.log(config, process.argv);
69

710
assert.strictEqual(typeof require('internal/freelist').FreeList, 'function');
11+
assert.strictEqual(config.exposeInternals, true);

0 commit comments

Comments
 (0)