Skip to content

Commit 88ca10f

Browse files
committed
fixup! src: use option parser for expose_internals
1 parent 8b07404 commit 88ca10f

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

lib/internal/bootstrap_node.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,9 @@
508508
return NativeModule._source.hasOwnProperty(id);
509509
};
510510

511-
const EXPOSE_INTERNALS = process._exposeInternals;
511+
const config = process.binding('config');
512512

513-
if (EXPOSE_INTERNALS) {
514-
delete process._exposeInternals;
513+
if (config.exposeInternals) {
515514
NativeModule.nonInternalExists = NativeModule.exists;
516515

517516
NativeModule.isInternal = function(id) {

src/node.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ static bool trace_sync_io = false;
163163
static bool track_heap_objects = false;
164164
static const char* eval_string = nullptr;
165165
static std::vector<std::string> preload_modules;
166-
static bool expose_internals = false;
167166
static const int v8_default_thread_pool_size = 4;
168167
static int v8_thread_pool_size = v8_default_thread_pool_size;
169168
static bool prof_process = false;
@@ -216,6 +215,12 @@ bool config_preserve_symlinks = false;
216215
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
217216
std::string config_warning_file; // NOLINT(runtime/string)
218217

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+
219224
bool v8_initialized = false;
220225

221226
// process-relative uptime base, initialized at start-up
@@ -3334,13 +3339,6 @@ void SetupProcessObject(Environment* env,
33343339
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
33353340
}
33363341

3337-
// --expose_internals, --expose-internals
3338-
// Note that this is not exposed as a process property, it is deleted when
3339-
// node's javascript bootstrap code runs.
3340-
if (expose_internals) {
3341-
READONLY_PROPERTY(process, "_exposeInternals", True(env->isolate()));
3342-
}
3343-
33443342
// --security-revert flags
33453343
#define V(code, _, __) \
33463344
do { \
@@ -3794,7 +3792,7 @@ static void ParseArgs(int* argc,
37943792
#endif
37953793
} else if (strcmp(arg, "--expose-internals") == 0 ||
37963794
strcmp(arg, "--expose_internals") == 0) {
3797-
expose_internals = true;
3795+
config_expose_internals = true;
37983796
} else if (strcmp(arg, "--") == 0) {
37993797
index += 1;
38003798
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-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +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');
8-
assert(!('_exposeInternals' in process), 'no process property is leaked');
11+
assert.strictEqual(config.exposeInternals, true);

0 commit comments

Comments
 (0)