diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-10-10 13:52:18 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-10-10 14:15:44 -0700 |
commit | 2c25507b81a18ab927071f8383fb73f65e7453d3 (patch) | |
tree | 397863b6a4da89979f31c982a911e2d0df784371 | |
parent | 6b9f5599849045a1f07cc9b9aca23d7a02aa5260 (diff) | |
download | node-new-2c25507b81a18ab927071f8383fb73f65e7453d3.tar.gz |
process.stderr goes through libuv now
This commit removes one assert from test-console.js in which we check that
process.stderr.write returns true. In the case of a dump to a file we cannot
guarantee this any longer now that it goes through fs.WriteStream.
-rw-r--r-- | src/node.js | 119 | ||||
-rw-r--r-- | test/simple/test-console.js | 2 | ||||
-rw-r--r-- | test/simple/test-module-load-list.js | 13 |
3 files changed, 72 insertions, 62 deletions
diff --git a/src/node.js b/src/node.js index 9e6c77dae0..06936bc32a 100644 --- a/src/node.js +++ b/src/node.js @@ -212,73 +212,74 @@ }; }; - startup.processStdio = function() { - var stdout, stdin; - - process.__defineGetter__('stdout', function() { - if (stdout) return stdout; - - var tty_wrap = process.binding('tty_wrap'); - var fd = 1; - - // Note stdout._type is used for test-module-load-list.js - - switch (tty_wrap.guessHandleType(fd)) { - case 'TTY': - var tty = NativeModule.require('tty'); - stdout = new tty.WriteStream(fd); - stdout._type = 'tty'; - - // Hack to have stdout not keep the event loop alive. - // See https://github.com/joyent/node/issues/1726 - if (stdout._handle && stdout._handle.unref) { - stdout._handle.unref(); - } - break; + function createWritableStdioStream(fd) { + var stream; + var 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 = NativeModule.require('tty'); + stream = new tty.WriteStream(fd); + stream._type = 'tty'; + + // Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + case 'FILE': + var fs = NativeModule.require('fs'); + stream = new fs.WriteStream(null, { fd: fd }); + stream._type = 'fs'; + break; + + case 'PIPE': + var net = NativeModule.require('net'); + stream = new net.Stream(fd); + + // FIXME Should probably have an option in net.Stream to create a + // stream from an existing fd which is writable only. But for now + // we'll just add this hack and set the `readable` member to false. + // Test: ./node test/fixtures/echo.js < /etc/passwd + stream.readable = false; + stream._type = 'pipe'; + + // FIXME Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; - case 'FILE': - var fs = NativeModule.require('fs'); - stdout = new fs.WriteStream(null, {fd: fd}); - stdout._type = 'fs'; - break; + default: + // Probably an error on in uv_guess_handle() + throw new Error('Implement me. Unknown stream file type!'); + } - case 'PIPE': - var net = NativeModule.require('net'); - stdout = new net.Stream(fd); - - // FIXME Should probably have an option in net.Stream to create a - // stream from an existing fd which is writable only. But for now - // we'll just add this hack and set the `readable` member to false. - // Test: ./node test/fixtures/echo.js < /etc/passwd - stdout.readable = false; - stdout._type = 'pipe'; - - // FIXME Hack to have stdout not keep the event loop alive. - // See https://github.com/joyent/node/issues/1726 - if (stdout._handle && stdout._handle.unref) { - stdout._handle.unref(); - } - break; + // For supporting legacy API we put the FD here. + stream.fd = fd; - default: - // Probably an error on in uv_guess_handle() - throw new Error('Implement me. Unknown stdout file type!'); - } + return stream; + } - // For supporting legacy API we put the FD here. - stdout.fd = fd; + startup.processStdio = function() { + var stdin, stdout, stderr; + process.__defineGetter__('stdout', function() { + if (stdout) return stdout; + stdout = createWritableStdioStream(1); return stdout; }); - var stderr = process.stderr = new EventEmitter(); - stderr.writable = true; - stderr.readable = false; - stderr.write = process.binding('stdio').writeError; - stderr.end = stderr.destroy = stderr.destroySoon = function() { }; - // For supporting legacy API we put the FD here. - // XXX this could break things if anyone ever closes this stream? - stderr.fd = 2; + process.__defineGetter__('stderr', function() { + if (stderr) return stderr; + stderr = createWritableStdioStream(2); + return stderr; + }); process.__defineGetter__('stdin', function() { if (stdin) return stdin; diff --git a/test/simple/test-console.js b/test/simple/test-console.js index fd4494dca4..0fba724ccf 100644 --- a/test/simple/test-console.js +++ b/test/simple/test-console.js @@ -49,4 +49,4 @@ assert.equal('foo bar\n', strings.shift()); assert.equal('foo bar hop\n', strings.shift()); assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift()); -assert.equal(true, process.stderr.write('hello world')); +process.stderr.write('hello world'); diff --git a/test/simple/test-module-load-list.js b/test/simple/test-module-load-list.js index b57795ef79..a6e17c5dd2 100644 --- a/test/simple/test-module-load-list.js +++ b/test/simple/test-module-load-list.js @@ -30,7 +30,14 @@ function assertEqual(x, y) { function checkExpected() { var toCompare = Math.max(expected.length, process.moduleLoadList.length); for (var i = 0; i < toCompare; i++) { - assertEqual(expected[i], process.moduleLoadList[i]); + if (expected[i] !== process.moduleLoadList[i]) { + console.error("process.moduleLoadList[" + i + "] = " + process.moduleLoadList[i]); + console.error("expected[" + i + "] = " + expected[i]); + + console.error("process.moduleLoadList", process.moduleLoadList); + console.error("expected = ", expected); + throw new Error("mismatch"); + } } } @@ -42,7 +49,6 @@ var expected = [ 'Binding buffer', 'NativeModule assert', 'NativeModule util', - 'Binding stdio', 'NativeModule path', 'NativeModule module', 'NativeModule fs', @@ -78,6 +84,7 @@ if (!process.features.uv) { case 'fs': expected = expected.concat([ 'NativeModule console', + 'Binding stdio', 'Binding tty_wrap' ]); break; @@ -85,6 +92,7 @@ if (!process.features.uv) { case 'tty': expected = expected.concat([ 'NativeModule console', + 'Binding stdio', 'Binding tty_wrap', 'NativeModule tty_uv', 'NativeModule net_uv', @@ -97,6 +105,7 @@ if (!process.features.uv) { case 'pipe': expected = expected.concat([ 'NativeModule console', + 'Binding stdio', 'Binding tty_wrap', 'NativeModule net_uv', 'NativeModule timers_uv', |