Skip to content

Commit 8f105f8

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).
1 parent 2c5dae5 commit 8f105f8

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

lib/internal/bootstrap/node.js

Lines changed: 10 additions & 15 deletions
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);
@@ -241,8 +242,7 @@ function startExecution() {
241242
}
242243

243244
// `node --prof-process`
244-
// TODO(joyeecheung): use internal/options instead of process.profProcess
245-
if (process.profProcess) {
245+
if (getOptionValue('--prof-process')) {
246246
NativeModule.require('internal/v8_prof_processor');
247247
return;
248248
}
@@ -264,13 +264,12 @@ function prepareUserCodeExecution() {
264264
}
265265

266266
// For user code, we preload modules if `-r` is passed
267-
// TODO(joyeecheung): use internal/options instead of
268-
// process._preload_modules
269-
if (process._preload_modules) {
267+
const preloadModules = getOptionValue('--require');
268+
if (preloadModules) {
270269
const {
271270
_preloadModules
272271
} = NativeModule.require('internal/modules/cjs/loader');
273-
_preloadModules(process._preload_modules);
272+
_preloadModules(preloadModules);
274273
}
275274
}
276275

@@ -279,14 +278,12 @@ function executeUserCode() {
279278
// `--interactive`.
280279
// Note that the name `forceRepl` is merely an alias of `interactive`
281280
// in code.
282-
// TODO(joyeecheung): use internal/options instead of
283-
// process._eval/process._forceRepl
284-
if (process._eval != null && !process._forceRepl) {
281+
if (getOptionValue('[has_eval_string]') && !getOptionValue('--interactive')) {
285282
const {
286283
addBuiltinLibsToObject
287284
} = NativeModule.require('internal/modules/cjs/helpers');
288285
addBuiltinLibsToObject(global);
289-
evalScript('[eval]', wrapForBreakOnFirstLine(process._eval));
286+
evalScript('[eval]', wrapForBreakOnFirstLine(getOptionValue('--eval')));
290287
return;
291288
}
292289

@@ -300,9 +297,7 @@ function executeUserCode() {
300297

301298
// If user passed `-c` or `--check` arguments to Node, check its syntax
302299
// instead of actually running the file.
303-
// TODO(joyeecheung): use internal/options instead of
304-
// process._syntax_check_only
305-
if (process._syntax_check_only != null) {
300+
if (getOptionValue('--check')) {
306301
const fs = NativeModule.require('fs');
307302
// Read the source.
308303
const filename = CJSModule._resolveFilename(process.argv[1]);
@@ -668,7 +663,7 @@ function evalScript(name, body) {
668663
`${JSON.stringify(body)}, { filename: ` +
669664
`${JSON.stringify(name)}, displayErrors: true });\n`;
670665
const result = module._compile(script, `${name}-wrapper`);
671-
if (process._print_eval) console.log(result);
666+
if (getOptionValue('--print')) console.log(result);
672667
// Handle any nextTicks added in the first tick of the program.
673668
process._tickCallback();
674669
}

src/node.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ void SetupProcessObject(Environment* env,
10121012
GetParentProcessId).FromJust());
10131013

10141014
// -e, --eval
1015+
// TODO(addaleax): Remove this.
10151016
if (env->options()->has_eval_string) {
10161017
READONLY_PROPERTY(process,
10171018
"_eval",
@@ -1022,23 +1023,27 @@ void SetupProcessObject(Environment* env,
10221023
}
10231024

10241025
// -p, --print
1026+
// TODO(addaleax): Remove this.
10251027
if (env->options()->print_eval) {
10261028
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
10271029
}
10281030

10291031
// -c, --check
1032+
// TODO(addaleax): Remove this.
10301033
if (env->options()->syntax_check_only) {
10311034
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
10321035
}
10331036

10341037
// -i, --interactive
1038+
// TODO(addaleax): Remove this.
10351039
if (env->options()->force_repl) {
10361040
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
10371041
}
10381042

10391043
// -r, --require
1040-
std::vector<std::string> preload_modules =
1041-
std::move(env->options()->preload_modules);
1044+
// TODO(addaleax): Remove this.
1045+
const std::vector<std::string>& preload_modules =
1046+
env->options()->preload_modules;
10421047
if (!preload_modules.empty()) {
10431048
Local<Array> array = Array::New(env->isolate());
10441049
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
@@ -1051,8 +1056,6 @@ void SetupProcessObject(Environment* env,
10511056
READONLY_PROPERTY(process,
10521057
"_preload_modules",
10531058
array);
1054-
1055-
preload_modules.clear();
10561059
}
10571060

10581061
// --no-deprecation
@@ -1081,6 +1084,7 @@ void SetupProcessObject(Environment* env,
10811084
#endif // NODE_NO_BROWSER_GLOBALS
10821085

10831086
// --prof-process
1087+
// TODO(addaleax): Remove this.
10841088
if (env->options()->prof_process) {
10851089
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
10861090
}

0 commit comments

Comments
 (0)