Skip to content

Commit

Permalink
src: pass cli options to bootstrap/loaders.js lexically
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
joyeecheung authored and antsmartian committed Feb 7, 2019
1 parent e81c6c8 commit 9f2cbaf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::LoadEnvironment()
/* global process, getBinding, getLinkedBinding, getInternalBinding */
/* global debugBreak */
/* global debugBreak, experimentalModules, exposeInternals */

if (debugBreak)
debugger; // eslint-disable-line no-debugger
Expand Down Expand Up @@ -158,6 +158,11 @@ let internalBinding;
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
internalBinding('module_wrap').callbackMap = new WeakMap();

// Think of this as module.exports in this file even though it is not
// written in CommonJS style.
const loaderExports = { internalBinding, NativeModule };
const loaderId = 'internal/bootstrap/loaders';

// Set up NativeModule.
function NativeModule(id) {
this.filename = `${id}.js`;
Expand All @@ -167,6 +172,14 @@ function NativeModule(id) {
this.exportKeys = undefined;
this.loaded = false;
this.loading = false;
if (id === loaderId) {
// 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;
}
}

const {
Expand Down Expand Up @@ -340,7 +353,7 @@ NativeModule.prototype.compile = function() {
const fn = compileFunction(id);
fn(this.exports, requireFn, this, process, internalBinding);

if (config.experimentalModules && !NativeModule.isInternal(this.id)) {
if (experimentalModules && this.canBeRequiredByUsers) {
this.proxifyExports();
}

Expand Down
13 changes: 11 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,12 @@ void RunBootstrapping(Environment* env) {
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
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 = {
process,
env->NewFunctionTemplate(binding::GetBinding)
Expand All @@ -691,7 +696,11 @@ void RunBootstrapping(Environment* env) {
->GetFunction(context)
.ToLocalChecked(),
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;
// Bootstrap internal loaders
Expand Down

0 comments on commit 9f2cbaf

Please sign in to comment.