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,