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: https://github.com/nodejs/node/pull/25463 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
6b2af91a88
commit
cd70cbcbdd
@ -42,7 +42,7 @@
|
|||||||
// This file is compiled as if it's wrapped in a function with arguments
|
// This file is compiled as if it's wrapped in a function with arguments
|
||||||
// passed by node::LoadEnvironment()
|
// passed by node::LoadEnvironment()
|
||||||
/* global process, getBinding, getLinkedBinding, getInternalBinding */
|
/* global process, getBinding, getLinkedBinding, getInternalBinding */
|
||||||
/* global debugBreak */
|
/* global debugBreak, experimentalModules, exposeInternals */
|
||||||
|
|
||||||
if (debugBreak)
|
if (debugBreak)
|
||||||
debugger; // eslint-disable-line no-debugger
|
debugger; // eslint-disable-line no-debugger
|
||||||
@ -162,7 +162,6 @@ internalBinding('module_wrap').callbackMap = new WeakMap();
|
|||||||
// written in CommonJS style.
|
// written in CommonJS style.
|
||||||
const loaderExports = { internalBinding, NativeModule };
|
const loaderExports = { internalBinding, NativeModule };
|
||||||
const loaderId = 'internal/bootstrap/loaders';
|
const loaderId = 'internal/bootstrap/loaders';
|
||||||
const config = internalBinding('config');
|
|
||||||
|
|
||||||
// Set up NativeModule.
|
// Set up NativeModule.
|
||||||
function NativeModule(id) {
|
function NativeModule(id) {
|
||||||
@ -177,7 +176,7 @@ function NativeModule(id) {
|
|||||||
// Do not expose this to user land even with --expose-internals.
|
// Do not expose this to user land even with --expose-internals.
|
||||||
this.canBeRequiredByUsers = false;
|
this.canBeRequiredByUsers = false;
|
||||||
} else if (id.startsWith('internal/')) {
|
} else if (id.startsWith('internal/')) {
|
||||||
this.canBeRequiredByUsers = config.exposeInternals;
|
this.canBeRequiredByUsers = exposeInternals;
|
||||||
} else {
|
} else {
|
||||||
this.canBeRequiredByUsers = true;
|
this.canBeRequiredByUsers = true;
|
||||||
}
|
}
|
||||||
@ -316,7 +315,7 @@ NativeModule.prototype.compile = function() {
|
|||||||
const fn = compileFunction(id);
|
const fn = compileFunction(id);
|
||||||
fn(this.exports, requireFn, this, process, internalBinding);
|
fn(this.exports, requireFn, this, process, internalBinding);
|
||||||
|
|
||||||
if (config.experimentalModules && this.canBeRequiredByUsers) {
|
if (experimentalModules && this.canBeRequiredByUsers) {
|
||||||
this.proxifyExports();
|
this.proxifyExports();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/node.cc
13
src/node.cc
@ -701,7 +701,12 @@ void RunBootstrapping(Environment* env) {
|
|||||||
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
|
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
|
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
|
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "debugBreak")};
|
// --inspect-brk-node
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "debugBreak"),
|
||||||
|
// --experimental-modules
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "experimentalModules"),
|
||||||
|
// --expose-internals
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "exposeInternals")};
|
||||||
std::vector<Local<Value>> loaders_args = {
|
std::vector<Local<Value>> loaders_args = {
|
||||||
process,
|
process,
|
||||||
env->NewFunctionTemplate(binding::GetBinding)
|
env->NewFunctionTemplate(binding::GetBinding)
|
||||||
@ -714,7 +719,11 @@ void RunBootstrapping(Environment* env) {
|
|||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked(),
|
.ToLocalChecked(),
|
||||||
Boolean::New(isolate,
|
Boolean::New(isolate,
|
||||||
env->options()->debug_options().break_node_first_line)};
|
env->options()->debug_options().break_node_first_line),
|
||||||
|
Boolean::New(isolate,
|
||||||
|
env->options()->experimental_modules),
|
||||||
|
Boolean::New(isolate,
|
||||||
|
env->options()->expose_internals)};
|
||||||
|
|
||||||
MaybeLocal<Value> loader_exports;
|
MaybeLocal<Value> loader_exports;
|
||||||
// Bootstrap internal loaders
|
// Bootstrap internal loaders
|
||||||
|
Loading…
x
Reference in New Issue
Block a user