From b5e9bb9e6a270d2d16081d54a2ed573bc714702b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 7 Sep 2016 14:40:18 -0700 Subject: [PATCH 1/3] Add spec for accessing process.stdin --- spec/node-spec.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/spec/node-spec.js b/spec/node-spec.js index 9382c4c9154b..87903bbfb8c8 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -221,12 +221,16 @@ describe('node feature', function () { }) describe('process.stdout', function () { - it('should not throw exception', function () { - process.stdout + it('does not throw an exception when accessed', function () { + assert.doesNotThrow(function () { + process.stdout + }) }) - it('should not throw exception when calling write()', function () { - process.stdout.write('test') + it('does not throw an exception when calling write()', function () { + assert.doesNotThrow(function () { + process.stdout.write('test') + }) }) it('should have isTTY defined', function () { @@ -236,6 +240,20 @@ describe('node feature', function () { }) }) + describe('process.stdin', function () { + it('does not throw an exception when accessed', function () { + assert.doesNotThrow(function () { + process.stdin + }) + }) + + it('does not throw an exception when calling read()', function () { + assert.doesNotThrow(function () { + assert.equal(process.stdin.read(), null) + }) + }) + }) + describe('process.version', function () { it('should not have -pre', function () { assert(!process.version.endsWith('-pre')) From 28b33074cf7355b3de2f84cdf9c1d064566402e7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 7 Sep 2016 14:45:56 -0700 Subject: [PATCH 2/3] Setup stdin in both processes on Windows --- lib/browser/init.js | 8 -------- lib/common/init.js | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/browser/init.js b/lib/browser/init.js index f7619fd17ba8..6ff328830e59 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -39,14 +39,6 @@ if (process.platform === 'win32') { } console.log = console.error = console.warn = consoleLog process.stdout.write = process.stderr.write = streamWrite - - // Always returns EOF for stdin stream. - var Readable = require('stream').Readable - var stdin = new Readable() - stdin.push(null) - process.__defineGetter__('stdin', function () { - return stdin - }) } // Don't quit on fatal error. diff --git a/lib/common/init.js b/lib/common/init.js index 257249f0a639..0ffd97a7c539 100644 --- a/lib/common/init.js +++ b/lib/common/init.js @@ -38,11 +38,21 @@ if (process.type === 'browser') { global.setInterval = wrapWithActivateUvLoop(timers.setInterval) } -// If we're running as a Windows Store app, __dirname will be set -// to C:/Program Files/WindowsApps. -// -// Nobody else get's to install there, changing the path is forbidden -// We can therefore say that we're running as appx -if (process.platform === 'win32' && __dirname.indexOf('\\Program Files\\WindowsApps\\') === 2) { - process.windowsStore = true +if (process.platform === 'win32') { + // Always returns EOF for stdin stream. + const {Readable} = require('stream') + const stdin = new Readable() + stdin.push(null) + process.__defineGetter__('stdin', function () { + return stdin + }) + + // If we're running as a Windows Store app, __dirname will be set + // to C:/Program Files/WindowsApps. + // + // Nobody else get's to install there, changing the path is forbidden + // We can therefore say that we're running as appx + if (__dirname.indexOf('\\Program Files\\WindowsApps\\') === 2) { + process.windowsStore = true + } } From d76c970da62cdee59df6da0159742ad65e3d6643 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 7 Sep 2016 14:51:05 -0700 Subject: [PATCH 3/3] Assert read value instead of exception --- spec/node-spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/node-spec.js b/spec/node-spec.js index 87903bbfb8c8..6d83b5ee483f 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -247,10 +247,8 @@ describe('node feature', function () { }) }) - it('does not throw an exception when calling read()', function () { - assert.doesNotThrow(function () { - assert.equal(process.stdin.read(), null) - }) + it('returns null when read from', function () { + assert.equal(process.stdin.read(), null) }) })