Skip to content

Commit 37ba201

Browse files
committed
src,lib: prefer internal/options over process._foo
This addresses a couple `TODO` comments and allows us to remove a number of underscored properties from `process` (in a semver-major follow-up). PR-URL: #25063 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b1500d9 commit 37ba201

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

lib/internal/bootstrap/node.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const {
3030
const { internalBinding, NativeModule } = loaderExports;
3131

3232
const exceptionHandlerState = { captureFn: null };
33+
let getOptionValue;
3334

3435
function startup() {
3536
setupTraceCategoryState();
@@ -105,7 +106,7 @@ function startup() {
105106
NativeModule.require('internal/inspector_async_hook').setup();
106107
}
107108

108-
const { getOptionValue } = NativeModule.require('internal/options');
109+
getOptionValue = NativeModule.require('internal/options').getOptionValue;
109110

110111
if (getOptionValue('--help')) {
111112
NativeModule.require('internal/print_help').print(process.stdout);
@@ -265,8 +266,7 @@ function startExecution() {
265266
}
266267

267268
// `node --prof-process`
268-
// TODO(joyeecheung): use internal/options instead of process.profProcess
269-
if (process.profProcess) {
269+
if (getOptionValue('--prof-process')) {
270270
NativeModule.require('internal/v8_prof_processor');
271271
return;
272272
}
@@ -288,13 +288,12 @@ function prepareUserCodeExecution() {
288288
}
289289

290290
// For user code, we preload modules if `-r` is passed
291-
// TODO(joyeecheung): use internal/options instead of
292-
// process._preload_modules
293-
if (process._preload_modules) {
291+
const preloadModules = getOptionValue('--require');
292+
if (preloadModules) {
294293
const {
295294
_preloadModules
296295
} = NativeModule.require('internal/modules/cjs/loader');
297-
_preloadModules(process._preload_modules);
296+
_preloadModules(preloadModules);
298297
}
299298
}
300299

@@ -303,14 +302,12 @@ function executeUserCode() {
303302
// `--interactive`.
304303
// Note that the name `forceRepl` is merely an alias of `interactive`
305304
// in code.
306-
// TODO(joyeecheung): use internal/options instead of
307-
// process._eval/process._forceRepl
308-
if (process._eval != null && !process._forceRepl) {
305+
if (getOptionValue('[has_eval_string]') && !getOptionValue('--interactive')) {
309306
const {
310307
addBuiltinLibsToObject
311308
} = NativeModule.require('internal/modules/cjs/helpers');
312309
addBuiltinLibsToObject(global);
313-
evalScript('[eval]', wrapForBreakOnFirstLine(process._eval));
310+
evalScript('[eval]', wrapForBreakOnFirstLine(getOptionValue('--eval')));
314311
return;
315312
}
316313

@@ -324,9 +321,7 @@ function executeUserCode() {
324321

325322
// If user passed `-c` or `--check` arguments to Node, check its syntax
326323
// instead of actually running the file.
327-
// TODO(joyeecheung): use internal/options instead of
328-
// process._syntax_check_only
329-
if (process._syntax_check_only != null) {
324+
if (getOptionValue('--check')) {
330325
const fs = NativeModule.require('fs');
331326
// Read the source.
332327
const filename = CJSModule._resolveFilename(process.argv[1]);
@@ -682,7 +677,7 @@ function evalScript(name, body) {
682677
`${JSON.stringify(body)}, { filename: ` +
683678
`${JSON.stringify(name)}, displayErrors: true });\n`;
684679
const result = module._compile(script, `${name}-wrapper`);
685-
if (process._print_eval) console.log(result);
680+
if (getOptionValue('--print')) console.log(result);
686681
// Handle any nextTicks added in the first tick of the program.
687682
process._tickCallback();
688683
}

src/node.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ void SetupProcessObject(Environment* env,
10021002
GetParentProcessId).FromJust());
10031003

10041004
// -e, --eval
1005+
// TODO(addaleax): Remove this.
10051006
if (env->options()->has_eval_string) {
10061007
READONLY_PROPERTY(process,
10071008
"_eval",
@@ -1012,23 +1013,27 @@ void SetupProcessObject(Environment* env,
10121013
}
10131014

10141015
// -p, --print
1016+
// TODO(addaleax): Remove this.
10151017
if (env->options()->print_eval) {
10161018
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
10171019
}
10181020

10191021
// -c, --check
1022+
// TODO(addaleax): Remove this.
10201023
if (env->options()->syntax_check_only) {
10211024
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
10221025
}
10231026

10241027
// -i, --interactive
1028+
// TODO(addaleax): Remove this.
10251029
if (env->options()->force_repl) {
10261030
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
10271031
}
10281032

10291033
// -r, --require
1030-
std::vector<std::string> preload_modules =
1031-
std::move(env->options()->preload_modules);
1034+
// TODO(addaleax): Remove this.
1035+
const std::vector<std::string>& preload_modules =
1036+
env->options()->preload_modules;
10321037
if (!preload_modules.empty()) {
10331038
Local<Array> array = Array::New(env->isolate());
10341039
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
@@ -1041,8 +1046,6 @@ void SetupProcessObject(Environment* env,
10411046
READONLY_PROPERTY(process,
10421047
"_preload_modules",
10431048
array);
1044-
1045-
preload_modules.clear();
10461049
}
10471050

10481051
// --no-deprecation
@@ -1071,6 +1074,7 @@ void SetupProcessObject(Environment* env,
10711074
#endif // NODE_NO_BROWSER_GLOBALS
10721075

10731076
// --prof-process
1077+
// TODO(addaleax): Remove this.
10741078
if (env->options()->prof_process) {
10751079
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
10761080
}

0 commit comments

Comments
 (0)