summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-05-14 16:00:54 -0700
committerJames M Snell <jasnell@gmail.com>2016-05-17 10:45:20 -0700
commitf856234ffaa10441545c3b6ce420b247a17c06cf (patch)
tree1becb08fec4beaeeefd38ce483dffd0141125ff1 /lib
parent42ede93d14838b062dfad870bb10f1606f55e2c2 (diff)
downloadandroid-node-v8-f856234ffaa10441545c3b6ce420b247a17c06cf.tar.gz
android-node-v8-f856234ffaa10441545c3b6ce420b247a17c06cf.tar.bz2
android-node-v8-f856234ffaa10441545c3b6ce420b247a17c06cf.zip
process: internal/process/stdio.js cleanup / modernization
Avoid using deprecated getter syntax plus other miscellaneous updates. PR-URL: https://github.com/nodejs/node/pull/6766 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/process/stdio.js56
1 files changed, 35 insertions, 21 deletions
diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js
index 55689069ff..cab1f10cd8 100644
--- a/lib/internal/process/stdio.js
+++ b/lib/internal/process/stdio.js
@@ -5,7 +5,7 @@ exports.setup = setupStdio;
function setupStdio() {
var stdin, stdout, stderr;
- process.__defineGetter__('stdout', function() {
+ function getStdout() {
if (stdout) return stdout;
stdout = createWritableStdioStream(1);
stdout.destroy = stdout.destroySoon = function(er) {
@@ -13,14 +13,12 @@ function setupStdio() {
stdout.emit('error', er);
};
if (stdout.isTTY) {
- process.on('SIGWINCH', function() {
- stdout._refreshSize();
- });
+ process.on('SIGWINCH', () => stdout._refreshSize());
}
return stdout;
- });
+ }
- process.__defineGetter__('stderr', function() {
+ function getStderr() {
if (stderr) return stderr;
stderr = createWritableStdioStream(2);
stderr.destroy = stderr.destroySoon = function(er) {
@@ -28,22 +26,20 @@ function setupStdio() {
stderr.emit('error', er);
};
if (stderr.isTTY) {
- process.on('SIGWINCH', function() {
- stderr._refreshSize();
- });
+ process.on('SIGWINCH', () => stderr._refreshSize());
}
return stderr;
- });
+ }
- process.__defineGetter__('stdin', function() {
+ function getStdin() {
if (stdin) return stdin;
- var tty_wrap = process.binding('tty_wrap');
- var fd = 0;
+ const tty_wrap = process.binding('tty_wrap');
+ const fd = 0;
switch (tty_wrap.guessHandleType(fd)) {
case 'TTY':
- var tty = require('tty');
+ const tty = require('tty');
stdin = new tty.ReadStream(fd, {
highWaterMark: 0,
readable: true,
@@ -52,13 +48,13 @@ function setupStdio() {
break;
case 'FILE':
- var fs = require('fs');
+ const fs = require('fs');
stdin = new fs.ReadStream(null, { fd: fd, autoClose: false });
break;
case 'PIPE':
case 'TCP':
- var net = require('net');
+ const net = require('net');
// It could be that process has been started with an IPC channel
// sitting on fd=0, in such case the pipe for this fd is already
@@ -100,7 +96,7 @@ function setupStdio() {
// if the user calls stdin.pause(), then we need to stop reading
// immediately, so that the process can close down.
- stdin.on('pause', function() {
+ stdin.on('pause', () => {
if (!stdin._handle)
return;
stdin._readableState.reading = false;
@@ -109,6 +105,24 @@ function setupStdio() {
});
return stdin;
+ }
+
+ Object.defineProperty(process, 'stdout', {
+ configurable: true,
+ enumerable: true,
+ get: getStdout
+ });
+
+ Object.defineProperty(process, 'stderr', {
+ configurable: true,
+ enumerable: true,
+ get: getStderr
+ });
+
+ Object.defineProperty(process, 'stdin', {
+ configurable: true,
+ enumerable: true,
+ get: getStdin
});
process.openStdin = function() {
@@ -119,26 +133,26 @@ function setupStdio() {
function createWritableStdioStream(fd) {
var stream;
- var tty_wrap = process.binding('tty_wrap');
+ const tty_wrap = process.binding('tty_wrap');
// Note stream._type is used for test-module-load-list.js
switch (tty_wrap.guessHandleType(fd)) {
case 'TTY':
- var tty = require('tty');
+ const tty = require('tty');
stream = new tty.WriteStream(fd);
stream._type = 'tty';
break;
case 'FILE':
- var fs = require('fs');
+ const fs = require('fs');
stream = new fs.SyncWriteStream(fd, { autoClose: false });
stream._type = 'fs';
break;
case 'PIPE':
case 'TCP':
- var net = require('net');
+ const net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,