Created
November 10, 2011 22:51
-
-
Save igorzi/1356530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 13324bf844d4527e91cf3777d3010aa4dca5f365 Mon Sep 17 00:00:00 2001 | |
From: Igor Zinkovsky <igorzi@microsoft.com> | |
Date: Thu, 10 Nov 2011 14:51:16 -0800 | |
Subject: [PATCH] throw from stdout.end and stderr.end | |
--- | |
lib/stream.js | 2 +- | |
src/node.js | 10 ++++++++-- | |
test/simple/test-tty-stdout-end.js | 19 ++++++++++--------- | |
3 files changed, 19 insertions(+), 12 deletions(-) | |
diff --git a/lib/stream.js b/lib/stream.js | |
index 530b087..fa45b8b 100644 | |
--- a/lib/stream.js | |
+++ b/lib/stream.js | |
@@ -54,7 +54,7 @@ Stream.prototype.pipe = function(dest, options) { | |
// If the 'end' option is not supplied, dest.end() will be called when | |
// source gets the 'end' or 'close' events. Only dest.end() once, and | |
// only when all sources have ended. | |
- if (!options || options.end !== false) { | |
+ if (!dest._isStdio && (!options || options.end !== false)) { | |
dest._pipeCount = dest._pipeCount || 0; | |
dest._pipeCount++; | |
diff --git a/src/node.js b/src/node.js | |
index f24a92e..2d409eb 100644 | |
--- a/src/node.js | |
+++ b/src/node.js | |
@@ -269,6 +269,8 @@ | |
// For supporting legacy API we put the FD here. | |
stream.fd = fd; | |
+ stream._isStdio = true; | |
+ | |
return stream; | |
} | |
@@ -278,14 +280,18 @@ | |
process.__defineGetter__('stdout', function() { | |
if (stdout) return stdout; | |
stdout = createWritableStdioStream(1); | |
- stdout.end = stdout.destroy = stdout.destroySoon = function() { }; | |
+ stdout.end = stdout.destroy = stdout.destroySoon = function() { | |
+ throw new Error('process.stdout cannot be closed'); | |
+ }; | |
return stdout; | |
}); | |
process.__defineGetter__('stderr', function() { | |
if (stderr) return stderr; | |
stderr = createWritableStdioStream(2); | |
- stderr.end = stderr.destroy = stderr.destroySoon = function() { }; | |
+ stderr.end = stderr.destroy = stderr.destroySoon = function() { | |
+ throw new Error('process.stderr cannot be closed'); | |
+ }; | |
return stderr; | |
}); | |
diff --git a/test/simple/test-tty-stdout-end.js b/test/simple/test-tty-stdout-end.js | |
index c79e029..f09bf8a 100644 | |
--- a/test/simple/test-tty-stdout-end.js | |
+++ b/test/simple/test-tty-stdout-end.js | |
@@ -22,14 +22,15 @@ | |
// Can't test this when 'make test' doesn't assign a tty to the stdout. | |
var common = require('../common'); | |
var assert = require('assert'); | |
-var tty = require('tty'); | |
-var closed = false; | |
-process.stdout.on('close', function() { | |
- closed = true; | |
-}); | |
-process.on('exit', function() { | |
- assert.ok(closed); | |
-}); | |
+var exceptionCaught = false; | |
-process.stdout.end(); | |
+try { | |
+ process.stdout.end(); | |
+} catch(e) { | |
+ exceptionCaught = true; | |
+ assert.ok(common.isError(e)); | |
+ assert.equal('process.stdout cannot be closed', e.message); | |
+} | |
+ | |
+assert.ok(exceptionCaught); | |
-- | |
1.7.4.msysgit.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment