http: add callback is function check

We were checking that the callback existed, but not
checking that it was a function. In `setTimeout`, if
callback is truthy but not a function, throw a
TypeError

Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
PR-URL: https://github.com/nodejs/node/pull/3090
This commit is contained in:
James M Snell 2015-09-27 11:54:57 -07:00
Родитель 05d424c029
Коммит 0094a8dad7
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -89,8 +89,12 @@ exports.OutgoingMessage = OutgoingMessage;
OutgoingMessage.prototype.setTimeout = function(msecs, callback) {
if (callback)
if (callback) {
if (typeof callback !== 'function')
throw new TypeError('callback must be a function');
this.on('timeout', callback);
}
if (!this.socket) {
this.once('socket', function(socket) {