Skip to content

Commit 547e74b

Browse files
sam-githubMylesBorins
authored andcommitted
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. Backport-PR-URL: #14483 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 f9e4279 commit 547e74b

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
@@ -443,11 +443,9 @@
443443
return NativeModule._source.hasOwnProperty(id);
444444
};
445445

446-
const EXPOSE_INTERNALS = process.execArgv.some(function(arg) {
447-
return arg.match(/^--expose[-_]internals$/);
448-
});
446+
const config = process.binding('config');
449447

450-
if (EXPOSE_INTERNALS) {
448+
if (config.exposeInternals) {
451449
NativeModule.nonInternalExists = NativeModule.exists;
452450

453451
NativeModule.isInternal = function(id) {

src/node.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ bool trace_warnings = false;
199199
// that is used by lib/module.js
200200
bool config_preserve_symlinks = false;
201201

202+
// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
203+
// used.
204+
// Used in node_config.cc to set a constant on process.binding('config')
205+
// that is used by lib/internal/bootstrap_node.js
206+
bool config_expose_internals = false;
207+
202208
// process-relative uptime base, initialized at start-up
203209
static double prog_start_time;
204210
static bool debugger_running;
@@ -3896,7 +3902,7 @@ static void ParseArgs(int* argc,
38963902
#endif
38973903
} else if (strcmp(arg, "--expose-internals") == 0 ||
38983904
strcmp(arg, "--expose_internals") == 0) {
3899-
// consumed in js
3905+
config_expose_internals = true;
39003906
} else if (strcmp(arg, "--") == 0) {
39013907
index += 1;
39023908
break;

src/node_config.cc

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void InitConfig(Local<Object> target,
4444

4545
if (config_preserve_symlinks)
4646
READONLY_BOOLEAN_PROPERTY("preserveSymlinks");
47+
48+
if (config_expose_internals)
49+
READONLY_BOOLEAN_PROPERTY("exposeInternals");
4750
} // InitConfig
4851

4952
} // namespace node

src/node_internals.h

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ extern std::string openssl_config;
4343
// that is used by lib/module.js
4444
extern bool config_preserve_symlinks;
4545

46+
// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
47+
// used.
48+
// Used in node_config.cc to set a constant on process.binding('config')
49+
// that is used by lib/internal/bootstrap_node.js
50+
extern bool config_expose_internals;
51+
4652
// Forward declaration
4753
class Environment;
4854

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)