Skip to content

Commit 9f2cbaf

Browse files
joyeecheungantsmartian
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: nodejs#25463 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent e81c6c8 commit 9f2cbaf

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/internal/bootstrap/loaders.js

+15-2
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
@@ -158,6 +158,11 @@ let internalBinding;
158158
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
159159
internalBinding('module_wrap').callbackMap = new WeakMap();
160160

161+
// Think of this as module.exports in this file even though it is not
162+
// written in CommonJS style.
163+
const loaderExports = { internalBinding, NativeModule };
164+
const loaderId = 'internal/bootstrap/loaders';
165+
161166
// Set up NativeModule.
162167
function NativeModule(id) {
163168
this.filename = `${id}.js`;
@@ -167,6 +172,14 @@ function NativeModule(id) {
167172
this.exportKeys = undefined;
168173
this.loaded = false;
169174
this.loading = false;
175+
if (id === loaderId) {
176+
// Do not expose this to user land even with --expose-internals.
177+
this.canBeRequiredByUsers = false;
178+
} else if (id.startsWith('internal/')) {
179+
this.canBeRequiredByUsers = exposeInternals;
180+
} else {
181+
this.canBeRequiredByUsers = true;
182+
}
170183
}
171184

172185
const {
@@ -340,7 +353,7 @@ NativeModule.prototype.compile = function() {
340353
const fn = compileFunction(id);
341354
fn(this.exports, requireFn, this, process, internalBinding);
342355

343-
if (config.experimentalModules && !NativeModule.isInternal(this.id)) {
356+
if (experimentalModules && this.canBeRequiredByUsers) {
344357
this.proxifyExports();
345358
}
346359

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)