Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
process.stderr goes through libuv now
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ry committed Oct 10, 2011
1 parent 6b9f559 commit 2c25507
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 62 deletions.
119 changes: 60 additions & 59 deletions src/node.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/simple/test-console.js
Expand Up @@ -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 changes: 11 additions & 2 deletions test/simple/test-module-load-list.js
Expand Up @@ -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");
}
}
}

Expand All @@ -42,7 +49,6 @@ var expected = [
'Binding buffer',
'NativeModule assert',
'NativeModule util',
'Binding stdio',
'NativeModule path',
'NativeModule module',
'NativeModule fs',
Expand Down Expand Up @@ -78,13 +84,15 @@ if (!process.features.uv) {
case 'fs':
expected = expected.concat([
'NativeModule console',
'Binding stdio',
'Binding tty_wrap'
]);
break;

case 'tty':
expected = expected.concat([
'NativeModule console',
'Binding stdio',
'Binding tty_wrap',
'NativeModule tty_uv',
'NativeModule net_uv',
Expand All @@ -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',
Expand Down

0 comments on commit 2c25507

Please sign in to comment.