Skip to content

Commit a03552d

Browse files
joyeecheungtargos
authored andcommitted
process: handle --expose-internals during pre-execution
Instead of relying on the value of the CLI option when executing bootstrap/loaders.js. PR-URL: #26759 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent bb9f1cc commit a03552d

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

lib/internal/bootstrap/loaders.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141

4242
// This file is compiled as if it's wrapped in a function with arguments
4343
// passed by node::RunBootstrapping()
44-
/* global process, getLinkedBinding, getInternalBinding */
45-
/* global exposeInternals, primordials */
44+
/* global process, getLinkedBinding, getInternalBinding, primordials */
4645

4746
const {
4847
Reflect,
@@ -157,15 +156,19 @@ function NativeModule(id) {
157156
this.exportKeys = undefined;
158157
this.loaded = false;
159158
this.loading = false;
160-
if (id === loaderId) {
159+
this.canBeRequiredByUsers = !id.startsWith('internal/');
160+
}
161+
162+
// To be called during pre-execution when --expose-internals is on.
163+
// Enables the user-land module loader to access internal modules.
164+
NativeModule.exposeInternals = function() {
165+
for (const [id, mod] of NativeModule.map) {
161166
// Do not expose this to user land even with --expose-internals.
162-
this.canBeRequiredByUsers = false;
163-
} else if (id.startsWith('internal/')) {
164-
this.canBeRequiredByUsers = exposeInternals;
165-
} else {
166-
this.canBeRequiredByUsers = true;
167+
if (id !== loaderId) {
168+
mod.canBeRequiredByUsers = true;
169+
}
167170
}
168-
}
171+
};
169172

170173
const {
171174
moduleIds,

lib/internal/bootstrap/pre_execution.js

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ function initializeReport() {
146146

147147
function setupDebugEnv() {
148148
require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG);
149+
if (getOptionValue('--expose-internals')) {
150+
require('internal/bootstrap/loaders').NativeModule.exposeInternals();
151+
}
149152
}
150153

151154
function setupSignalHandlers() {

src/node.cc

-3
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
296296
env->process_string(),
297297
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
298298
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
299-
// --expose-internals
300-
FIXED_ONE_BYTE_STRING(isolate, "exposeInternals"),
301299
env->primordials_string()};
302300
std::vector<Local<Value>> loaders_args = {
303301
process,
@@ -307,7 +305,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
307305
env->NewFunctionTemplate(binding::GetInternalBinding)
308306
->GetFunction(context)
309307
.ToLocalChecked(),
310-
Boolean::New(isolate, env->options()->expose_internals),
311308
env->primordials()};
312309

313310
// Bootstrap internal loaders

0 commit comments

Comments
 (0)