summaryrefslogtreecommitdiff
path: root/lib/internal/process
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-06 05:56:00 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-16 04:24:26 +0800
commita38e9c438ae872da37999c39d974facd4d524ea2 (patch)
treeafd23a9511e2e306760b71f1dabfdded92c8a25b /lib/internal/process
parent7938238b31f69d1a8bfa8069387cc2374435996c (diff)
downloadandroid-node-v8-a38e9c438ae872da37999c39d974facd4d524ea2.tar.gz
android-node-v8-a38e9c438ae872da37999c39d974facd4d524ea2.tar.bz2
android-node-v8-a38e9c438ae872da37999c39d974facd4d524ea2.zip
lib: require globals instead of using the global proxy
In addition, use process.stderr instead of console.error when there is no need to swallow the error. PR-URL: https://github.com/nodejs/node/pull/27112 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/process')
-rw-r--r--lib/internal/process/execution.js8
-rw-r--r--lib/internal/process/warning.js10
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js
index 7b651ba5d1..86f3ee5b5a 100644
--- a/lib/internal/process/execution.js
+++ b/lib/internal/process/execution.js
@@ -36,17 +36,18 @@ function tryGetCwd() {
}
function evalModule(source) {
+ const { log, error } = require('internal/console/global');
const { decorateErrorStack } = require('internal/util');
const asyncESM = require('internal/process/esm_loader');
asyncESM.loaderPromise.then(async (loader) => {
const { result } = await loader.eval(source);
if (require('internal/options').getOptionValue('--print')) {
- console.log(result);
+ log(result);
}
})
.catch((e) => {
decorateErrorStack(e);
- console.error(e);
+ error(e);
process.exit(1);
});
// Handle any nextTicks added in the first tick of the program.
@@ -79,7 +80,8 @@ function evalScript(name, body, breakFirstLine) {
});\n`;
const result = module._compile(script, `${name}-wrapper`);
if (require('internal/options').getOptionValue('--print')) {
- console.log(result);
+ const { log } = require('internal/console/global');
+ log(result);
}
// Handle any nextTicks added in the first tick of the program.
process._tickCallback();
diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js
index 71a2c4fa3a..3ad3d4b9fb 100644
--- a/lib/internal/process/warning.js
+++ b/lib/internal/process/warning.js
@@ -17,10 +17,14 @@ function lazyOption() {
return warningFile;
}
+// If we can't write to stderr, we'd like to make this a noop,
+// so use console.error.
+let error;
function writeOut(message) {
- if (console && typeof console.error === 'function')
- return console.error(message);
- process._rawDebug(message);
+ if (!error) {
+ error = require('internal/console/global').error;
+ }
+ error(message);
}
function writeToFile(message) {