Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: handle --expose-internals during pre-execution #26759

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

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

const {
Reflect,
Expand Down Expand Up @@ -157,15 +156,19 @@ function NativeModule(id) {
this.exportKeys = undefined;
this.loaded = false;
this.loading = false;
if (id === loaderId) {
this.canBeRequiredByUsers = !id.startsWith('internal/');
}

// To be called during pre-execution when --expose-internals is on.
// Enables the user-land module loader to access internal modules.
NativeModule.exposeInternals = function() {
for (const [id, mod] of NativeModule.map) {
// Do not expose this to user land even with --expose-internals.
this.canBeRequiredByUsers = false;
} else if (id.startsWith('internal/')) {
this.canBeRequiredByUsers = exposeInternals;
} else {
this.canBeRequiredByUsers = true;
if (id !== loaderId) {
mod.canBeRequiredByUsers = true;
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
};

const {
moduleIds,
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ function initializeReport() {

function setupDebugEnv() {
require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG);
if (getOptionValue('--expose-internals')) {
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
require('internal/bootstrap/loaders').NativeModule.exposeInternals();
}
}

function setupSignalHandlers() {
Expand Down
3 changes: 0 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
env->process_string(),
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
// --expose-internals
FIXED_ONE_BYTE_STRING(isolate, "exposeInternals"),
env->primordials_string()};
std::vector<Local<Value>> loaders_args = {
process,
Expand All @@ -307,7 +305,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
env->NewFunctionTemplate(binding::GetInternalBinding)
->GetFunction(context)
.ToLocalChecked(),
Boolean::New(isolate, env->options()->expose_internals),
env->primordials()};

// Bootstrap internal loaders
Expand Down