diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-05-09 20:42:31 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-12-04 13:08:54 -0800 |
commit | ab6c09b177eca67755a4c1f1d4d35fab9d2bb5d4 (patch) | |
tree | 9086836cb18a09beeacc663387ab2c30b649824d /lib | |
parent | 54f8453ea1211e1a11280e337ffdfdb7bc8f4ff1 (diff) | |
download | android-node-v8-ab6c09b177eca67755a4c1f1d4d35fab9d2bb5d4.tar.gz android-node-v8-ab6c09b177eca67755a4c1f1d4d35fab9d2bb5d4.tar.bz2 android-node-v8-ab6c09b177eca67755a4c1f1d4d35fab9d2bb5d4.zip |
process: provide dummy stdio for non-console Windows apps
The only known condition where we could not provide appropriate
stdio streams so far were non-console Windows applications.
Since this issue has come up a few times in our issue tracker now,
switch to providing dummy streams for these cases instead.
If there are other valid cases in which `uv_guess_handle` fails,
and where there is a more sensible way to provide stdio,
we’ll probably still find out because the streams don’t work
properly either way.
Refs: https://github.com/nodejs/help/issues/1251
PR-URL: https://github.com/nodejs/node/pull/20640
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/errors.js | 3 | ||||
-rw-r--r-- | lib/internal/process/stdio.js | 28 |
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 0ed23a9438..f497a0d6e4 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -905,10 +905,7 @@ E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError); E('ERR_UNKNOWN_FILE_EXTENSION', 'Unknown file extension: %s', Error); E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); -E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type', Error); -// This should probably be a `TypeError`. -E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type', Error); E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. See https://github.com/nodejs/node/wiki/Intl', Error); diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js index b769ea2bca..224af28b0f 100644 --- a/lib/internal/process/stdio.js +++ b/lib/internal/process/stdio.js @@ -1,10 +1,5 @@ 'use strict'; -const { - ERR_UNKNOWN_STDIN_TYPE, - ERR_UNKNOWN_STREAM_TYPE -} = require('internal/errors').codes; - exports.setupProcessStdio = setupProcessStdio; exports.getMainThreadStdio = getMainThreadStdio; @@ -87,8 +82,11 @@ function getMainThreadStdio() { break; default: - // Probably an error on in uv_guess_handle() - throw new ERR_UNKNOWN_STDIN_TYPE(); + // Provide a dummy contentless input for e.g. non-console + // Windows applications. + const { Readable } = require('stream'); + stdin = new Readable({ read() {} }); + stdin.push(null); } // For supporting legacy API we put the FD here. @@ -123,6 +121,12 @@ function getMainThreadStdio() { return stdin; } + exports.resetStdioForTesting = function() { + stdin = undefined; + stdout = undefined; + stderr = undefined; + }; + return { getStdout, getStderr, @@ -199,8 +203,14 @@ function createWritableStdioStream(fd) { break; default: - // Probably an error on in uv_guess_handle() - throw new ERR_UNKNOWN_STREAM_TYPE(); + // Provide a dummy black-hole output for e.g. non-console + // Windows applications. + const { Writable } = require('stream'); + stream = new Writable({ + write(buf, enc, cb) { + cb(); + } + }); } // For supporting legacy API we put the FD here. |