lint
This commit is contained in:
parent
e232f6e735
commit
dd53ceebe4
@ -7,22 +7,22 @@ function Stream() {
|
||||
util.inherits(Stream, events.EventEmitter);
|
||||
exports.Stream = Stream;
|
||||
|
||||
Stream.prototype.pipe = function (dest, options) {
|
||||
Stream.prototype.pipe = function(dest, options) {
|
||||
var source = this;
|
||||
|
||||
function ondata (chunk) {
|
||||
function ondata(chunk) {
|
||||
if (dest.writable) {
|
||||
if (false === dest.write(chunk)) source.pause();
|
||||
}
|
||||
}
|
||||
|
||||
source.on("data", ondata);
|
||||
source.on('data', ondata);
|
||||
|
||||
function ondrain () {
|
||||
function ondrain() {
|
||||
if (source.readable) source.resume();
|
||||
}
|
||||
|
||||
dest.on("drain", ondrain);
|
||||
dest.on('drain', ondrain);
|
||||
|
||||
/*
|
||||
* If the 'end' option is not supplied, dest.end() will be called when
|
||||
@ -30,14 +30,14 @@ Stream.prototype.pipe = function (dest, options) {
|
||||
*/
|
||||
|
||||
if (!options || options.end !== false) {
|
||||
function onend () {
|
||||
function onend() {
|
||||
dest.end();
|
||||
}
|
||||
|
||||
source.on("end", onend);
|
||||
source.on('end', onend);
|
||||
}
|
||||
|
||||
dest.on('close', function () {
|
||||
dest.on('close', function() {
|
||||
source.removeListener('data', ondata);
|
||||
dest.removeListener('drain', ondrain);
|
||||
source.removeListener('end', onend);
|
||||
@ -49,22 +49,22 @@ Stream.prototype.pipe = function (dest, options) {
|
||||
*/
|
||||
|
||||
if (!source.pause) {
|
||||
source.pause = function () {
|
||||
source.emit("pause");
|
||||
source.pause = function() {
|
||||
source.emit('pause');
|
||||
};
|
||||
}
|
||||
|
||||
if (!source.resume) {
|
||||
source.resume = function () {
|
||||
source.emit("resume");
|
||||
source.resume = function() {
|
||||
source.emit('resume');
|
||||
};
|
||||
}
|
||||
|
||||
dest.on("pause", function () {
|
||||
dest.on('pause', function() {
|
||||
source.pause();
|
||||
});
|
||||
|
||||
dest.on("resume", function () {
|
||||
dest.on('resume', function() {
|
||||
if (source.readable) source.resume();
|
||||
});
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
var StringDecoder = exports.StringDecoder = function (encoding) {
|
||||
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/,'');
|
||||
var StringDecoder = exports.StringDecoder = function(encoding) {
|
||||
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
||||
if (this.encoding === 'utf8') {
|
||||
this.charBuffer = new Buffer(4);
|
||||
this.charReceived = 0;
|
||||
@ -8,7 +8,7 @@ var StringDecoder = exports.StringDecoder = function (encoding) {
|
||||
};
|
||||
|
||||
|
||||
StringDecoder.prototype.write = function (buffer) {
|
||||
StringDecoder.prototype.write = function(buffer) {
|
||||
// If not utf8...
|
||||
if (this.encoding !== 'utf8') {
|
||||
return buffer.toString(this.encoding);
|
||||
@ -18,9 +18,9 @@ StringDecoder.prototype.write = function (buffer) {
|
||||
// if our last write ended with an incomplete multibyte character
|
||||
if (this.charLength) {
|
||||
// determine how many remaining bytes this buffer has to offer for this char
|
||||
var i = (buffer.length >= this.charLength - this.charReceived)
|
||||
? this.charLength - this.charReceived
|
||||
: buffer.length;
|
||||
var i = (buffer.length >= this.charLength - this.charReceived) ?
|
||||
this.charLength - this.charReceived :
|
||||
buffer.length;
|
||||
|
||||
// add the new bytes to the char buffer
|
||||
buffer.copy(this.charBuffer, this.charReceived, 0, i);
|
||||
@ -46,7 +46,8 @@ StringDecoder.prototype.write = function (buffer) {
|
||||
// determine how many bytes we have to check at the end of this buffer
|
||||
var i = (buffer.length >= 3) ? 3 : buffer.length;
|
||||
|
||||
// figure out if one of the last i bytes of our buffer announces an incomplete char
|
||||
// Figure out if one of the last i bytes of our buffer announces an
|
||||
// incomplete char.
|
||||
for (; i > 0; i--) {
|
||||
c = buffer[buffer.length - i];
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
var util = require("util");
|
||||
var util = require('util');
|
||||
|
||||
var sysWarning;
|
||||
if (!sysWarning) {
|
||||
sysWarning = "The 'sys' module is now called 'util'. It should have a similar interface.";
|
||||
sysWarning = 'The "sys" module is now called "util". ' +
|
||||
'It should have a similar interface.';
|
||||
// Uncomment in 2011
|
||||
//util.error(sysWarning);
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ var assert = process.assert;
|
||||
* To enable debug statements for the timers do NODE_DEBUG=8 ./node script.js
|
||||
*/
|
||||
var debugLevel = parseInt(process.env.NODE_DEBUG, 16);
|
||||
function debug () {
|
||||
if (debugLevel & 0x8) {
|
||||
require('util').error.apply(this, arguments);
|
||||
}
|
||||
var debug;
|
||||
if (debugLevel & 0x8) {
|
||||
debug = function() { require('util').error.apply(this, arguments); };
|
||||
} else {
|
||||
debug = function() { };
|
||||
}
|
||||
|
||||
|
||||
// IDLE TIMEOUTS
|
||||
//
|
||||
// Because often many sockets will have the same idle timeout we will not
|
||||
@ -25,14 +27,14 @@ function debug () {
|
||||
var lists = {};
|
||||
|
||||
// show the most idle item
|
||||
function peek (list) {
|
||||
function peek(list) {
|
||||
if (list._idlePrev == list) return null;
|
||||
return list._idlePrev;
|
||||
}
|
||||
|
||||
|
||||
// remove the most idle item from the list
|
||||
function shift (list) {
|
||||
function shift(list) {
|
||||
var first = list._idlePrev;
|
||||
remove(first);
|
||||
return first;
|
||||
@ -40,14 +42,14 @@ function shift (list) {
|
||||
|
||||
|
||||
// remove a item from its list
|
||||
function remove (item) {
|
||||
function remove(item) {
|
||||
item._idleNext._idlePrev = item._idlePrev;
|
||||
item._idlePrev._idleNext = item._idleNext;
|
||||
}
|
||||
|
||||
|
||||
// remove a item from its list and place at the end.
|
||||
function append (list, item) {
|
||||
function append(list, item) {
|
||||
item._idleNext = list._idleNext;
|
||||
list._idleNext._idlePrev = item;
|
||||
item._idlePrev = list;
|
||||
@ -57,7 +59,7 @@ function append (list, item) {
|
||||
|
||||
// the main function - creates lists on demand and the watchers associated
|
||||
// with them.
|
||||
function insert (item, msecs) {
|
||||
function insert(item, msecs) {
|
||||
item._idleStart = new Date();
|
||||
item._idleTimeout = msecs;
|
||||
|
||||
@ -74,18 +76,18 @@ function insert (item, msecs) {
|
||||
|
||||
lists[msecs] = list;
|
||||
|
||||
list.callback = function () {
|
||||
list.callback = function() {
|
||||
debug('timeout callback ' + msecs);
|
||||
// TODO - don't stop and start the watcher all the time.
|
||||
// just set its repeat
|
||||
var now = new Date();
|
||||
debug("now: " + now);
|
||||
debug('now: ' + now);
|
||||
var first;
|
||||
while (first = peek(list)) {
|
||||
var diff = now - first._idleStart;
|
||||
if (diff < msecs) {
|
||||
list.again(msecs - diff);
|
||||
debug(msecs + ' list wait because diff is ' + diff);
|
||||
debug(msecs + ' list wait because diff is ' + diff);
|
||||
return;
|
||||
} else {
|
||||
remove(first);
|
||||
@ -109,7 +111,7 @@ function insert (item, msecs) {
|
||||
}
|
||||
|
||||
|
||||
var unenroll = exports.unenroll = function (item) {
|
||||
var unenroll = exports.unenroll = function(item) {
|
||||
if (item._idleNext) {
|
||||
remove(item);
|
||||
|
||||
@ -125,7 +127,7 @@ var unenroll = exports.unenroll = function (item) {
|
||||
|
||||
|
||||
// Does not start the time, just sets up the members needed.
|
||||
exports.enroll = function (item, msecs) {
|
||||
exports.enroll = function(item, msecs) {
|
||||
// if this item was already in a list somewhere
|
||||
// then we should unenroll it from that
|
||||
if (item._idleNext) unenroll(item);
|
||||
@ -137,7 +139,7 @@ exports.enroll = function (item, msecs) {
|
||||
|
||||
// call this whenever the item is active (not idle)
|
||||
// it will reset its timeout.
|
||||
exports.active = function (item) {
|
||||
exports.active = function(item) {
|
||||
var msecs = item._idleTimeout;
|
||||
if (msecs >= 0) {
|
||||
var list = lists[msecs];
|
||||
@ -162,8 +164,8 @@ exports.active = function (item) {
|
||||
*/
|
||||
|
||||
|
||||
exports.setTimeout = function (callback, after) {
|
||||
var timer;
|
||||
exports.setTimeout = function(callback, after) {
|
||||
var timer;
|
||||
|
||||
if (after <= 0) {
|
||||
// Use the slow case for after == 0
|
||||
@ -186,7 +188,7 @@ exports.setTimeout = function (callback, after) {
|
||||
*/
|
||||
if (arguments.length > 2) {
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var c = function () {
|
||||
var c = function() {
|
||||
callback.apply(timer, args);
|
||||
};
|
||||
|
||||
@ -207,7 +209,7 @@ exports.setTimeout = function (callback, after) {
|
||||
};
|
||||
|
||||
|
||||
exports.clearTimeout = function (timer) {
|
||||
exports.clearTimeout = function(timer) {
|
||||
if (timer && (timer.callback || timer._onTimeout)) {
|
||||
timer.callback = timer._onTimeout = null;
|
||||
exports.unenroll(timer);
|
||||
@ -216,12 +218,12 @@ exports.clearTimeout = function (timer) {
|
||||
};
|
||||
|
||||
|
||||
exports.setInterval = function (callback, repeat) {
|
||||
exports.setInterval = function(callback, repeat) {
|
||||
var timer = new Timer();
|
||||
|
||||
if (arguments.length > 2) {
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
timer.callback = function () {
|
||||
timer.callback = function() {
|
||||
callback.apply(timer, args);
|
||||
};
|
||||
} else {
|
||||
@ -233,7 +235,7 @@ exports.setInterval = function (callback, repeat) {
|
||||
};
|
||||
|
||||
|
||||
exports.clearInterval = function (timer) {
|
||||
exports.clearInterval = function(timer) {
|
||||
if (timer instanceof Timer) {
|
||||
timer.callback = null;
|
||||
timer.stop();
|
||||
|
33
lib/tls.js
33
lib/tls.js
@ -36,12 +36,12 @@ var inherits = require('util').inherits;
|
||||
// TODO:
|
||||
// cleartext.credentials (by mirroring from pair object)
|
||||
// cleartext.getCertificate() (by mirroring from pair.credentials.context)
|
||||
function Server ( /* [options], listener */) {
|
||||
function Server(/* [options], listener */) {
|
||||
var options, listener;
|
||||
if (typeof arguments[0] == "object") {
|
||||
if (typeof arguments[0] == 'object') {
|
||||
options = arguments[0];
|
||||
listener = arguments[1];
|
||||
} else if (typeof arguments[0] == "function") {
|
||||
} else if (typeof arguments[0] == 'function') {
|
||||
options = {};
|
||||
listener = arguments[0];
|
||||
}
|
||||
@ -51,10 +51,9 @@ function Server ( /* [options], listener */) {
|
||||
var self = this;
|
||||
|
||||
// constructor call
|
||||
net.Server.call(this, function (socket) {
|
||||
var creds = crypto.createCredentials({ key: self.key,
|
||||
cert: self.cert,
|
||||
ca: self.ca });
|
||||
net.Server.call(this, function(socket) {
|
||||
var creds = crypto.createCredentials(
|
||||
{ key: self.key, cert: self.cert, ca: self.ca });
|
||||
creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
|
||||
|
||||
var pair = crypto.createPair(creds,
|
||||
@ -63,14 +62,14 @@ function Server ( /* [options], listener */) {
|
||||
pair.encrypted.pipe(socket);
|
||||
socket.pipe(pair.encrypted);
|
||||
|
||||
pair.on('secure', function () {
|
||||
pair.on('secure', function() {
|
||||
var verifyError = pair._ssl.verifyError();
|
||||
|
||||
if (verifyError) {
|
||||
if (self.unauthorizedPeers) {
|
||||
self.emit('unauthorized', pair.cleartext, verifyError);
|
||||
} else {
|
||||
console.error("REJECT PEER. verify error: %s", verifyError);
|
||||
console.error('REJECT PEER. verify error: %s', verifyError);
|
||||
socket.destroy();
|
||||
}
|
||||
} else {
|
||||
@ -78,15 +77,9 @@ function Server ( /* [options], listener */) {
|
||||
}
|
||||
});
|
||||
|
||||
pair.on('error', function (e) {
|
||||
pair.on('error', function(e) {
|
||||
console.log('pair got error: ' + e);
|
||||
|
||||
// TODO better way to get error code.
|
||||
if (/no shared cipher/.test(e.message)) {
|
||||
;
|
||||
} else {
|
||||
self.emit('error', e);
|
||||
}
|
||||
self.emit('error', e);
|
||||
});
|
||||
|
||||
pair.cleartext.on('error', function(err) {
|
||||
@ -110,13 +103,13 @@ function Server ( /* [options], listener */) {
|
||||
|
||||
inherits(Server, net.Server);
|
||||
exports.Server = Server;
|
||||
exports.createServer = function (options, listener) {
|
||||
exports.createServer = function(options, listener) {
|
||||
return new Server(options, listener);
|
||||
};
|
||||
|
||||
|
||||
Server.prototype.setOptions = function (options) {
|
||||
if (typeof options.unauthorizedPeers == "boolean") {
|
||||
Server.prototype.setOptions = function(options) {
|
||||
if (typeof options.unauthorizedPeers == 'boolean') {
|
||||
this.unauthorizedPeers = options.unauthorizedPeers;
|
||||
} else {
|
||||
this.unauthorizedPeers = false;
|
||||
|
162
lib/util.js
162
lib/util.js
@ -1,26 +1,26 @@
|
||||
var events = require('events');
|
||||
|
||||
|
||||
exports.print = function () {
|
||||
exports.print = function() {
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
process.stdout.write(String(arguments[i]));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.puts = function () {
|
||||
exports.puts = function() {
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
process.stdout.write(arguments[i] + '\n');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.debug = function (x) {
|
||||
process.binding('stdio').writeError("DEBUG: " + x + "\n");
|
||||
exports.debug = function(x) {
|
||||
process.binding('stdio').writeError('DEBUG: ' + x + '\n');
|
||||
};
|
||||
|
||||
|
||||
var error = exports.error = function (x) {
|
||||
var error = exports.error = function(x) {
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
process.binding('stdio').writeError(arguments[i] + '\n');
|
||||
}
|
||||
@ -31,41 +31,41 @@ var error = exports.error = function (x) {
|
||||
* Echos the value of a value. Trys to print the value out
|
||||
* in the best way possible given the different types.
|
||||
*
|
||||
* @param {Object} value The object to print out
|
||||
* @param {Object} value The object to print out.
|
||||
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
||||
* properties of objects.
|
||||
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
||||
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
||||
* output. Default is false (no coloring).
|
||||
*/
|
||||
exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
exports.inspect = function(obj, showHidden, depth, colors) {
|
||||
var seen = [];
|
||||
|
||||
var stylize = function (str, styleType) {
|
||||
var stylize = function(str, styleType) {
|
||||
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||
var styles = { 'bold' : [1, 22]
|
||||
, 'italic' : [3, 23]
|
||||
, 'underline' : [4, 24]
|
||||
, 'inverse' : [7, 27]
|
||||
, 'white' : [37, 39]
|
||||
, 'grey' : [90, 39]
|
||||
, 'black' : [30, 39]
|
||||
, 'blue' : [34, 39]
|
||||
, 'cyan' : [36, 39]
|
||||
, 'green' : [32, 39]
|
||||
, 'magenta' : [35, 39]
|
||||
, 'red' : [31, 39]
|
||||
, 'yellow' : [33, 39]
|
||||
var styles = { 'bold' : [1, 22]
|
||||
, 'italic' : [3, 23]
|
||||
, 'underline' : [4, 24]
|
||||
, 'inverse' : [7, 27]
|
||||
, 'white' : [37, 39]
|
||||
, 'grey' : [90, 39]
|
||||
, 'black' : [30, 39]
|
||||
, 'blue' : [34, 39]
|
||||
, 'cyan' : [36, 39]
|
||||
, 'green' : [32, 39]
|
||||
, 'magenta' : [35, 39]
|
||||
, 'red' : [31, 39]
|
||||
, 'yellow' : [33, 39]
|
||||
};
|
||||
var style = { "special": "grey"
|
||||
, "number": "blue"
|
||||
, "boolean": "blue"
|
||||
, "undefined": "red"
|
||||
, "null": "red"
|
||||
, "string": "green"
|
||||
, "date": "magenta"
|
||||
var style = { 'special': 'grey'
|
||||
, 'number': 'blue'
|
||||
, 'boolean': 'blue'
|
||||
, 'undefined': 'red'
|
||||
, 'null': 'red'
|
||||
, 'string': 'green'
|
||||
, 'date': 'magenta'
|
||||
//, "name": intentionally not styling
|
||||
, "regexp": "cyan"
|
||||
, 'regexp': 'cyan'
|
||||
}[styleType];
|
||||
if (style) {
|
||||
return '\033[' + styles[style][0] + 'm' + str +
|
||||
@ -92,13 +92,13 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
// Primitive types cannot have properties
|
||||
switch (typeof value) {
|
||||
case 'undefined': return stylize('undefined', 'undefined');
|
||||
case 'string': return stylize(
|
||||
case 'string': return stylize(
|
||||
JSON.stringify(value).replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/(^"|"$)/g, "'"),
|
||||
'string');
|
||||
case 'number': return stylize('' + value, 'number');
|
||||
case 'boolean': return stylize('' + value, 'boolean');
|
||||
case 'number': return stylize('' + value, 'number');
|
||||
case 'boolean': return stylize('' + value, 'boolean');
|
||||
}
|
||||
// For some reason typeof null is "object", so special case here.
|
||||
if (value === null) {
|
||||
@ -114,7 +114,7 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
return stylize('[Function'+ (value.name ? ': '+ value.name : '')+ ']', 'special');
|
||||
return stylize('[Function' + (value.name ? ': ' + value.name : '') + ']', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,17 +127,17 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
// Determine the object type
|
||||
if (isArray(value)) {
|
||||
type = 'Array';
|
||||
braces = ["[", "]"];
|
||||
braces = ['[', ']'];
|
||||
} else {
|
||||
type = 'Object';
|
||||
braces = ["{", "}"];
|
||||
braces = ['{', '}'];
|
||||
}
|
||||
|
||||
// Make functions say that they are functions
|
||||
if (typeof value === 'function') {
|
||||
base = (isRegExp(value)) ? ' ' + value : ' [Function'+ (value.name ? ': '+ value.name : '')+ ']';
|
||||
base = (isRegExp(value)) ? ' ' + value : ' [Function' + (value.name ? ': ' + value.name : '') + ']';
|
||||
} else {
|
||||
base = "";
|
||||
base = '';
|
||||
}
|
||||
|
||||
// Make dates with properties first say the date
|
||||
@ -151,35 +151,35 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
|
||||
if (recurseTimes < 0) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, "regexp");
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
return stylize("[Object]", "special");
|
||||
return stylize('[Object]', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
seen.push(value);
|
||||
|
||||
var output = keys.map(function (key) {
|
||||
var output = keys.map(function(key) {
|
||||
var name, str;
|
||||
if (value.__lookupGetter__) {
|
||||
if (value.__lookupGetter__(key)) {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize("[Getter/Setter]", "special");
|
||||
str = stylize('[Getter/Setter]', 'special');
|
||||
} else {
|
||||
str = stylize("[Getter]", "special");
|
||||
str = stylize('[Getter]', 'special');
|
||||
}
|
||||
} else {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize("[Setter]", "special");
|
||||
str = stylize('[Setter]', 'special');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible_keys.indexOf(key) < 0) {
|
||||
name = "[" + key + "]";
|
||||
name = '[' + key + ']';
|
||||
}
|
||||
if (!str) {
|
||||
if (seen.indexOf(value[key]) < 0) {
|
||||
if ( recurseTimes === null) {
|
||||
if (recurseTimes === null) {
|
||||
str = format(value[key]);
|
||||
} else {
|
||||
str = format(value[key], recurseTimes - 1);
|
||||
@ -205,17 +205,17 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
}
|
||||
name = JSON.stringify('' + key);
|
||||
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
||||
name = name.substr(1, name.length-2);
|
||||
name = stylize(name, "name");
|
||||
name = name.substr(1, name.length - 2);
|
||||
name = stylize(name, 'name');
|
||||
} else {
|
||||
name = name.replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/(^"|"$)/g, "'");
|
||||
name = stylize(name, "string");
|
||||
name = stylize(name, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
return name + ": " + str;
|
||||
return name + ': ' + str;
|
||||
});
|
||||
|
||||
seen.pop();
|
||||
@ -223,7 +223,7 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
var numLinesEst = 0;
|
||||
var length = output.reduce(function(prev, cur) {
|
||||
numLinesEst++;
|
||||
if( cur.indexOf('\n') >= 0 ) {
|
||||
if (cur.indexOf('\n') >= 0) {
|
||||
numLinesEst++;
|
||||
}
|
||||
return prev + cur.length + 1;
|
||||
@ -235,8 +235,8 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
+ ' '
|
||||
+ output.join(',\n ')
|
||||
+ ' '
|
||||
+ braces[1]
|
||||
;
|
||||
+ braces[1];
|
||||
|
||||
} else {
|
||||
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||
}
|
||||
@ -247,18 +247,18 @@ exports.inspect = function (obj, showHidden, depth, colors) {
|
||||
};
|
||||
|
||||
|
||||
function isArray (ar) {
|
||||
function isArray(ar) {
|
||||
return ar instanceof Array
|
||||
|| Array.isArray(ar)
|
||||
|| (ar && ar !== Object.prototype && isArray(ar.__proto__));
|
||||
}
|
||||
|
||||
|
||||
function isRegExp (re) {
|
||||
var s = ""+re;
|
||||
function isRegExp(re) {
|
||||
var s = ''+ re;
|
||||
return re instanceof RegExp // easy case
|
||||
|| typeof(re) === "function" // duck-type for context-switching evalcx case
|
||||
&& re.constructor.name === "RegExp"
|
||||
|| typeof(re) === 'function' // duck-type for context-switching evalcx case
|
||||
&& re.constructor.name === 'RegExp'
|
||||
&& re.compile
|
||||
&& re.test
|
||||
&& re.exec
|
||||
@ -266,9 +266,9 @@ function isRegExp (re) {
|
||||
}
|
||||
|
||||
|
||||
function isDate (d) {
|
||||
function isDate(d) {
|
||||
if (d instanceof Date) return true;
|
||||
if (typeof d !== "object") return false;
|
||||
if (typeof d !== 'object') return false;
|
||||
var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype);
|
||||
var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__);
|
||||
return JSON.stringify(proto) === JSON.stringify(properties);
|
||||
@ -277,9 +277,9 @@ function isDate (d) {
|
||||
|
||||
var pWarning;
|
||||
|
||||
exports.p = function () {
|
||||
exports.p = function() {
|
||||
if (!pWarning) {
|
||||
pWarning = "util.p will be removed in future versions of Node. Use util.puts(util.inspect()) instead.\n";
|
||||
pWarning = 'util.p will be removed in future versions of Node. Use util.puts(util.inspect()) instead.\n';
|
||||
exports.error(pWarning);
|
||||
}
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
@ -288,7 +288,7 @@ exports.p = function () {
|
||||
};
|
||||
|
||||
|
||||
function pad (n) {
|
||||
function pad(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
@ -296,22 +296,22 @@ function pad (n) {
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
// 26 Feb 16:19:34
|
||||
function timestamp () {
|
||||
function timestamp() {
|
||||
var d = new Date();
|
||||
return [ d.getDate()
|
||||
return [d.getDate()
|
||||
, months[d.getMonth()]
|
||||
, [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':')
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
|
||||
exports.log = function (msg) {
|
||||
exports.log = function(msg) {
|
||||
exports.puts(timestamp() + ' - ' + msg.toString());
|
||||
};
|
||||
|
||||
|
||||
var execWarning;
|
||||
exports.exec = function () {
|
||||
exports.exec = function() {
|
||||
if (!execWarning) {
|
||||
execWarning = 'util.exec has moved to the "child_process" module. Please update your source code.';
|
||||
error(execWarning);
|
||||
@ -320,49 +320,49 @@ exports.exec = function () {
|
||||
};
|
||||
|
||||
|
||||
exports.pump = function (readStream, writeStream, callback) {
|
||||
exports.pump = function(readStream, writeStream, callback) {
|
||||
var callbackCalled = false;
|
||||
|
||||
function call (a, b, c) {
|
||||
function call(a, b, c) {
|
||||
if (callback && !callbackCalled) {
|
||||
callback(a, b, c);
|
||||
callbackCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!readStream.pause) readStream.pause = function () {readStream.emit("pause");};
|
||||
if (!readStream.resume) readStream.resume = function () {readStream.emit("resume");};
|
||||
if (!readStream.pause) readStream.pause = function() {readStream.emit('pause');};
|
||||
if (!readStream.resume) readStream.resume = function() {readStream.emit('resume');};
|
||||
|
||||
readStream.addListener("data", function (chunk) {
|
||||
readStream.addListener('data', function(chunk) {
|
||||
if (writeStream.write(chunk) === false) readStream.pause();
|
||||
});
|
||||
|
||||
writeStream.addListener("pause", function () {
|
||||
writeStream.addListener('pause', function() {
|
||||
readStream.pause();
|
||||
});
|
||||
|
||||
writeStream.addListener("drain", function () {
|
||||
writeStream.addListener('drain', function() {
|
||||
readStream.resume();
|
||||
});
|
||||
|
||||
writeStream.addListener("resume", function () {
|
||||
writeStream.addListener('resume', function() {
|
||||
readStream.resume();
|
||||
});
|
||||
|
||||
readStream.addListener("end", function () {
|
||||
readStream.addListener('end', function() {
|
||||
writeStream.end();
|
||||
});
|
||||
|
||||
readStream.addListener("close", function () {
|
||||
readStream.addListener('close', function() {
|
||||
call();
|
||||
});
|
||||
|
||||
readStream.addListener("error", function (err) {
|
||||
readStream.addListener('error', function(err) {
|
||||
writeStream.end();
|
||||
call(err);
|
||||
});
|
||||
|
||||
writeStream.addListener("error", function (err) {
|
||||
writeStream.addListener('error', function(err) {
|
||||
readStream.destroy();
|
||||
call(err);
|
||||
});
|
||||
@ -378,10 +378,10 @@ exports.pump = function (readStream, writeStream, callback) {
|
||||
* expected during bootstrapping (see mirror.js in r114903).
|
||||
*
|
||||
* @param {function} ctor Constructor function which needs to inherit the
|
||||
* prototype
|
||||
* @param {function} superCtor Constructor function to inherit prototype from
|
||||
* prototype.
|
||||
* @param {function} superCtor Constructor function to inherit prototype from.
|
||||
*/
|
||||
exports.inherits = function (ctor, superCtor) {
|
||||
exports.inherits = function(ctor, superCtor) {
|
||||
ctor.super_ = superCtor;
|
||||
ctor.prototype = Object.create(superCtor.prototype, {
|
||||
constructor: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user