Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v0.10' into master
Browse files Browse the repository at this point in the history
Conflicts:
	doc/api/buffer.markdown
	lib/_stream_readable.js
	lib/assert.js
	lib/buffer.js
	lib/child_process.js
	lib/http.js
	lib/string_decoder.js
	lib/zlib.js
	node.gyp
	test/simple/test-buffer.js
	test/simple/test-https-foafssl.js
	test/simple/test-stream2-compatibility.js
	test/simple/test-tls-server-verify.js
  • Loading branch information
indutny committed Jul 29, 2014
2 parents ef3c4ed + 38f6fcd commit f310c0f
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 41 deletions.
2 changes: 2 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ def configure_node(o):

if target_arch != host_arch and not options.without_snapshot:
o['variables']['want_separate_host_toolset'] = 1
else:
o['variables']['want_separate_host_toolset'] = 0

if target_arch == 'arm':
configure_arm(o)
Expand Down
16 changes: 16 additions & 0 deletions doc/api/buffer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ encoding method. Here are the different string encodings.

* `'hex'` - Encode each byte as two hexadecimal characters.

Creating a typed array from a `Buffer` works with the following caveats:

1. The buffer's memory is copied, not shared.

2. The buffer's memory is interpreted as an array, not a byte array. That is,
`new Uint32Array(new Buffer([1,2,3,4]))` creates a 4-element `Uint32Array`
with elements `[1,2,3,4]`, not an `Uint32Array` with a single element
`[0x1020304]` or `[0x4030201]`.

NOTE: Node.js v0.8 simply retained a reference to the buffer in `array.buffer`
instead of cloning it.

While more efficient, it introduces subtle incompatibilities with the typed
arrays specification. `ArrayBuffer#slice()` makes a copy of the slice while
`Buffer#slice()` creates a view.

## Class: Buffer

The Buffer class is a global type for dealing with binary data directly.
Expand Down
11 changes: 6 additions & 5 deletions doc/api/console.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ Finish timer, record output. Example:
}
console.timeEnd('100-elements');

## console.trace(label)
## console.trace(message, [...])

Print a stack trace to stderr of the current position.
Print to stderr `'Trace :'`, followed by the formatted message and stack trace
to the current position.

## console.assert(expression, [message])
## console.assert(value, [message], [...])

Same as [assert.ok()][] where if the `expression` evaluates as `false` throw an
AssertionError with `message`.
Similar to [assert.ok()][], but the error message is formatted as
`util.format(message...)`.

[assert.ok()]: assert.html#assert_assert_value_message_assert_ok_value_message
[util.format()]: util.html#util_util_format_format
4 changes: 2 additions & 2 deletions doc/api/crypto.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ which must be a `'binary'` encoded string or a [buffer](buffer.html).

It is a [stream](stream.html) that is both readable and writable. The
written data is used to compute the hash. Once the writable side of
the stream is ended, use the `read()` method to get the computed hash
digest. The legacy `update` and `digest` methods are also supported.
the stream is ended, use the `read()` method to get the enciphered
contents. The legacy `update` and `final` methods are also supported.

## crypto.createCipheriv(algorithm, key, iv)

Expand Down
3 changes: 2 additions & 1 deletion doc/api/modules.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ in pseudocode of what require.resolve does:
LOAD_AS_FILE(X)
1. If X is a file, load X as JavaScript text. STOP
2. If X.js is a file, load X.js as JavaScript text. STOP
3. If X.node is a file, load X.node as binary addon. STOP
3. If X.json is a file, parse X.json to a JavaScript Object. STOP
4. If X.node is a file, load X.node as binary addon. STOP

