Skip to content

Commit 8086cb6

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 config binding. PR-URL: #12245 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent e505c07 commit 8086cb6

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

lib/internal/bootstrap_node.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,9 @@
510510
return NativeModule._source.hasOwnProperty(id);
511511
};
512512

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

517-
if (EXPOSE_INTERNALS) {
515+
if (config.exposeInternals) {
518516
NativeModule.nonInternalExists = NativeModule.exists;
519517

520518
NativeModule.isInternal = function(id) {

src/node.cc

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

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

219225
// process-relative uptime base, initialized at start-up
@@ -3787,7 +3793,7 @@ static void ParseArgs(int* argc,
37873793
#endif
37883794
} else if (strcmp(arg, "--expose-internals") == 0 ||
37893795
strcmp(arg, "--expose_internals") == 0) {
3790-
// consumed in js
3796+
config_expose_internals = true;
37913797
} else if (strcmp(arg, "--") == 0) {
37923798
index += 1;
37933799
break;

src/node_config.cc

+3
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

+6
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

+4
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)