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 <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent f9e4279 commit 547e74b

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎lib/internal/bootstrap_node.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,9 @@
443443
returnNativeModule._source.hasOwnProperty(id);
444444
};
445445

446-
constEXPOSE_INTERNALS=process.execArgv.some(function(arg){
447-
returnarg.match(/^--expose[-_]internals$/);
448-
});
446+
constconfig=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‎

Lines changed: 7 additions & 1 deletion
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
staticdouble prog_start_time;
204210
staticbool debugger_running;
@@ -3896,7 +3902,7 @@ static void ParseArgs(int* argc,
38963902
#endif
38973903
} elseif (strcmp(arg, "--expose-internals") == 0 ||
38983904
strcmp(arg, "--expose_internals") == 0) {
3899-
// consumed in js
3905+
config_expose_internals = true;
39003906
} elseif (strcmp(arg, "--") == 0) {
39013907
index += 1;
39023908
break;

‎src/node_config.cc‎

Lines changed: 3 additions & 0 deletions
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‎

Lines changed: 6 additions & 0 deletions
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
externbool 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+
externbool config_expose_internals;
51+
4652
// Forward declaration
4753
classEnvironment;
4854

‎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
constassert=require('assert');
6+
constconfig=process.binding('config');
7+
8+
console.log(config,process.argv);
69

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

0 commit comments

Comments
 (0)