LOAD_AS_DIRECTORY(X)
1. If X/package.json is a file,
Expand Down
5 changes: 1 addition & 4 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ function ReadableState(options, stream) {
// if true, a maybeReadMore has been scheduled
this.readingMore = false;

// if true, stream is in old mode
this.oldMode = false;

this.decoder = null;
this.encoding = null;
if (options.encoding) {
Expand Down Expand Up @@ -227,7 +224,7 @@ function howMuchToRead(n, state) {
if (state.objectMode)
return n === 0 ? 0 : 1;

if (isNaN(n) || util.isNull(n)) {
if (util.isNull(n) || isNaN(n)) {
// only flow one buffer at a time
if (state.flowing && state.buffer.length)
return state.buffer[0].length;
Expand Down
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function replacer(key, value) {
if (util.isUndefined(value)) {
return '' + value;
}
if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
if (util.isNumber(value) && !isFinite(value)) {
return value.toString();
}
if (util.isFunction(value) || util.isRegExp(value)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Buffer.prototype.readUInt32BE = function(offset, noAssert) {
return (this[offset] * 0x1000000) +
((this[offset + 1] << 16) |
(this[offset + 2] << 8) |
(this[offset + 3]) >>> 0);
this[offset + 3]);
};


Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Socket.prototype.listen = function() {


Socket.prototype.setTimeout = function(msecs, callback) {
if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) {
if (msecs > 0 && isFinite(msecs)) {
timers.enroll(this, msecs);
timers._unrefActive(this);
if (callback) {
Expand Down
4 changes: 2 additions & 2 deletions lib/string_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ StringDecoder.prototype.write = function(buffer) {
while (this.charLength) {
// determine how many remaining bytes this buffer has to offer for this char
var available = (buffer.length >= this.charLength - this.charReceived) ?
this.charLength - this.charReceived :
buffer.length;
this.charLength - this.charReceived :
buffer.length;

// add the new bytes to the char buffer
buffer.copy(this.charBuffer, this.charReceived, 0, available);
Expand Down
7 changes: 7 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ Zlib.prototype.params = function(level, strategy, callback) {
if (this._level !== level || this._strategy !== strategy) {
var self = this;
this.flush(binding.Z_SYNC_FLUSH, function() {
assert(!self._closed, 'zlib binding closed');
self._handle.params(level, strategy);
if (!self._hadError) {
self._level = level;
Expand All @@ -416,6 +417,7 @@ Zlib.prototype.params = function(level, strategy, callback) {
};

Zlib.prototype.reset = function() {
assert(!this._closed, 'zlib binding closed');
return this._handle.reset();
};

Expand Down Expand Up @@ -476,6 +478,9 @@ Zlib.prototype._transform = function(chunk, encoding, cb) {
if (!util.isNull(chunk) && !util.isBuffer(chunk))
return cb(new Error('invalid input'));

if (this._closed)
return cb(new Error('zlib binding closed'));

// If it's the last chunk, or a final flush, we use the Z_FINISH flush flag.
// If it's explicitly flushing at some other time, then we use
// Z_FULL_FLUSH. Otherwise, use Z_NO_FLUSH for maximum compression
Expand Down Expand Up @@ -512,6 +517,7 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
error = er;
});

assert(!this._closed, 'zlib binding closed');
do {
var res = this._handle.writeSync(flushFlag,
chunk, // in
Expand All @@ -532,6 +538,7 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
return buf;
}

assert(!this._closed, 'zlib binding closed');
var req = this._handle.write(flushFlag,
chunk, // in
inOff, // in_off
Expand Down
2 changes: 1 addition & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
'./deps/openssl/openssl.gyp:openssl',

# For tests
'./deps/openssl/openssl.gyp:openssl-cli'
'./deps/openssl/openssl.gyp:openssl-cli',
],
}]]
}, {
Expand Down
11 changes: 1 addition & 10 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,15 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// O_NONBLOCK is not exported unless _XOPEN_SOURCE >= 500.
#if defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 500
#undef _XOPEN_SOURCE
#endif

#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 500
#endif

#include "node_constants.h"

#include "uv.h"

#include <errno.h>
#include <fcntl.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-https-foafssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var join = require('path').join;

var fs = require('fs');
var spawn = require('child_process').spawn;

var https = require('https');

var options = {
Expand Down
58 changes: 58 additions & 0 deletions test/simple/test-stream2-base64-single-char-read-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.js');
var R = require('_stream_readable');
var W = require('_stream_writable');
var assert = require('assert');

var src = new R({encoding: 'base64'});
var dst = new W();
var hasRead = false;
var accum = [];
var timeout;

src._read = function(n) {
if(!hasRead) {
hasRead = true;
process.nextTick(function() {
src.push(new Buffer('1'));
src.push(null);
});
};
};

dst._write = function(chunk, enc, cb) {
accum.push(chunk);
cb();
};

src.on('end', function() {
assert.equal(Buffer.concat(accum) + '', 'MQ==');
clearTimeout(timeout);
})

src.pipe(dst);

timeout = setTimeout(function() {
assert.fail('timed out waiting for _write');
}, 100);
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@
// 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 common = require('../common.js');
var assert = require('assert');
var zlib = require('zlib');

var Readable = require('stream').Readable;
var closed = false;

var r = new Readable();
var errors = 0;

// Setting `data` listener should not trigger `_read()` calls before we will
// set the `error` listener below
r.on('data', function() {
});

r.on('error', function() {
errors++;
zlib.gzip('hello', function(err, out) {
var unzip = zlib.createGunzip();
unzip.close(function() {
closed = true;
});
assert.throws(function() {
unzip.write(out);
});
});

process.on('exit', function() {
assert.equal(errors, 1);
assert(closed);
});

0 comments on commit f310c0f

Please sign in to comment.