diff --git a/configure b/configure index 772e4e14b3..f7f6cc3d72 100755 --- a/configure +++ b/configure @@ -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) diff --git a/doc/api/buffer.markdown b/doc/api/buffer.markdown index 923688a14a..3e6289ec10 100644 --- a/doc/api/buffer.markdown +++ b/doc/api/buffer.markdown @@ -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. diff --git a/doc/api/console.markdown b/doc/api/console.markdown index 154b4bf697..5cfe068f26 100644 --- a/doc/api/console.markdown +++ b/doc/api/console.markdown @@ -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 diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index dcb25c34e1..0c324c543a 100644 --- a/doc/api/crypto.markdown +++ b/doc/api/crypto.markdown @@ -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) diff --git a/doc/api/modules.markdown b/doc/api/modules.markdown index a9c503448e..7632d30e54 100644 --- a/doc/api/modules.markdown +++ b/doc/api/modules.markdown @@ -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, diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index a9d9fc60b7..999195216c 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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) { @@ -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; diff --git a/lib/assert.js b/lib/assert.js index 7602996c91..c83f977a25 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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)) { diff --git a/lib/buffer.js b/lib/buffer.js index c1abb00590..bd69a97200 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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]); }; diff --git a/lib/net.js b/lib/net.js index 650ce30391..1877e42153 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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) { diff --git a/lib/string_decoder.js b/lib/string_decoder.js index 7d8de27c9e..fd11e51c8d 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -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); diff --git a/lib/zlib.js b/lib/zlib.js index 2460cbb5ea..ad9ceaa7eb 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -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; @@ -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(); }; @@ -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 @@ -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 @@ -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 diff --git a/node.gyp b/node.gyp index 4898ac316d..f8d4ba18a6 100644 --- a/node.gyp +++ b/node.gyp @@ -182,7 +182,7 @@ './deps/openssl/openssl.gyp:openssl', # For tests - './deps/openssl/openssl.gyp:openssl-cli' + './deps/openssl/openssl.gyp:openssl-cli', ], }]] }, { diff --git a/src/node_constants.cc b/src/node_constants.cc index d4f0c69c35..dc7dc80670 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -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 -#include #if !defined(_MSC_VER) #include #endif +#include #include #include #include diff --git a/test/simple/test-https-foafssl.js b/test/simple/test-https-foafssl.js index 152d122426..c9fc746e89 100644 --- a/test/simple/test-https-foafssl.js +++ b/test/simple/test-https-foafssl.js @@ -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 = { diff --git a/test/simple/test-stream2-base64-single-char-read-end.js b/test/simple/test-stream2-base64-single-char-read-end.js new file mode 100644 index 0000000000..5a3834128c --- /dev/null +++ b/test/simple/test-stream2-base64-single-char-read-end.js @@ -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); diff --git a/test/simple/test-stream-readable-data-sync-race.js b/test/simple/test-zlib-write-after-close.js similarity index 78% rename from test/simple/test-stream-readable-data-sync-race.js rename to test/simple/test-zlib-write-after-close.js index 5bbfcc88ae..d3f3d4e6b3 100644 --- a/test/simple/test-stream-readable-data-sync-race.js +++ b/test/simple/test-zlib-write-after-close.js @@ -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); });