Skip to content

Commit

Permalink
lib: delay access to CLI option to pre-execution
Browse files Browse the repository at this point in the history
CLI options should not be added through the config binding, instead
they are already available in the JS land via
`require('internal/options')`. Also CLI options in principle should
be processed in pre-execution instead of bootstrap scripts.

PR-URL: #30778
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
joyeecheung authored and BethGriggs committed Feb 6, 2020
1 parent 45b74fb commit abfb8c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 0 additions & 3 deletions lib/internal/bootstrap/loaders.js
Expand Up @@ -160,9 +160,6 @@ function NativeModule(id) {
this.loaded = false;
this.loading = false;
this.canBeRequiredByUsers = !id.startsWith('internal/');

if (id === 'wasi')
this.canBeRequiredByUsers = !!internalBinding('config').experimentalWasi;
}

// To be called during pre-execution when --expose-internals is on.
Expand Down
12 changes: 11 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Expand Up @@ -62,6 +62,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
initializeClusterIPC();

initializeDeprecations();
initializeWASI();
initializeCJSLoader();
initializeESMLoader();

Expand Down Expand Up @@ -400,6 +401,14 @@ function initializePolicy() {
}
}

function initializeWASI() {
if (getOptionValue('--experimental-wasi-unstable-preview0')) {
const { NativeModule } = require('internal/bootstrap/loaders');
const mod = NativeModule.map.get('wasi');
mod.canBeRequiredByUsers = true;
}
}

function initializeCJSLoader() {
const CJSLoader = require('internal/modules/cjs/loader');
CJSLoader.Module._initPaths();
Expand Down Expand Up @@ -466,5 +475,6 @@ module.exports = {
setupTraceCategoryState,
setupInspectorHooks,
initializeReport,
initializeCJSLoader
initializeCJSLoader,
initializeWASI
};
2 changes: 2 additions & 0 deletions lib/internal/main/worker_thread.js
Expand Up @@ -14,6 +14,7 @@ const {
setupWarningHandler,
setupDebugEnv,
initializeDeprecations,
initializeWASI,
initializeCJSLoader,
initializeESMLoader,
initializeFrozenIntrinsics,
Expand Down Expand Up @@ -109,6 +110,7 @@ port.on('message', (message) => {
require('internal/process/policy').setup(manifestSrc, manifestURL);
}
initializeDeprecations();
initializeWASI();
initializeCJSLoader();
initializeESMLoader();

Expand Down
8 changes: 4 additions & 4 deletions src/node_config.cc
Expand Up @@ -15,11 +15,14 @@ using v8::Number;
using v8::Object;
using v8::Value;

// The config binding is used to provide an internal view of compile or runtime
// The config binding is used to provide an internal view of compile time
// config options that are required internally by lib/*.js code. This is an
// alternative to dropping additional properties onto the process object as
// has been the practice previously in node.cc.

// Command line arguments are already accessible in the JS land via
// require('internal/options').getOptionValue('--some-option'). Do not add them
// here.
static void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
Expand Down Expand Up @@ -84,9 +87,6 @@ static void Initialize(Local<Object> target,

READONLY_PROPERTY(target, "hasCachedBuiltins",
v8::Boolean::New(isolate, native_module::has_code_cache));

if (env->options()->experimental_wasi)
READONLY_TRUE_PROPERTY(target, "experimentalWasi");
} // InitConfig

} // namespace node
Expand Down

0 comments on commit abfb8c1

Please sign in to comment.