Browse Source

Merge branch 'v0.10'

Conflicts:
	tools/test.py
v0.11.2-release
Bert Belder 12 years ago
parent
commit
bdc5881169
  1. 2
      README.md
  2. 4
      doc/about/index.html
  3. 8
      doc/api/child_process.markdown
  4. 4
      doc/api/stream.markdown
  5. 4
      doc/blog.html
  6. 17
      doc/blog/Uncategorized/version-0-6.md
  7. 2
      doc/changelog-foot.html
  8. 2
      doc/changelog-head.html
  9. 6
      doc/community/index.html
  10. 4
      doc/download/index.html
  11. 4
      doc/index.html
  12. 4
      doc/logos/index.html
  13. 4
      doc/template.html
  14. 3
      lib/_stream_readable.js
  15. 7
      lib/child_process.js
  16. 3
      test/pummel/test-net-many-clients.js
  17. 85
      test/simple/test-child-process-recv-handle.js
  18. 43
      test/simple/test-stream2-readable-wrap-empty.js
  19. 86
      test/simple/test-stream2-readable-wrap.js

2
README.md

@ -51,7 +51,7 @@ Resources for Newcomers
- [nodejs.org](http://nodejs.org/) - [nodejs.org](http://nodejs.org/)
- [how to install node.js and npm (node package manager)](http://joyeur.com/2010/12/10/installing-node-and-npm/) - [how to install node.js and npm (node package manager)](http://joyeur.com/2010/12/10/installing-node-and-npm/)
- [list of modules](https://github.com/joyent/node/wiki/modules) - [list of modules](https://github.com/joyent/node/wiki/modules)
- [searching the npm registry](http://search.npmjs.org/) - [searching the npm registry](http://npmjs.org/)
- [list of companies and projects using node](https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node) - [list of companies and projects using node](https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node)
- [node.js mailing list](http://groups.google.com/group/nodejs) - [node.js mailing list](http://groups.google.com/group/nodejs)
- irc chatroom, [#node.js on freenode.net](http://webchat.freenode.net?channels=node.js&uio=d4) - irc chatroom, [#node.js on freenode.net](http://webchat.freenode.net?channels=node.js&uio=d4)

4
doc/about/index.html

@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li> <li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about current">About</a></li> <li><a href="/about/" class="about current">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li> <li><a href="/community/" class="community">Community</a></li>
@ -116,7 +116,7 @@ console.log('Server running at http://127.0.0.1:1337/');</pre>
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/#download">Download</a></li> <li><a href="/#download">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

8
doc/api/child_process.markdown

@ -466,11 +466,6 @@ See also: `child_process.exec()` and `child_process.fork()`
* `command` {String} The command to run, with space-separated arguments * `command` {String} The command to run, with space-separated arguments
* `options` {Object} * `options` {Object}
* `cwd` {String} Current working directory of the child process * `cwd` {String} Current working directory of the child process
* `stdio` {Array|String} Child's stdio configuration. (See above)
Only stdin is configurable, anything else will lead to unpredictable
results.
* `customFds` {Array} **Deprecated** File descriptors for the child to use
for stdio. (See above)
* `env` {Object} Environment key-value pairs * `env` {Object} Environment key-value pairs
* `encoding` {String} (Default: 'utf8') * `encoding` {String} (Default: 'utf8')
* `timeout` {Number} (Default: 0) * `timeout` {Number} (Default: 0)
@ -524,9 +519,6 @@ the child process is killed.
* `args` {Array} List of string arguments * `args` {Array} List of string arguments
* `options` {Object} * `options` {Object}
* `cwd` {String} Current working directory of the child process * `cwd` {String} Current working directory of the child process
* `stdio` {Array|String} Child's stdio configuration. (See above)
* `customFds` {Array} **Deprecated** File descriptors for the child to use
for stdio. (See above)
* `env` {Object} Environment key-value pairs * `env` {Object} Environment key-value pairs
* `encoding` {String} (Default: 'utf8') * `encoding` {String} (Default: 'utf8')
* `timeout` {Number} (Default: 0) * `timeout` {Number} (Default: 0)

4
doc/api/stream.markdown

@ -549,6 +549,10 @@ Emitted when the stream's write queue empties and it's safe to write
without buffering again. Listen for it when `stream.write()` returns without buffering again. Listen for it when `stream.write()` returns
`false`. `false`.
### Event: 'error'
Emitted if there was an error receiving data.
### Event: 'close' ### Event: 'close'
Emitted when the underlying resource (for example, the backing file Emitted when the underlying resource (for example, the backing file

4
doc/blog.html

@ -86,7 +86,7 @@
<li><a href="http://nodejs.org/about/" class="about">About</a></li> <li><a href="http://nodejs.org/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm <li><a href="http://npmjs.org/" class="npm">npm
Registry</a></li> Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
@ -213,7 +213,7 @@
<li><a href="http://nodejs.org/">Node.js</a></li> <li><a href="http://nodejs.org/">Node.js</a></li>
<li><a href="http://nodejs.org/download/">Download</a></li> <li><a href="http://nodejs.org/download/">Download</a></li>
<li><a href="http://nodejs.org/about/">About</a></li> <li><a href="http://nodejs.org/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="http://nodejs.org/community/">Community</a></li> <li><a href="http://nodejs.org/community/">Community</a></li>

17
doc/blog/Uncategorized/version-0-6.md

@ -5,8 +5,19 @@ status: publish
category: Uncategorized category: Uncategorized
slug: version-0-6 slug: version-0-6
Version 0.6.0 will be released next week. Please spend some time this week upgrading your code to v0.5.10. Report any API differences at <a href="https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6">https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6</a> or report a bug to us at <a href="http://github.com/joyent/node/issues">http://github.com/joyent/node/issues</a> if you hit problems. Version 0.6.0 will be released next week. Please spend some time this
week upgrading your code to v0.5.10. Report any API differences at <a
href="https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6">https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6</a>
or report a bug to us at <a
href="http://github.com/joyent/node/issues">http://github.com/joyent/node/issues</a>
if you hit problems.
The API changes between v0.4.12 and v0.5.10 are 99% cosmetic, minor, and easy to fix. Most people are able to migrate their code in 10 minutes. Don't fear. The API changes between v0.4.12 and v0.5.10 are 99% cosmetic, minor,
and easy to fix. Most people are able to migrate their code in 10
minutes. Don't fear.
Once you've ported your code to v0.5.10 please help out by testing third party modules. Make bug reports. Encourage authors to publish new versions of their modules. Go through the list of modules at <a href="http://search.npmjs.org/">http://search.npmjs.org/</a> and try out random ones. This is especially encouraged of Windows users! Once you've ported your code to v0.5.10 please help out by testing
third party modules. Make bug reports. Encourage authors to publish
new versions of their modules. Go through the list of modules at <a
href="http://npmjs.org/">http://npmjs.org/</a> and try out random
ones. This is especially encouraged of Windows users!

2
doc/changelog-foot.html

@ -7,7 +7,7 @@
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li> <li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

2
doc/changelog-head.html

@ -19,7 +19,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li> <li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li> <li><a href="/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li> <li><a href="/community/" class="community">Community</a></li>

6
doc/community/index.html

@ -28,7 +28,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li> <li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li> <li><a href="/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community current">Community</a></li> <li><a href="/community/" class="community current">Community</a></li>
@ -93,7 +93,7 @@
Projects, Applications, and Companies Using Node</a> or the Projects, Applications, and Companies Using Node</a> or the
<a href="https://github.com/joyent/node/wiki/modules">very long <a href="https://github.com/joyent/node/wiki/modules">very long
list of Node modules</a>, many of which are published in the list of Node modules</a>, many of which are published in the
<a href="http://search.npmjs.org/">npm registry</a>. <a href="http://npmjs.org/">npm registry</a>.
</p> </p>
</div> </div>
</div> </div>
@ -223,7 +223,7 @@
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li> <li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

4
doc/download/index.html

@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download current">Download</a></li> <li><a href="/download/" class="download current">Download</a></li>
<li><a href="/about/" class="about">About</a></li> <li><a href="/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li> <li><a href="/community/" class="community">Community</a></li>
@ -162,7 +162,7 @@
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li> <li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

4
doc/index.html

@ -118,7 +118,7 @@ server.listen(1337, '127.0.0.1');</pre>
<h2>Explore Node.js</h2> <h2>Explore Node.js</h2>
<ul id="explore"> <ul id="explore">
<li><a href="about/" class="explore">About</a><br><span>Technical overview</span></li> <li><a href="about/" class="explore">About</a><br><span>Technical overview</span></li>
<li><a href="http://search.npmjs.org/" class="explore">npm Registry</a><br><span>Modules, resources and more</span></li> <li><a href="http://npmjs.org/" class="explore">npm Registry</a><br><span>Modules, resources and more</span></li>
<li><a href="http://nodejs.org/api/" class="explore">Documentation</a><br><span>API Specifications</span></li> <li><a href="http://nodejs.org/api/" class="explore">Documentation</a><br><span>API Specifications</span></li>
<li><a href="http://blog.nodejs.org" class="explore">Node.js Blog</a><br><span>Insight, perspective and events</span></li> <li><a href="http://blog.nodejs.org" class="explore">Node.js Blog</a><br><span>Insight, perspective and events</span></li>
<li><a href="community/" class="explore">Community</a><br><span>Mailing lists, blogs, and more</span></li> <li><a href="community/" class="explore">Community</a><br><span>Mailing lists, blogs, and more</span></li>
@ -134,7 +134,7 @@ server.listen(1337, '127.0.0.1');</pre>
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li> <li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

4
doc/logos/index.html

@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/#download" class="download">Download</a></li> <li><a href="/#download" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li> <li><a href="/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li> <li><a href="/community/" class="community">Community</a></li>
@ -68,7 +68,7 @@
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/#download">Download</a></li> <li><a href="/#download">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

4
doc/template.html

@ -19,7 +19,7 @@
<li><a href="/" class="home">Home</a></li> <li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li> <li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li> <li><a href="/about/" class="about">About</a></li>
<li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li> <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li> <li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li> <li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li> <li><a href="/community/" class="community">Community</a></li>
@ -58,7 +58,7 @@
<li><a href="/">Node.js</a></li> <li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li> <li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li> <li><a href="/about/">About</a></li>
<li><a href="http://search.npmjs.org/">npm Registry</a></li> <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li> <li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li> <li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li> <li><a href="/community/">Community</a></li>

3
lib/_stream_readable.js

@ -759,7 +759,6 @@ Readable.prototype.wrap = function(stream) {
if (chunk && chunk.length) if (chunk && chunk.length)
self.push(chunk); self.push(chunk);
} }
state.ended = true;
self.push(null); self.push(null);
}); });
@ -767,7 +766,7 @@ Readable.prototype.wrap = function(stream) {
stream.on('data', function(chunk) { stream.on('data', function(chunk) {
if (state.decoder) if (state.decoder)
chunk = state.decoder.write(chunk); chunk = state.decoder.write(chunk);
if (!chunk || !chunk.length) if (!chunk || !state.objectMode && !chunk.length)
return; return;
var ret = self.push(chunk); var ret = self.push(chunk);

7
lib/child_process.js

@ -336,8 +336,13 @@ function setupChannel(target, channel) {
var json = jsonBuffer.slice(start, i); var json = jsonBuffer.slice(start, i);
var message = JSON.parse(json); var message = JSON.parse(json);
// There will be at most one NODE_HANDLE message in every chunk we
// read because SCM_RIGHTS messages don't get coalesced. Make sure
// that we deliver the handle with the right message however.
if (message && message.cmd === 'NODE_HANDLE')
handleMessage(target, message, recvHandle); handleMessage(target, message, recvHandle);
recvHandle = undefined; else
handleMessage(target, message, undefined);
start = i + 1; start = i + 1;
} }

3
test/pummel/test-net-many-clients.js

@ -37,12 +37,11 @@ for (var i = 0; i < bytes; i++) {
} }
var server = net.createServer(function(c) { var server = net.createServer(function(c) {
c.on('connect', function() { console.log('connected');
total_connections++; total_connections++;
common.print('#'); common.print('#');
c.write(body); c.write(body);
c.end(); c.end();
});
}); });
function runClient(callback) { function runClient(callback) {

85
test/simple/test-child-process-recv-handle.js

@ -0,0 +1,85 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Test that a Linux specific quirk in the handle passing protocol is handled
// correctly. See https://github.com/joyent/node/issues/5330 for details.
var common = require('../common');
var assert = require('assert');
var net = require('net');
var spawn = require('child_process').spawn;
if (process.argv[2] === 'worker')
worker();
else
master();
function master() {
// spawn() can only create one IPC channel so we use stdin/stdout as an
// ad-hoc command channel.
var proc = spawn(process.execPath, [__filename, 'worker'], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
});
var handle = null;
proc.on('exit', function() {
handle.close();
});
proc.stdout.on('data', function(data) {
assert.equal(data, 'ok\r\n');
net.createServer(assert.fail).listen(common.PORT, function() {
handle = this._handle;
proc.send('one');
proc.send('two', handle);
proc.send('three');
proc.stdin.write('ok\r\n');
});
});
proc.stderr.pipe(process.stderr);
}
function worker() {
process._channel.readStop(); // Make messages batch up.
process.stdout.ref();
process.stdout.write('ok\r\n');
process.stdin.once('data', function(data) {
assert.equal(data, 'ok\r\n');
process._channel.readStart();
});
var n = 0;
process.on('message', function(msg, handle) {
n += 1;
if (n === 1) {
assert.equal(msg, 'one');
assert.equal(handle, undefined);
}
else if (n === 2) {
assert.equal(msg, 'two');
assert.equal(typeof handle, 'object'); // Also matches null, therefore...
assert.ok(handle); // also check that it's truthy.
handle.close();
}
else if (n === 3) {
assert.equal(msg, 'three');
assert.equal(handle, undefined);
process.exit();
}
});
}

43
test/simple/test-stream2-readable-wrap-empty.js

@ -0,0 +1,43 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var Readable = require('_stream_readable');
var EE = require('events').EventEmitter;
var oldStream = new EE();
oldStream.pause = function(){};
oldStream.resume = function(){};
var newStream = new Readable().wrap(oldStream);
var ended = false;
newStream
.on('readable', function(){})
.on('end', function(){ ended = true; });
oldStream.emit('end');
process.on('exit', function(){
assert.ok(ended);
});

86
test/simple/test-stream2-readable-wrap.js

@ -26,69 +26,83 @@ var Readable = require('_stream_readable');
var Writable = require('_stream_writable'); var Writable = require('_stream_writable');
var EE = require('events').EventEmitter; var EE = require('events').EventEmitter;
var old = new EE; var testRuns = 0, completedRuns = 0;
var r = new Readable({ highWaterMark: 10 }); function runTest(highWaterMark, objectMode, produce) {
assert.equal(r, r.wrap(old)); testRuns++;
var ended = false; var old = new EE;
r.on('end', function() { var r = new Readable({ highWaterMark: highWaterMark, objectMode: objectMode });
assert.equal(r, r.wrap(old));
var ended = false;
r.on('end', function() {
ended = true; ended = true;
}); });
var pauses = 0; var pauses = 0;
var resumes = 0; var resumes = 0;
old.pause = function() { old.pause = function() {
pauses++; pauses++;
old.emit('pause'); old.emit('pause');
flowing = false; flowing = false;
}; };
old.resume = function() { old.resume = function() {
resumes++; resumes++;
old.emit('resume'); old.emit('resume');
flow(); flow();
}; };
var flowing; var flowing;
var chunks = 10; var chunks = 10;
var oldEnded = false; var oldEnded = false;
function flow() { var expected = [];
function flow() {
flowing = true; flowing = true;
while (flowing && chunks-- > 0) { while (flowing && chunks-- > 0) {
old.emit('data', new Buffer('xxxxxxxxxx')); var item = produce();
expected.push(item);
console.log('emit', chunks);
old.emit('data', item);
} }
if (chunks <= 0) { if (chunks <= 0) {
oldEnded = true; oldEnded = true;
console.log('old end', chunks, flowing);
old.emit('end'); old.emit('end');
} }
} }
var w = new Writable({ highWaterMark: 20 }); var w = new Writable({ highWaterMark: highWaterMark * 2, objectMode: objectMode });
var written = []; var written = [];
w._write = function(chunk, encoding, cb) { w._write = function(chunk, encoding, cb) {
written.push(chunk.toString()); console.log(chunk);
written.push(chunk);
setTimeout(cb); setTimeout(cb);
}; };
var finished = false; w.on('finish', function() {
w.on('finish', function() { completedRuns++;
finished = true; performAsserts();
}); });
r.pipe(w);
var expect = new Array(11).join('xxxxxxxxxx'); flow();
r.pipe(w); function performAsserts() {
assert(ended);
assert(oldEnded);
assert.deepEqual(written, expected);
assert.equal(pauses, 10);
assert.equal(resumes, 9);
}
}
flow(); runTest(10, false, function(){ return new Buffer('xxxxxxxxxx'); });
runTest(1, true, function(){ return { foo: 'bar' }; });
process.on('exit', function() { process.on('exit', function() {
assert.equal(pauses, 10); assert.equal(testRuns, completedRuns);
assert.equal(resumes, 9);
assert(ended);
assert(finished);
assert(oldEnded);
assert.equal(written.join(''), expect);
console.log('ok'); console.log('ok');
}); });

Loading…
Cancel
Save