lib: use getOptionValue instead of process underscore aliases
This patch reduce usage of `process._breakFirstLine` and `process._eval` in the internals and use `getOptionValue('--inspect-brk')` and `getOptionValue('--eval')` instead wherever possible. PR-URL: https://github.com/nodejs/node/pull/27278 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
b66f01d903
commit
49ee010005
@ -6,6 +6,8 @@ const {
|
|||||||
prepareMainThreadExecution
|
prepareMainThreadExecution
|
||||||
} = require('internal/bootstrap/pre_execution');
|
} = require('internal/bootstrap/pre_execution');
|
||||||
|
|
||||||
|
const { getOptionValue } = require('internal/options');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
evalModule,
|
evalModule,
|
||||||
evalScript,
|
evalScript,
|
||||||
@ -16,9 +18,16 @@ prepareMainThreadExecution();
|
|||||||
markBootstrapComplete();
|
markBootstrapComplete();
|
||||||
|
|
||||||
readStdin((code) => {
|
readStdin((code) => {
|
||||||
|
// This is necessary for fork() and CJS module compilation.
|
||||||
|
// TODO(joyeecheung): pass this with something really internal.
|
||||||
process._eval = code;
|
process._eval = code;
|
||||||
if (require('internal/options').getOptionValue('--input-type') === 'module')
|
|
||||||
evalModule(process._eval);
|
const print = getOptionValue('--print');
|
||||||
|
if (getOptionValue('--input-type') === 'module')
|
||||||
|
evalModule(code, print);
|
||||||
else
|
else
|
||||||
evalScript('[stdin]', process._eval, process._breakFirstLine);
|
evalScript('[stdin]',
|
||||||
|
code,
|
||||||
|
getOptionValue('--inspect-brk'),
|
||||||
|
print);
|
||||||
});
|
});
|
||||||
|
@ -10,11 +10,17 @@ const { evalModule, evalScript } = require('internal/process/execution');
|
|||||||
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
|
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
|
||||||
|
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
const source = getOptionValue('--eval');
|
|
||||||
prepareMainThreadExecution();
|
prepareMainThreadExecution();
|
||||||
addBuiltinLibsToObject(global);
|
addBuiltinLibsToObject(global);
|
||||||
markBootstrapComplete();
|
markBootstrapComplete();
|
||||||
|
|
||||||
|
const source = getOptionValue('--eval');
|
||||||
|
const print = getOptionValue('--print');
|
||||||
if (getOptionValue('--input-type') === 'module')
|
if (getOptionValue('--input-type') === 'module')
|
||||||
evalModule(source);
|
evalModule(source, print);
|
||||||
else
|
else
|
||||||
evalScript('[eval]', source, process._breakFirstLine);
|
evalScript('[eval]',
|
||||||
|
source,
|
||||||
|
getOptionValue('--inspect-brk'),
|
||||||
|
print);
|
||||||
|
@ -13,10 +13,14 @@ const {
|
|||||||
|
|
||||||
const console = require('internal/console/global');
|
const console = require('internal/console/global');
|
||||||
|
|
||||||
|
const { getOptionValue } = require('internal/options');
|
||||||
|
|
||||||
prepareMainThreadExecution();
|
prepareMainThreadExecution();
|
||||||
|
|
||||||
|
markBootstrapComplete();
|
||||||
|
|
||||||
// --input-type flag not supported in REPL
|
// --input-type flag not supported in REPL
|
||||||
if (require('internal/options').getOptionValue('--input-type')) {
|
if (getOptionValue('--input-type')) {
|
||||||
// If we can't write to stderr, we'd like to make this a noop,
|
// If we can't write to stderr, we'd like to make this a noop,
|
||||||
// so use console.error.
|
// so use console.error.
|
||||||
console.error('Cannot specify --input-type for REPL');
|
console.error('Cannot specify --input-type for REPL');
|
||||||
@ -44,8 +48,10 @@ cliRepl.createInternalRepl(process.env, (err, repl) => {
|
|||||||
|
|
||||||
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
|
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
|
||||||
// evaluate the code in the current context.
|
// evaluate the code in the current context.
|
||||||
if (process._eval != null) {
|
const source = getOptionValue('--eval');
|
||||||
evalScript('[eval]', process._eval, process._breakFirstLine);
|
if (source != null) {
|
||||||
|
evalScript('[eval]',
|
||||||
|
source,
|
||||||
|
getOptionValue('--inspect-brk'),
|
||||||
|
getOptionValue('--print'));
|
||||||
}
|
}
|
||||||
|
|
||||||
markBootstrapComplete();
|
|
||||||
|
@ -680,7 +680,7 @@ Module.prototype.require = function(id) {
|
|||||||
// Resolved path to process.argv[1] will be lazily placed here
|
// Resolved path to process.argv[1] will be lazily placed here
|
||||||
// (needed for setting breakpoint when called with --inspect-brk)
|
// (needed for setting breakpoint when called with --inspect-brk)
|
||||||
var resolvedArgv;
|
var resolvedArgv;
|
||||||
|
let hasPausedEntry = false;
|
||||||
|
|
||||||
// Run the file contents in the correct scope or sandbox. Expose
|
// Run the file contents in the correct scope or sandbox. Expose
|
||||||
// the correct helper variables (require, module, exports) to
|
// the correct helper variables (require, module, exports) to
|
||||||
@ -736,7 +736,7 @@ Module.prototype._compile = function(content, filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var inspectorWrapper = null;
|
var inspectorWrapper = null;
|
||||||
if (process._breakFirstLine && process._eval == null) {
|
if (getOptionValue('--inspect-brk') && process._eval == null) {
|
||||||
if (!resolvedArgv) {
|
if (!resolvedArgv) {
|
||||||
// We enter the repl if we're not given a filename argument.
|
// We enter the repl if we're not given a filename argument.
|
||||||
if (process.argv[1]) {
|
if (process.argv[1]) {
|
||||||
@ -747,8 +747,8 @@ Module.prototype._compile = function(content, filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set breakpoint on module start
|
// Set breakpoint on module start
|
||||||
if (filename === resolvedArgv) {
|
if (!hasPausedEntry && filename === resolvedArgv) {
|
||||||
delete process._breakFirstLine;
|
hasPausedEntry = true;
|
||||||
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
|
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,14 @@ const {
|
|||||||
const { ModuleWrap } = internalBinding('module_wrap');
|
const { ModuleWrap } = internalBinding('module_wrap');
|
||||||
|
|
||||||
const { decorateErrorStack } = require('internal/util');
|
const { decorateErrorStack } = require('internal/util');
|
||||||
|
const { getOptionValue } = require('internal/options');
|
||||||
const assert = require('internal/assert');
|
const assert = require('internal/assert');
|
||||||
const resolvedPromise = SafePromise.resolve();
|
const resolvedPromise = SafePromise.resolve();
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
let hasPausedEntry = false;
|
||||||
|
|
||||||
/* A ModuleJob tracks the loading of a single Module, and the ModuleJobs of
|
/* A ModuleJob tracks the loading of a single Module, and the ModuleJobs of
|
||||||
* its dependencies, over time. */
|
* its dependencies, over time. */
|
||||||
class ModuleJob {
|
class ModuleJob {
|
||||||
@ -82,8 +85,8 @@ class ModuleJob {
|
|||||||
};
|
};
|
||||||
await addJobsToDependencyGraph(this);
|
await addJobsToDependencyGraph(this);
|
||||||
try {
|
try {
|
||||||
if (this.isMain && process._breakFirstLine) {
|
if (!hasPausedEntry && this.isMain && getOptionValue('--inspect-brk')) {
|
||||||
delete process._breakFirstLine;
|
hasPausedEntry = true;
|
||||||
const initWrapper = internalBinding('inspector').callAndPauseOnStart;
|
const initWrapper = internalBinding('inspector').callAndPauseOnStart;
|
||||||
initWrapper(this.module.instantiate, this.module);
|
initWrapper(this.module.instantiate, this.module);
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,13 +35,13 @@ function tryGetCwd() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function evalModule(source) {
|
function evalModule(source, print) {
|
||||||
const { log, error } = require('internal/console/global');
|
const { log, error } = require('internal/console/global');
|
||||||
const { decorateErrorStack } = require('internal/util');
|
const { decorateErrorStack } = require('internal/util');
|
||||||
const asyncESM = require('internal/process/esm_loader');
|
const asyncESM = require('internal/process/esm_loader');
|
||||||
asyncESM.loaderPromise.then(async (loader) => {
|
asyncESM.loaderPromise.then(async (loader) => {
|
||||||
const { result } = await loader.eval(source);
|
const { result } = await loader.eval(source);
|
||||||
if (require('internal/options').getOptionValue('--print')) {
|
if (print) {
|
||||||
log(result);
|
log(result);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -54,7 +54,7 @@ function evalModule(source) {
|
|||||||
process._tickCallback();
|
process._tickCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
function evalScript(name, body, breakFirstLine) {
|
function evalScript(name, body, breakFirstLine, print) {
|
||||||
const CJSModule = require('internal/modules/cjs/loader');
|
const CJSModule = require('internal/modules/cjs/loader');
|
||||||
const { kVmBreakFirstLineSymbol } = require('internal/util');
|
const { kVmBreakFirstLineSymbol } = require('internal/util');
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ function evalScript(name, body, breakFirstLine) {
|
|||||||
[kVmBreakFirstLineSymbol]: ${!!breakFirstLine}
|
[kVmBreakFirstLineSymbol]: ${!!breakFirstLine}
|
||||||
});\n`;
|
});\n`;
|
||||||
const result = module._compile(script, `${name}-wrapper`);
|
const result = module._compile(script, `${name}-wrapper`);
|
||||||
if (require('internal/options').getOptionValue('--print')) {
|
if (print) {
|
||||||
const { log } = require('internal/console/global');
|
const { log } = require('internal/console/global');
|
||||||
log(result);
|
log(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user