summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2013-04-12 11:30:11 -0400
committerFedor Indutny <fedor.indutny@gmail.com>2013-04-12 11:30:11 -0400
commit259839fe75dde67472b815d05637750360fd76bf (patch)
tree0ac2a31410fd7bc53bcd7ddecb0d52c60dd2b2f0 /lib
parentf83afd3c74865182bce62843fe23d28b4f876638 (diff)
parent8ee43006b81b713db1a0ca190f5332edd45121c1 (diff)
downloadandroid-node-v8-259839fe75dde67472b815d05637750360fd76bf.tar.gz
android-node-v8-259839fe75dde67472b815d05637750360fd76bf.tar.bz2
android-node-v8-259839fe75dde67472b815d05637750360fd76bf.zip
Merge branch 'v0.10'
Conflicts: ChangeLog deps/uv/src/version.c src/node.h src/node_crypto.cc src/node_crypto_bio.cc src/node_crypto_bio.h src/node_object_wrap.h src/node_version.h
Diffstat (limited to 'lib')
-rw-r--r--lib/_stream_readable.js51
-rw-r--r--lib/_stream_transform.js6
-rw-r--r--lib/_stream_writable.js21
-rw-r--r--lib/buffer.js4
-rw-r--r--lib/child_process.js14
-rw-r--r--lib/cluster.js7
-rw-r--r--lib/crypto.js5
-rw-r--r--lib/http.js9
-rw-r--r--lib/net.js14
-rw-r--r--lib/tls.js4
10 files changed, 83 insertions, 52 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index e30a327f9d..070628288e 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -115,34 +115,44 @@ Readable.prototype.push = function(chunk) {
Readable.prototype.unshift = function(chunk) {
var state = this._readableState;
- if (typeof chunk === 'string' && !state.objectMode)
- chunk = new Buffer(chunk, arguments[1]);
return readableAddChunk(this, state, chunk, true);
};
function readableAddChunk(stream, state, chunk, addToFront) {
- state.reading = false;
-
var er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
} else if (chunk === null || chunk === undefined) {
- onEofChunk(stream, state);
+ state.reading = false;
+ if (!state.ended)
+ onEofChunk(stream, state);
} else if (state.objectMode || chunk && chunk.length > 0) {
- if (state.decoder)
- chunk = state.decoder.write(chunk);
+ if (state.ended && !addToFront) {
+ var e = new Error('stream.push() after EOF');
+ stream.emit('error', e);
+ } else if (state.endEmitted && addToFront) {
+ var e = new Error('stream.unshift() after end event');
+ stream.emit('error', e);
+ } else {
+ if (state.decoder && !addToFront)
+ chunk = state.decoder.write(chunk);
- // update the buffer info.
- state.length += state.objectMode ? 1 : chunk.length;
- if (addToFront)
- state.buffer.unshift(chunk);
- else
- state.buffer.push(chunk);
+ // update the buffer info.
+ state.length += state.objectMode ? 1 : chunk.length;
+ if (addToFront) {
+ state.buffer.unshift(chunk);
+ } else {
+ state.reading = false;
+ state.buffer.push(chunk);
+ }
- if (state.needReadable)
- emitReadable(stream);
+ if (state.needReadable)
+ emitReadable(stream);
- maybeReadMore(stream, state);
+ maybeReadMore(stream, state);
+ }
+ } else {
+ state.reading = false;
}
return needMoreData(state);
@@ -877,10 +887,13 @@ function endReadable(stream) {
if (!state.endEmitted && state.calledRead) {
state.ended = true;
- state.endEmitted = true;
process.nextTick(function() {
- stream.readable = false;
- stream.emit('end');
+ // Check that we didn't get one last unshift.
+ if (!state.endEmitted && state.length === 0) {
+ state.endEmitted = true;
+ stream.readable = false;
+ stream.emit('end');
+ }
});
}
}
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
index ec2b46a953..8a00d343b6 100644
--- a/lib/_stream_transform.js
+++ b/lib/_stream_transform.js
@@ -70,8 +70,6 @@ util.inherits(Transform, Duplex);
function TransformState(options, stream) {
- var ts = this;
-
this.afterTransform = function(er, data) {
return afterTransform(stream, er, data);
};
@@ -152,7 +150,7 @@ Transform.prototype.push = function(chunk) {
// Call `cb(err)` when you are done with this chunk. If you pass
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
-Transform.prototype._transform = function(chunk, output, cb) {
+Transform.prototype._transform = function(chunk, encoding, cb) {
throw new Error('not implemented');
};
@@ -171,7 +169,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
};
// Doesn't matter what the args are here.
-// the output and callback functions passed to _transform do all the work.
+// _transform does all the work.
// That we got here means that the readable side wants more data.
Transform.prototype._read = function(n) {
var ts = this._transformState;
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index 346f2cc96a..c060e015a0 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -240,7 +240,8 @@ function onwrite(stream, er) {
if (er)
onwriteError(stream, state, sync, er, cb);
else {
- var finished = finishMaybe(stream, state);
+ // Check if we're actually ready to finish, but don't emit yet
+ var finished = needFinish(stream, state);
if (!finished && !state.bufferProcessing && state.buffer.length)
clearBuffer(stream, state);
@@ -259,6 +260,8 @@ function afterWrite(stream, state, finished, cb) {
if (!finished)
onwriteDrain(stream, state);
cb();
+ if (finished)
+ finishMaybe(stream, state);
}
// Must force callback to be called on nextTick, so that we don't
@@ -326,15 +329,21 @@ Writable.prototype.end = function(chunk, encoding, cb) {
endWritable(this, state, cb);
};
+
+function needFinish(stream, state) {
+ return (state.ending &&
+ state.length === 0 &&
+ !state.finished &&
+ !state.writing);
+}
+
function finishMaybe(stream, state) {
- if (state.ending &&
- state.length === 0 &&
- !state.finished &&
- !state.writing) {
+ var need = needFinish(stream, state);
+ if (need) {
state.finished = true;
stream.emit('finish');
}
- return state.finished;
+ return need;
}
function endWritable(stream, state, cb) {
diff --git a/lib/buffer.js b/lib/buffer.js
index 24ca3bbbef..e5fa44d928 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -738,14 +738,14 @@ function readInt32(buffer, offset, isBigEndian) {
Buffer.prototype.readInt32LE = function(offset, noAssert) {
if (!noAssert)
- checkOffset(offset, 2, this.length);
+ checkOffset(offset, 4, this.length);
return readInt32(this, offset, false);
};
Buffer.prototype.readInt32BE = function(offset, noAssert) {
if (!noAssert)
- checkOffset(offset, 2, this.length);
+ checkOffset(offset, 4, this.length);
return readInt32(this, offset, true);
};
diff --git a/lib/child_process.js b/lib/child_process.js
index e4fe26ecda..1b6b8b21d6 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -305,19 +305,17 @@ function getSocketList(type, slave, key) {
return socketList;
}
+var INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
- //Filter out internal messages
- //if cmd property begin with "_NODE"
+ var eventName = 'message';
if (message !== null &&
typeof message === 'object' &&
typeof message.cmd === 'string' &&
- message.cmd.indexOf('NODE_') === 0) {
- target.emit('internalMessage', message, handle);
- }
- //Non-internal message
- else {
- target.emit('message', message, handle);
+ message.cmd.length > INTERNAL_PREFIX.length &&
+ message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
+ eventName = 'internalMessage';
}
+ target.emit(eventName, message, handle);
}
function setupChannel(target, channel) {
diff --git a/lib/cluster.js b/lib/cluster.js
index 5561c9fbcf..44dd2e5d2a 100644
--- a/lib/cluster.js
+++ b/lib/cluster.js
@@ -141,9 +141,10 @@ cluster.setupMaster = function(options) {
// Check if a message is internal only
var INTERNAL_PREFIX = 'NODE_CLUSTER_';
function isInternalMessage(message) {
- return (isObject(message) &&
- typeof message.cmd === 'string' &&
- message.cmd.indexOf(INTERNAL_PREFIX) === 0);
+ return isObject(message) &&
+ typeof message.cmd === 'string' &&
+ message.cmd.length > INTERNAL_PREFIX.length &&
+ message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX;
}
// Modify message object to be internal
diff --git a/lib/crypto.js b/lib/crypto.js
index 9fd7ad6b90..c8bc69bfd0 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -155,7 +155,10 @@ function LazyTransform(options) {
}
util.inherits(LazyTransform, stream.Transform);
-['read', 'write', 'end'].forEach(function(action, i, actions) {
+var transformMethods = ['read', 'write', 'end', 'pipe', 'unpipe',
+ 'setEncoding', 'pause', 'resume'];
+
+transformMethods.forEach(function(action, i, actions) {
LazyTransform.prototype[action] = function() {
stream.Transform.call(this, this._options);
diff --git a/lib/http.js b/lib/http.js
index b4fc2add11..ac6b1c6bf7 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -772,15 +772,18 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
var len, ret;
if (this.chunkedEncoding) {
- if (typeof(chunk) === 'string') {
+ if (typeof(chunk) === 'string' &&
+ encoding !== 'hex' &&
+ encoding !== 'base64' &&
+ encoding !== 'binary') {
len = Buffer.byteLength(chunk, encoding);
chunk = len.toString(16) + CRLF + chunk + CRLF;
ret = this._send(chunk, encoding);
} else {
- // buffer
+ // buffer, or a non-toString-friendly encoding
len = chunk.length;
this._send(len.toString(16) + CRLF);
- this._send(chunk);
+ this._send(chunk, encoding);
ret = this._send(CRLF);
}
} else {
diff --git a/lib/net.js b/lib/net.js
index 6174b40eac..646983f6ca 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -667,12 +667,18 @@ Socket.prototype.__defineGetter__('bytesWritten', function() {
encoding = this._pendingEncoding;
state.buffer.forEach(function(el) {
- el = el[0];
- bytes += Buffer.byteLength(el[0], el[1]);
+ if (Buffer.isBuffer(el.chunk))
+ bytes += el.chunk.length;
+ else
+ bytes += Buffer.byteLength(el.chunk, el.encoding);
});
- if (data)
- bytes += Buffer.byteLength(data, encoding);
+ if (data) {
+ if (Buffer.isBuffer(data))
+ bytes += data.length;
+ else
+ bytes += Buffer.byteLength(data, encoding);
+ }
return bytes;
});
diff --git a/lib/tls.js b/lib/tls.js
index 55effb6273..0c5bb633bb 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -140,7 +140,6 @@ function checkServerIdentity(host, cert) {
//
// Walk through altnames and generate lists of those names
if (cert.subjectaltname) {
- matchCN = false;
cert.subjectaltname.split(/, /g).forEach(function(altname) {
if (/^DNS:/.test(altname)) {
dnsNames.push(altname.slice(4));
@@ -178,7 +177,8 @@ function checkServerIdentity(host, cert) {
if (dnsNames.length > 0) matchCN = false;
- // Match against Common Name (CN) only if altnames are not present.
+ // Match against Common Name (CN) only if no supported identifiers are
+ // present.
//
// "As noted, a client MUST NOT seek a match for a reference identifier
// of CN-ID if the presented identifiers include a DNS-ID, SRV-ID,