summaryrefslogtreecommitdiff
path: root/lib/internal/process
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-18 12:25:57 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-28 14:46:23 +0800
commit2b24ffae2240163a74ae11e49ee198e98abb07dc (patch)
treef6abfd48eba3b21e722dd96e0ede245d50d28035 /lib/internal/process
parent31b3dd28429df7ea7ebc84bdfaf8d9eb9e417b41 (diff)
downloadandroid-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.tar.gz
android-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.tar.bz2
android-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.zip
lib: print to stdout/stderr directly instead of using console
This patch adds an internal function that prints to stdout or stderr by directly writing to the known file descriptor, and uses it internally in common cases to avoid the overhead of the console implementation. PR-URL: https://github.com/nodejs/node/pull/27320 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/process')
-rw-r--r--lib/internal/process/execution.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js
index addd450ed3..93855ddbfc 100644
--- a/lib/internal/process/execution.js
+++ b/lib/internal/process/execution.js
@@ -35,26 +35,24 @@ function tryGetCwd() {
}
}
-function evalModule(source, print) {
- const { log, error } = require('internal/console/global');
+function evalModule(source, printResult) {
const { decorateErrorStack } = require('internal/util');
const asyncESM = require('internal/process/esm_loader');
+ const { kStdout, kStderr, print } = require('internal/util/print');
asyncESM.loaderPromise.then(async (loader) => {
const { result } = await loader.eval(source);
- if (print) {
- log(result);
- }
+ if (printResult) { print(kStdout, result); }
})
.catch((e) => {
decorateErrorStack(e);
- error(e);
+ print(kStderr, e);
process.exit(1);
});
// Handle any nextTicks added in the first tick of the program.
process._tickCallback();
}
-function evalScript(name, body, breakFirstLine, print) {
+function evalScript(name, body, breakFirstLine, printResult) {
const CJSModule = require('internal/modules/cjs/loader');
const { kVmBreakFirstLineSymbol } = require('internal/util');
@@ -79,9 +77,9 @@ function evalScript(name, body, breakFirstLine, print) {
[kVmBreakFirstLineSymbol]: ${!!breakFirstLine}
});\n`;
const result = module._compile(script, `${name}-wrapper`);
- if (print) {
- const { log } = require('internal/console/global');
- log(result);
+ if (printResult) {
+ const { kStdout, print } = require('internal/util/print');
+ print(kStdout, result);
}
// Handle any nextTicks added in the first tick of the program.
process._tickCallback();