Skip to content

Commit 7565586

Browse files
joyeecheungtargos
authored andcommitted
src: pass cli options to bootstrap/loaders.js lexically
Instead of using `internalBinding('config')` which should be used to carry information about build-time options, directly pass the run-time cli options into bootstrap/loaders.js lexically via function arguments. PR-URL: #25463 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Backport-PR-URL: #26027
1 parent 2b48a38 commit 7565586

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/internal/bootstrap/loaders.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// This file is compiled as if it's wrapped in a function with arguments
4343
// passed by node::LoadEnvironment()
4444
/* global process, getBinding, getLinkedBinding, getInternalBinding */
45-
/* global debugBreak */
45+
/* global debugBreak, experimentalModules, exposeInternals */
4646

4747
if (debugBreak)
4848
debugger; // eslint-disable-line no-debugger
@@ -162,7 +162,6 @@ internalBinding('module_wrap').callbackMap = new WeakMap();
162162
// written in CommonJS style.
163163
const loaderExports = { internalBinding, NativeModule };
164164
const loaderId = 'internal/bootstrap/loaders';
165-
const config = internalBinding('config');
166165

167166
// Set up NativeModule.
168167
function NativeModule(id) {
@@ -177,7 +176,7 @@ function NativeModule(id) {
177176
// Do not expose this to user land even with --expose-internals.
178177
this.canBeRequiredByUsers = false;
179178
} else if (id.startsWith('internal/')) {
180-
this.canBeRequiredByUsers = config.exposeInternals;
179+
this.canBeRequiredByUsers = exposeInternals;
181180
} else {
182181
this.canBeRequiredByUsers = true;
183182
}
@@ -316,7 +315,7 @@ NativeModule.prototype.compile = function() {
316315
const fn = compileFunction(id);
317316
fn(this.exports, requireFn, this, process, internalBinding);
318317

319-
if (config.experimentalModules && this.canBeRequiredByUsers) {
318+
if (experimentalModules && this.canBeRequiredByUsers) {
320319
this.proxifyExports();
321320
}
322321

src/node.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,12 @@ void RunBootstrapping(Environment* env) {
678678
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
679679
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
680680
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
681-
FIXED_ONE_BYTE_STRING(isolate, "debugBreak")};
681+
// --inspect-brk-node
682+
FIXED_ONE_BYTE_STRING(isolate, "debugBreak"),
683+
// --experimental-modules
684+
FIXED_ONE_BYTE_STRING(isolate, "experimentalModules"),
685+
// --expose-internals
686+
FIXED_ONE_BYTE_STRING(isolate, "exposeInternals")};
682687
std::vector<Local<Value>> loaders_args = {
683688
process,
684689
env->NewFunctionTemplate(binding::GetBinding)
@@ -691,7 +696,11 @@ void RunBootstrapping(Environment* env) {
691696
->GetFunction(context)
692697
.ToLocalChecked(),
693698
Boolean::New(isolate,
694-
env->options()->debug_options().break_node_first_line)};
699+
env->options()->debug_options().break_node_first_line),
700+
Boolean::New(isolate,
701+
env->options()->experimental_modules),
702+
Boolean::New(isolate,
703+
env->options()->expose_internals)};
695704

696705
MaybeLocal<Value> loader_exports;
697706
// Bootstrap internal loaders

0 commit comments

Comments
 (0)