Skip to content

Commit 8b57208

Browse files
addaleaxdanbev
authored andcommitted
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0461e4c commit 8b57208

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
@@ -29,6 +29,7 @@ const {
2929
const { internalBinding, NativeModule } = loaderExports;
3030

3131
const exceptionHandlerState = { captureFn: null };
32+
let getOptionValue;
3233

3334
function startup() {
3435
setupTraceCategoryState();
@@ -117,7 +118,7 @@ function startup() {
117118
NativeModule.require('internal/inspector_async_hook').setup();
118119
}
119120

120-
const { getOptionValue } = NativeModule.require('internal/options');
121+
getOptionValue = NativeModule.require('internal/options').getOptionValue;
121122

122123
if (getOptionValue('--help')) {
123124
NativeModule.require('internal/print_help').print(process.stdout);
@@ -253,8 +254,7 @@ function startExecution() {
253254
}
254255

255256
// `node --prof-process`
256-
// TODO(joyeecheung): use internal/options instead of process.profProcess
257-
if (process.profProcess) {
257+
if (getOptionValue('--prof-process')) {
258258
NativeModule.require('internal/v8_prof_processor');
259259
return;
260260
}
@@ -276,13 +276,12 @@ function prepareUserCodeExecution() {
276276
}
277277

278278
// For user code, we preload modules if `-r` is passed
279-
// TODO(joyeecheung): use internal/options instead of
280-
// process._preload_modules
281-
if (process._preload_modules) {
279+
const preloadModules = getOptionValue('--require');
280+
if (preloadModules) {
282281
const {
283282
_preloadModules
284283
} = NativeModule.require('internal/modules/cjs/loader');
285-
_preloadModules(process._preload_modules);
284+
_preloadModules(preloadModules);
286285
}
287286
}
288287

@@ -291,14 +290,12 @@ function executeUserCode() {
291290
// `--interactive`.
292291
// Note that the name `forceRepl` is merely an alias of `interactive`
293292
// in code.
294-
// TODO(joyeecheung): use internal/options instead of
295-
// process._eval/process._forceRepl
296-
if (process._eval != null && !process._forceRepl) {
293+
if (getOptionValue('[has_eval_string]') && !getOptionValue('--interactive')) {
297294
const {
298295
addBuiltinLibsToObject
299296
} = NativeModule.require('internal/modules/cjs/helpers');
300297
addBuiltinLibsToObject(global);
301-
evalScript('[eval]', wrapForBreakOnFirstLine(process._eval));
298+
evalScript('[eval]', wrapForBreakOnFirstLine(getOptionValue('--eval')));
302299
return;
303300
}
304301

@@ -312,9 +309,7 @@ function executeUserCode() {
312309

313310
// If user passed `-c` or `--check` arguments to Node, check its syntax
314311
// instead of actually running the file.
315-
// TODO(joyeecheung): use internal/options instead of
316-
// process._syntax_check_only
317-
if (process._syntax_check_only != null) {
312+
if (getOptionValue('--check')) {
318313
const fs = NativeModule.require('fs');
319314
// Read the source.
320315
const filename = CJSModule._resolveFilename(process.argv[1]);
@@ -661,7 +656,7 @@ function evalScript(name, body) {
661656
`${JSON.stringify(body)}, { filename: ` +
662657
`${JSON.stringify(name)}, displayErrors: true });\n`;
663658
const result = module._compile(script, `${name}-wrapper`);
664-
if (process._print_eval) console.log(result);
659+
if (getOptionValue('--print')) console.log(result);
665660
// Handle any nextTicks added in the first tick of the program.
666661
process._tickCallback();
667662
}

src/node.cc

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

976976
// -e, --eval
977+
// TODO(addaleax): Remove this.
977978
if (env->options()->has_eval_string) {
978979
READONLY_PROPERTY(process,
979980
"_eval",
@@ -984,23 +985,27 @@ void SetupProcessObject(Environment* env,
984985
}
985986

986987
// -p, --print
988+
// TODO(addaleax): Remove this.
987989
if (env->options()->print_eval) {
988990
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
989991
}
990992

991993
// -c, --check
994+
// TODO(addaleax): Remove this.
992995
if (env->options()->syntax_check_only) {
993996
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
994997
}
995998

996999
// -i, --interactive
1000+
// TODO(addaleax): Remove this.
9971001
if (env->options()->force_repl) {
9981002
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
9991003
}
10001004

10011005
// -r, --require
1002-
std::vector<std::string> preload_modules =
1003-
std::move(env->options()->preload_modules);
1006+
// TODO(addaleax): Remove this.
1007+
const std::vector<std::string>& preload_modules =
1008+
env->options()->preload_modules;
10041009
if (!preload_modules.empty()) {
10051010
Local<Array> array = Array::New(env->isolate());
10061011
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
@@ -1013,8 +1018,6 @@ void SetupProcessObject(Environment* env,
10131018
READONLY_PROPERTY(process,
10141019
"_preload_modules",
10151020
array);
1016-
1017-
preload_modules.clear();
10181021
}
10191022

10201023
// --no-deprecation
@@ -1043,6 +1046,7 @@ void SetupProcessObject(Environment* env,
10431046
#endif // NODE_NO_BROWSER_GLOBALS
10441047

10451048
// --prof-process
1049+
// TODO(addaleax): Remove this.
10461050
if (env->options()->prof_process) {
10471051
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
10481052
}

0 commit comments

Comments
 (0)