Skip to content

Commit

Permalink
process: handle --expose-internals during pre-execution
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and targos committed Mar 30, 2019
1 parent bb9f1cc commit a03552d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
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;
}
}
}
};

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 @@ -146,6 +146,9 @@ function initializeReport() {

function setupDebugEnv() {
require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG);
if (getOptionValue('--expose-internals')) {
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

0 comments on commit a03552d

Please sign in to comment.