Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,lib: prefer internal/options over process._foo #25063

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
const { internalBinding, NativeModule } = loaderExports;

const exceptionHandlerState = { captureFn: null };
let getOptionValue;

function startup() {
setupTraceCategoryState();
Expand Down Expand Up @@ -105,7 +106,7 @@ function startup() {
NativeModule.require('internal/inspector_async_hook').setup();
}

const { getOptionValue } = NativeModule.require('internal/options');
getOptionValue = NativeModule.require('internal/options').getOptionValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep the same extraction method as before with:

({ getOptionValue } = NativeModule.require('internal/options'));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex I thought about it but thought this was maybe easier to read without the parenthesis? If you’d prefer this, I’d be totally okay with that too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind either way, was just throwing that out there.


if (getOptionValue('--help')) {
NativeModule.require('internal/print_help').print(process.stdout);
Expand Down Expand Up @@ -241,8 +242,7 @@ function startExecution() {
}

// `node --prof-process`
// TODO(joyeecheung): use internal/options instead of process.profProcess
if (process.profProcess) {
if (getOptionValue('--prof-process')) {
NativeModule.require('internal/v8_prof_processor');
return;
}
Expand All @@ -264,13 +264,12 @@ function prepareUserCodeExecution() {
}

// For user code, we preload modules if `-r` is passed
// TODO(joyeecheung): use internal/options instead of
// process._preload_modules
if (process._preload_modules) {
const preloadModules = getOptionValue('--require');
if (preloadModules) {
const {
_preloadModules
} = NativeModule.require('internal/modules/cjs/loader');
_preloadModules(process._preload_modules);
_preloadModules(preloadModules);
}
}

Expand All @@ -279,14 +278,12 @@ function executeUserCode() {
// `--interactive`.
// Note that the name `forceRepl` is merely an alias of `interactive`
// in code.
// TODO(joyeecheung): use internal/options instead of
// process._eval/process._forceRepl
if (process._eval != null && !process._forceRepl) {
if (getOptionValue('[has_eval_string]') && !getOptionValue('--interactive')) {
const {
addBuiltinLibsToObject
} = NativeModule.require('internal/modules/cjs/helpers');
addBuiltinLibsToObject(global);
evalScript('[eval]', wrapForBreakOnFirstLine(process._eval));
evalScript('[eval]', wrapForBreakOnFirstLine(getOptionValue('--eval')));
return;
}

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

// If user passed `-c` or `--check` arguments to Node, check its syntax
// instead of actually running the file.
// TODO(joyeecheung): use internal/options instead of
// process._syntax_check_only
if (process._syntax_check_only != null) {
if (getOptionValue('--check')) {
const fs = NativeModule.require('fs');
// Read the source.
const filename = CJSModule._resolveFilename(process.argv[1]);
Expand Down Expand Up @@ -668,7 +663,7 @@ function evalScript(name, body) {
`${JSON.stringify(body)}, { filename: ` +
`${JSON.stringify(name)}, displayErrors: true });\n`;
const result = module._compile(script, `${name}-wrapper`);
if (process._print_eval) console.log(result);
if (getOptionValue('--print')) console.log(result);
// Handle any nextTicks added in the first tick of the program.
process._tickCallback();
}
Expand Down
12 changes: 8 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ void SetupProcessObject(Environment* env,
GetParentProcessId).FromJust());

// -e, --eval
// TODO(addaleax): Remove this.
if (env->options()->has_eval_string) {
READONLY_PROPERTY(process,
"_eval",
Expand All @@ -1022,23 +1023,27 @@ void SetupProcessObject(Environment* env,
}

// -p, --print
// TODO(addaleax): Remove this.
if (env->options()->print_eval) {
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
}

// -c, --check
// TODO(addaleax): Remove this.
if (env->options()->syntax_check_only) {
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
}

// -i, --interactive
// TODO(addaleax): Remove this.
if (env->options()->force_repl) {
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
}

// -r, --require
std::vector<std::string> preload_modules =
std::move(env->options()->preload_modules);
// TODO(addaleax): Remove this.
const std::vector<std::string>& preload_modules =
env->options()->preload_modules;
if (!preload_modules.empty()) {
Local<Array> array = Array::New(env->isolate());
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
Expand All @@ -1051,8 +1056,6 @@ void SetupProcessObject(Environment* env,
READONLY_PROPERTY(process,
"_preload_modules",
array);

preload_modules.clear();
}

// --no-deprecation
Expand Down Expand Up @@ -1081,6 +1084,7 @@ void SetupProcessObject(Environment* env,
#endif // NODE_NO_BROWSER_GLOBALS

// --prof-process
// TODO(addaleax): Remove this.
if (env->options()->prof_process) {
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
}
Expand Down