Browse Source

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.
v0.7.4-release
Ryan Dahl 13 years ago
parent
commit
2c25507b81
  1. 63
      src/node.js
  2. 2
      test/simple/test-console.js
  3. 13
      test/simple/test-module-load-list.js

63
src/node.js

@ -212,73 +212,74 @@
};
};
startup.processStdio = function() {
var stdout, stdin;
process.__defineGetter__('stdout', function() {
if (stdout) return stdout;
function createWritableStdioStream(fd) {
var stream;
var tty_wrap = process.binding('tty_wrap');
var fd = 1;
// Note stdout._type is used for test-module-load-list.js
// Note stream._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';
stream = new tty.WriteStream(fd);
stream._type = 'tty';
// Hack to have stdout not keep the event loop alive.
// Hack to have stream not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
if (stdout._handle && stdout._handle.unref) {
stdout._handle.unref();
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';
stream = new fs.WriteStream(null, { fd: fd });
stream._type = 'fs';
break;
case 'PIPE':
var net = NativeModule.require('net');
stdout = new net.Stream(fd);
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
stdout.readable = false;
stdout._type = 'pipe';
stream.readable = false;
stream._type = 'pipe';
// FIXME Hack to have stdout not keep the event loop alive.
// FIXME Hack to have stream not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
if (stdout._handle && stdout._handle.unref) {
stdout._handle.unref();
if (stream._handle && stream._handle.unref) {
stream._handle.unref();
}
break;
default:
// Probably an error on in uv_guess_handle()
throw new Error('Implement me. Unknown stdout file type!');
throw new Error('Implement me. Unknown stream file type!');
}
// For supporting legacy API we put the FD here.
stdout.fd = fd;
stream.fd = fd;
return stream;
}
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;

2
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');

13
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',

Loading…
Cancel
Save