summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/_debugger.js20
-rw-r--r--lib/_http_agent.js2
-rw-r--r--lib/_http_client.js10
-rw-r--r--lib/_http_incoming.js8
-rw-r--r--lib/_http_outgoing.js16
-rw-r--r--lib/_http_server.js10
-rw-r--r--lib/_stream_readable.js20
-rw-r--r--lib/_stream_transform.js6
-rw-r--r--lib/_stream_writable.js24
-rw-r--r--lib/_tls_legacy.js14
-rw-r--r--lib/_tls_wrap.js18
-rw-r--r--lib/assert.js20
-rw-r--r--lib/buffer.js34
-rw-r--r--lib/child_process.js46
-rw-r--r--lib/cluster.js20
-rw-r--r--lib/console.js2
-rw-r--r--lib/crypto.js10
-rw-r--r--lib/dgram.js18
-rw-r--r--lib/dns.js6
-rw-r--r--lib/domain.js2
-rw-r--r--lib/events.js36
-rw-r--r--lib/fs.js144
-rw-r--r--lib/https.js12
-rw-r--r--lib/module.js5
-rw-r--r--lib/net.js58
-rw-r--r--lib/path.js10
-rw-r--r--lib/querystring.js19
-rw-r--r--lib/readline.js24
-rw-r--r--lib/repl.js27
-rw-r--r--lib/smalloc.js7
-rw-r--r--lib/stream.js2
-rw-r--r--lib/tls.js8
-rw-r--r--lib/url.js19
-rw-r--r--lib/util.js107
-rw-r--r--lib/vm.js3
-rw-r--r--lib/zlib.js24
-rw-r--r--node.gyp1
-rw-r--r--src/macros.py16
38 files changed, 439 insertions, 389 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js
index 993fcba28..f7b825249 100644
--- a/lib/_debugger.js
+++ b/lib/_debugger.js
@@ -182,7 +182,7 @@ exports.Client = Client;
Client.prototype._addHandle = function(desc) {
- if (!IS_OBJECT(desc) || !IS_NUMBER(desc.handle)) {
+ if (!util.isObject(desc) || !util.isNumber(desc.handle)) {
return;
}
@@ -296,7 +296,7 @@ Client.prototype.reqLookup = function(refs, cb) {
this.req(req, function(err, res) {
if (err) return cb(err);
for (var ref in res) {
- if (IS_OBJECT(res[ref])) {
+ if (util.isObject(res[ref])) {
self._addHandle(res[ref]);
}
}
@@ -559,7 +559,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
}
- if (IS_ARRAY(mirror) && !IS_NUMBER(prop.name)) {
+ if (util.isArray(mirror) && !util.isNumber(prop.name)) {
// Skip the 'length' property.
return;
}
@@ -592,7 +592,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
val = function() {};
} else if (handle.type === 'null') {
val = null;
- } else if (!IS_UNDEFINED(handle.value)) {
+ } else if (!util.isUndefined(handle.value)) {
val = handle.value;
} else if (handle.type === 'undefined') {
val = undefined;
@@ -891,7 +891,7 @@ Interface.prototype.print = function(text, oneline) {
if (this.killed) return;
this.clearline();
- this.stdout.write(IS_STRING(text) ? text : util.inspect(text));
+ this.stdout.write(util.isString(text) ? text : util.inspect(text));
if (oneline !== true) {
this.stdout.write('\n');
@@ -1213,7 +1213,7 @@ Interface.prototype.scripts = function() {
this.pause();
for (var id in client.scripts) {
var script = client.scripts[id];
- if (IS_OBJECT(script) && script.name) {
+ if (util.isObject(script) && script.name) {
if (displayNatives ||
script.name == client.currentScript ||
!script.isNative) {
@@ -1350,13 +1350,13 @@ Interface.prototype.setBreakpoint = function(script, line,
ambiguous;
// setBreakpoint() should insert breakpoint on current line
- if (IS_UNDEFINED(script)) {
+ if (util.isUndefined(script)) {
script = this.client.currentScript;
line = this.client.currentSourceLine + 1;
}
// setBreakpoint(line-number) should insert breakpoint in current script
- if (IS_UNDEFINED(line) && IS_NUMBER(script)) {
+ if (util.isUndefined(line) && util.isNumber(script)) {
line = script;
script = this.client.currentScript;
}
@@ -1451,7 +1451,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
if (bp.scriptId === script ||
bp.scriptReq === script ||
(bp.script && bp.script.indexOf(script) !== -1)) {
- if (!IS_UNDEFINED(index)) {
+ if (!util.isUndefined(index)) {
ambiguous = true;
}
if (bp.line === line) {
@@ -1464,7 +1464,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
if (ambiguous) return this.error('Script name is ambiguous');
- if (IS_UNDEFINED(breakpoint)) {
+ if (util.isUndefined(breakpoint)) {
return this.error('Script : ' + script + ' not found');
}
diff --git a/lib/_http_agent.js b/lib/_http_agent.js
index 500ddb057..cced26698 100644
--- a/lib/_http_agent.js
+++ b/lib/_http_agent.js
@@ -246,7 +246,7 @@ Agent.prototype.destroy = function() {
};
Agent.prototype.request = function(options, cb) {
- if (IS_STRING(options)) {
+ if (util.isString(options)) {
options = url.parse(options);
}
// don't try to do dns lookups of foo.com:8080, just foo.com
diff --git a/lib/_http_client.js b/lib/_http_client.js
index ca82bf7fe..cf73538a6 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -44,14 +44,14 @@ function ClientRequest(options, cb) {
var self = this;
OutgoingMessage.call(self);
- self.agent = IS_UNDEFINED(options.agent) ? globalAgent : options.agent;
+ self.agent = util.isUndefined(options.agent) ? globalAgent : options.agent;
var defaultPort = options.defaultPort || 80;
var port = options.port || defaultPort;
var host = options.hostname || options.host || 'localhost';
- if (IS_UNDEFINED(options.setHost)) {
+ if (util.isUndefined(options.setHost)) {
var setHost = true;
}
@@ -63,7 +63,7 @@ function ClientRequest(options, cb) {
self.once('response', cb);
}
- if (!IS_ARRAY(options.headers)) {
+ if (!util.isArray(options.headers)) {
if (options.headers) {
var keys = Object.keys(options.headers);
for (var i = 0, l = keys.length; i < l; i++) {
@@ -92,7 +92,7 @@ function ClientRequest(options, cb) {
self.useChunkedEncodingByDefault = true;
}
- if (IS_ARRAY(options.headers)) {
+ if (util.isArray(options.headers)) {
self._storeHeader(self.method + ' ' + self.path + ' HTTP/1.1\r\n',
options.headers);
} else if (self.getHeader('expect')) {
@@ -413,7 +413,7 @@ ClientRequest.prototype.onSocket = function(socket) {
httpSocketSetup(socket);
// Propagate headers limit from request object to parser
- if (IS_NUMBER(req.maxHeadersCount)) {
+ if (util.isNumber(req.maxHeadersCount)) {
parser.maxHeaderPairs = req.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js
index f11d09803..f609e4fc2 100644
--- a/lib/_http_incoming.js
+++ b/lib/_http_incoming.js
@@ -125,7 +125,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
switch (field) {
// Array headers:
case 'set-cookie':
- if (!IS_UNDEFINED(dest[field])) {
+ if (!util.isUndefined(dest[field])) {
dest[field].push(value);
} else {
dest[field] = [value];
@@ -145,7 +145,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
case 'proxy-authenticate':
case 'sec-websocket-extensions':
case 'sec-websocket-protocol':
- if (!IS_UNDEFINED(dest[field])) {
+ if (!util.isUndefined(dest[field])) {
dest[field] += ', ' + value;
} else {
dest[field] = value;
@@ -156,14 +156,14 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
default:
if (field.slice(0, 2) == 'x-') {
// except for x-
- if (!IS_UNDEFINED(dest[field])) {
+ if (!util.isUndefined(dest[field])) {
dest[field] += ', ' + value;
} else {
dest[field] = value;
}
} else {
// drop duplicates
- if (IS_UNDEFINED(dest[field])) dest[field] = value;
+ if (util.isUndefined(dest[field])) dest[field] = value;
}
break;
}
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index fd4681f39..7cfa92c9c 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -115,7 +115,7 @@ OutgoingMessage.prototype._send = function(data, encoding) {
// the same packet. Future versions of Node are going to take care of
// this at a lower level and in a more general way.
if (!this._headerSent) {
- if (IS_STRING(data)) {
+ if (util.isString(data)) {
data = this._header + data;
} else {
this.output.unshift(this._header);
@@ -166,7 +166,7 @@ OutgoingMessage.prototype._buffer = function(data, encoding) {
var length = this.output.length;
- if (length === 0 || !IS_STRING(data)) {
+ if (length === 0 || !util.isString(data)) {
this.output.push(data);
this.outputEncodings.push(encoding);
return false;
@@ -205,7 +205,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
if (headers) {
var keys = Object.keys(headers);
- var isArray = IS_ARRAY(headers);
+ var isArray = util.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {
@@ -218,7 +218,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
value = headers[key];
}
- if (IS_ARRAY(value)) {
+ if (util.isArray(value)) {
for (var j = 0; j < value.length; j++) {
storeHeader(this, state, field, value[j]);
}
@@ -401,7 +401,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
return true;
}
- if (!IS_STRING(chunk) && !IS_BUFFER(chunk)) {
+ if (!util.isString(chunk) && !util.isBuffer(chunk)) {
throw new TypeError('first argument must be a string or Buffer');
}
@@ -412,7 +412,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
var len, ret;
if (this.chunkedEncoding) {
- if (IS_STRING(chunk) &&
+ if (util.isString(chunk) &&
encoding !== 'hex' &&
encoding !== 'base64' &&
encoding !== 'binary') {
@@ -444,7 +444,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
OutgoingMessage.prototype.addTrailers = function(headers) {
this._trailer = '';
var keys = Object.keys(headers);
- var isArray = IS_ARRAY(headers);
+ var isArray = util.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
@@ -466,7 +466,7 @@ var crlf_buf = new Buffer('\r\n');
OutgoingMessage.prototype.end = function(data, encoding) {
- if (data && !IS_STRING(data) && !IS_BUFFER(data)) {
+ if (data && !util.isString(data) && !util.isBuffer(data)) {
throw new TypeError('first argument must be a string or Buffer');
}
diff --git a/lib/_http_server.js b/lib/_http_server.js
index 4c7f92d9e..b4fc2c3ca 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -173,7 +173,7 @@ ServerResponse.prototype._implicitHeader = function() {
ServerResponse.prototype.writeHead = function(statusCode) {
var reasonPhrase, headers, headerIndex;
- if (IS_STRING(arguments[1])) {
+ if (util.isString(arguments[1])) {
reasonPhrase = arguments[1];
headerIndex = 2;
} else {
@@ -188,13 +188,13 @@ ServerResponse.prototype.writeHead = function(statusCode) {
// Slow-case: when progressive API and header fields are passed.
headers = this._renderHeaders();
- if (IS_ARRAY(obj)) {
+ if (util.isArray(obj)) {
// handle array case
// TODO: remove when array is no longer accepted
var field;
for (var i = 0, len = obj.length; i < len; ++i) {
field = obj[i][0];
- if (!IS_UNDEFINED(headers[field])) {
+ if (!util.isUndefined(headers[field])) {
obj.push([field, headers[field]]);
}
}
@@ -332,7 +332,7 @@ function connectionListener(socket) {
parser.incoming = null;
// Propagate headers limit from server instance to parser
- if (IS_NUMBER(this.maxHeadersCount)) {
+ if (util.isNumber(this.maxHeadersCount)) {
parser.maxHeaderPairs = this.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
@@ -442,7 +442,7 @@ function connectionListener(socket) {
}
});
- if (!IS_UNDEFINED(req.headers.expect) &&
+ if (!util.isUndefined(req.headers.expect) &&
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1) &&
continueExpression.test(req.headers['expect'])) {
res._expect_continue = true;
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 1b6e4cee0..0f155f3c0 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -111,7 +111,7 @@ function Readable(options) {
Readable.prototype.push = function(chunk, encoding) {
var state = this._readableState;
- if (IS_STRING(chunk) && !state.objectMode) {
+ if (util.isString(chunk) && !state.objectMode) {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = new Buffer(chunk, encoding);
@@ -132,7 +132,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
var er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
- } else if (IS_NULL_OR_UNDEFINED(chunk)) {
+ } else if (util.isNullOrUndefined(chunk)) {
state.reading = false;
if (!state.ended)
onEofChunk(stream, state);
@@ -213,7 +213,7 @@ function howMuchToRead(n, state) {
if (state.objectMode)
return n === 0 ? 0 : 1;
- if (isNaN(n) || IS_NULL(n)) {
+ if (isNaN(n) || util.isNull(n)) {
// only flow one buffer at a time
if (state.flowing && state.buffer.length)
return state.buffer[0].length;
@@ -249,7 +249,7 @@ Readable.prototype.read = function(n) {
var state = this._readableState;
var nOrig = n;
- if (!IS_NUMBER(n) || n > 0)
+ if (!util.isNumber(n) || n > 0)
state.emittedReadable = false;
// if we're doing read(0) to trigger a readable event, but we
@@ -337,7 +337,7 @@ Readable.prototype.read = function(n) {
else
ret = null;
- if (IS_NULL(ret)) {
+ if (util.isNull(ret)) {
state.needReadable = true;
n = 0;
}
@@ -353,7 +353,7 @@ Readable.prototype.read = function(n) {
if (nOrig !== n && state.ended && state.length === 0)
endReadable(this);
- if (!IS_NULL(ret))
+ if (!util.isNull(ret))
this.emit('data', ret);
return ret;
@@ -361,9 +361,9 @@ Readable.prototype.read = function(n) {
function chunkInvalid(state, chunk) {
var er = null;
- if (!IS_BUFFER(chunk) &&
- !IS_STRING(chunk) &&
- !IS_NULL_OR_UNDEFINED(chunk) &&
+ if (!util.isBuffer(chunk) &&
+ !util.isString(chunk) &&
+ !util.isNullOrUndefined(chunk) &&
!state.objectMode &&
!er) {
er = new TypeError('Invalid non-string/buffer chunk');
@@ -761,7 +761,7 @@ Readable.prototype.wrap = function(stream) {
// proxy all the other methods.
// important when wrapping filters and duplexes.
for (var i in stream) {
- if (IS_FUNCTION(stream[i]) && IS_UNDEFINED(this[i])) {
+ if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
this[i] = function(method) { return function() {
return stream[method].apply(stream, arguments);
}}(i);
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
index 735f2cf5e..d2bdcffe6 100644
--- a/lib/_stream_transform.js
+++ b/lib/_stream_transform.js
@@ -92,7 +92,7 @@ function afterTransform(stream, er, data) {
ts.writechunk = null;
ts.writecb = null;
- if (!IS_NULL_OR_UNDEFINED(data))
+ if (!util.isNullOrUndefined(data))
stream.push(data);
if (cb)
@@ -126,7 +126,7 @@ function Transform(options) {
this._readableState.sync = false;
this.once('prefinish', function() {
- if (IS_FUNCTION(this._flush))
+ if (util.isFunction(this._flush))
this._flush(function(er) {
done(stream, er);
});
@@ -174,7 +174,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
Transform.prototype._read = function(n) {
var ts = this._transformState;
- if (!IS_NULL(ts.writechunk) && ts.writecb && !ts.transforming) {
+ if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
ts.transforming = true;
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
} else {
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index a6b02f6c2..de96f83ed 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -153,9 +153,9 @@ function writeAfterEnd(stream, state, cb) {
// how many bytes or characters.
function validChunk(stream, state, chunk, cb) {
var valid = true;
- if (!IS_BUFFER(chunk) &&
- !IS_STRING(chunk) &&
- !IS_NULL_OR_UNDEFINED(chunk) &&
+ if (!util.isBuffer(chunk) &&
+ !util.isString(chunk) &&
+ !util.isNullOrUndefined(chunk) &&
!state.objectMode) {
var er = new TypeError('Invalid non-string/buffer chunk');
stream.emit('error', er);
@@ -171,17 +171,17 @@ Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
- if (IS_FUNCTION(encoding)) {
+ if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
- if (IS_BUFFER(chunk))
+ if (util.isBuffer(chunk))
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
- if (!IS_FUNCTION(cb))
+ if (!util.isFunction(cb))
cb = function() {};
if (state.ended)
@@ -216,7 +216,9 @@ Writable.prototype.uncork = function() {
};
function decodeChunk(state, chunk, encoding) {
- if (!state.objectMode && state.decodeStrings !== false && IS_STRING(chunk)) {
+ if (!state.objectMode &&
+ state.decodeStrings !== false &&
+ util.isString(chunk)) {
chunk = new Buffer(chunk, encoding);
}
return chunk;
@@ -227,7 +229,7 @@ function decodeChunk(state, chunk, encoding) {
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, chunk, encoding, cb) {
chunk = decodeChunk(state, chunk, encoding);
- if (IS_BUFFER(chunk))
+ if (util.isBuffer(chunk))
encoding = 'buffer';
var len = state.objectMode ? 1 : chunk.length;
@@ -388,16 +390,16 @@ Writable.prototype._writev = null;
Writable.prototype.end = function(chunk, encoding, cb) {
var state = this._writableState;
- if (IS_FUNCTION(chunk)) {
+ if (util.isFunction(chunk)) {
cb = chunk;
chunk = null;
encoding = null;
- } else if (IS_FUNCTION(encoding)) {
+ } else if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
- if (!IS_NULL_OR_UNDEFINED(chunk))
+ if (!util.isNullOrUndefined(chunk))
this.write(chunk, encoding);
// .end() fully uncorks
diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js
index 6c85251c1..b5860a17e 100644
--- a/lib/_tls_legacy.js
+++ b/lib/_tls_legacy.js
@@ -36,7 +36,7 @@ SlabBuffer.prototype.use = function use(context, fn, size) {
var actualSize = this.remaining;
- if (!IS_NULL(size)) actualSize = Math.min(size, actualSize);
+ if (!util.isNull(size)) actualSize = Math.min(size, actualSize);
var bytes = fn.call(context, this.pool, this.offset, actualSize);
if (bytes > 0) {
@@ -72,7 +72,7 @@ function CryptoStream(pair, options) {
this._finished = false;
this._opposite = null;
- if (IS_NULL(slabBuffer)) slabBuffer = new SlabBuffer();
+ if (util.isNull(slabBuffer)) slabBuffer = new SlabBuffer();
this._buffer = slabBuffer;
this.once('finish', onCryptoStreamFinish);
@@ -144,7 +144,7 @@ CryptoStream.prototype.init = function init() {
CryptoStream.prototype._write = function write(data, encoding, cb) {
- assert(IS_NULL(this._pending));
+ assert(util.isNull(this._pending));
// Black-hole data
if (!this.pair.ssl) return cb(null);
@@ -191,7 +191,7 @@ CryptoStream.prototype._write = function write(data, encoding, cb) {
// Invoke callback only when all data read from opposite stream
if (this._opposite._halfRead) {
- assert(IS_NULL(this._sslOutCb));
+ assert(util.isNull(this._sslOutCb));
this._sslOutCb = cb;
} else {
cb(null);
@@ -285,8 +285,8 @@ CryptoStream.prototype._read = function read(size) {
}
// Try writing pending data
- if (!IS_NULL(this._pending)) this._writePending();
- if (!IS_NULL(this._opposite._pending)) this._opposite._writePending();
+ if (!util.isNull(this._pending)) this._writePending();
+ if (!util.isNull(this._opposite._pending)) this._opposite._writePending();
if (bytesRead === 0) {
// EOF when cleartext has finished and we have nothing to read
@@ -405,7 +405,7 @@ CryptoStream.prototype.end = function(chunk, encoding) {
}
// Write pending data first
- if (!IS_NULL(this._pending)) this._writePending();
+ if (!util.isNull(this._pending)) this._writePending();
this.writable = false;
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index 65c0fd94c..1a5c6cb39 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -208,7 +208,7 @@ TLSSocket.prototype.setServername = function(name) {
};
TLSSocket.prototype.setSession = function(session) {
- if (IS_STRING(session))
+ if (util.isString(session))
session = new Buffer(session, 'binary');
this.ssl.setSession(session);
};
@@ -320,10 +320,10 @@ TLSSocket.prototype.getCipher = function(err) {
//
function Server(/* [options], listener */) {
var options, listener;
- if (IS_OBJECT(arguments[0])) {
+ if (util.isObject(arguments[0])) {
options = arguments[0];
listener = arguments[1];
- } else if (IS_FUNCTION(arguments[0])) {
+ } else if (util.isFunction(arguments[0])) {
options = {};
listener = arguments[0];
}
@@ -357,7 +357,7 @@ function Server(/* [options], listener */) {
var timeout = options.handshakeTimeout || (120 * 1000);
- if (!IS_NUMBER(timeout)) {
+ if (!util.isNumber(timeout)) {
throw new TypeError('handshakeTimeout must be a number');
}
@@ -441,13 +441,13 @@ Server.prototype._setServerData = function(data) {
Server.prototype.setOptions = function(options) {
- if (IS_BOOLEAN(options.requestCert)) {
+ if (util.isBoolean(options.requestCert)) {
this.requestCert = options.requestCert;
} else {
this.requestCert = false;
}
- if (IS_BOOLEAN(options.rejectUnauthorized)) {
+ if (util.isBoolean(options.rejectUnauthorized)) {
this.rejectUnauthorized = options.rejectUnauthorized;
} else {
this.rejectUnauthorized = false;
@@ -499,7 +499,7 @@ Server.prototype.SNICallback = function(servername) {
var ctx;
this._contexts.some(function(elem) {
- if (!IS_NULL(servername.match(elem[0]))) {
+ if (!util.isNull(servername.match(elem[0]))) {
ctx = elem[1];
return true;
}
@@ -528,9 +528,9 @@ function normalizeConnectArgs(listArgs) {
var options = args[0];
var cb = args[1];
- if (IS_OBJECT(listArgs[1])) {
+ if (util.isObject(listArgs[1])) {
options = util._extend(options, listArgs[1]);
- } else if (IS_OBJECT(listArgs[2])) {
+ } else if (util.isObject(listArgs[2])) {
options = util._extend(options, listArgs[2]);
}
diff --git a/lib/assert.js b/lib/assert.js
index 63a69390d..1202f4baa 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -51,20 +51,20 @@ assert.AssertionError = function AssertionError(options) {
util.inherits(assert.AssertionError, Error);
function replacer(key, value) {
- if (IS_UNDEFINED(value)) {
+ if (util.isUndefined(value)) {
return '' + value;
}
- if (IS_NUMBER(value) && (isNaN(value) || !isFinite(value))) {
+ if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
return value.toString();
}
- if (IS_FUNCTION(value) || IS_REGEXP(value)) {
+ if (util.isFunction(value) || util.isRegExp(value)) {
return value.toString();
}
return value;
}
function truncate(s, n) {
- if (IS_STRING(s)) {
+ if (util.isString(s)) {
return s.length < n ? s : s.slice(0, n);
} else {
return s;
@@ -144,7 +144,7 @@ function _deepEqual(actual, expected) {
if (actual === expected) {
return true;
- } else if (IS_BUFFER(actual) && IS_BUFFER(expected)) {
+ } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
@@ -155,13 +155,13 @@ function _deepEqual(actual, expected) {
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
- } else if (IS_DATE(actual) && IS_DATE(expected)) {
+ } else if (util.isDate(actual) && util.isDate(expected)) {
return actual.getTime() === expected.getTime();
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source and
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
- } else if (IS_REGEXP(actual) && IS_REGEXP(expected)) {
+ } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
@@ -170,7 +170,7 @@ function _deepEqual(actual, expected) {
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
- } else if (!IS_OBJECT(actual) && !IS_OBJECT(expected)) {
+ } else if (!util.isObject(actual) && !util.isObject(expected)) {
return actual == expected;
// 7.5 For all other Object pairs, including Array objects, equivalence is
@@ -189,7 +189,7 @@ function isArguments(object) {
}
function objEquiv(a, b) {
- if (IS_NULL_OR_UNDEFINED(a) || IS_NULL_OR_UNDEFINED(b))
+ if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
return false;
// an identical 'prototype' property.
if (a.prototype !== b.prototype) return false;
@@ -277,7 +277,7 @@ function expectedException(actual, expected) {
function _throws(shouldThrow, block, expected, message) {
var actual;
- if (IS_STRING(expected)) {
+ if (util.isString(expected)) {
message = expected;
expected = null;
}
diff --git a/lib/buffer.js b/lib/buffer.js
index 83f23e94d..68f3f17f3 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -48,16 +48,16 @@ function createPool() {
function Buffer(subject, encoding) {
- if (!IS_BUFFER(this))
+ if (!util.isBuffer(this))
return new Buffer(subject, encoding);
- if (IS_NUMBER(subject))
+ if (util.isNumber(subject))
this.length = subject > 0 ? Math.floor(subject) : 0;
- else if (IS_STRING(subject))
+ else if (util.isString(subject))
this.length = Buffer.byteLength(subject, encoding = encoding || 'utf8');
- else if (IS_OBJECT(subject))
+ else if (util.isObject(subject))
this.length = +subject.length > 0 ? Math.floor(+subject.length) : 0;
- else if (IS_UNDEFINED(subject)) {
+ else if (util.isUndefined(subject)) {
// undef first arg returns unallocated buffer, also assumes length passed.
// this is a stop-gap for now while look for better architecture.
// for internal use only.
@@ -82,14 +82,14 @@ function Buffer(subject, encoding) {
alloc(this, this.length);
}
- if (!IS_NUMBER(subject)) {
- if (IS_STRING(subject)) {
+ if (!util.isNumber(subject)) {
+ if (util.isString(subject)) {
// FIXME: the number of bytes hasn't changed, so why change the length?
this.length = this.write(subject, 0, encoding);
} else {
- if (IS_BUFFER(subject))
+ if (util.isBuffer(subject))
this.copy(subject, 0, 0, this.length);
- else if (IS_NUMBER(subject.length) || IS_ARRAY(subject))
+ else if (util.isNumber(subject.length) || util.isArray(subject))
for (var i = 0; i < this.length; i++)
this[i] = subject[i];
}
@@ -108,7 +108,7 @@ function SlowBuffer(length) {
// Static methods
Buffer.isBuffer = function isBuffer(b) {
- return IS_BUFFER(b);
+ return util.isBuffer(b);
};
@@ -134,10 +134,10 @@ Buffer.isEncoding = function(encoding) {
Buffer.concat = function(list, length) {
- if (!IS_ARRAY(list))
+ if (!util.isArray(list))
throw new TypeError('Usage: Buffer.concat(list[, length])');
- if (IS_UNDEFINED(length)) {
+ if (util.isUndefined(length)) {
length = 0;
for (var i = 0; i < list.length; i++)
length += list[i].length;
@@ -174,7 +174,7 @@ Buffer.prototype.toString = function(encoding, start, end) {
encoding = !!encoding ? (encoding + '').toLowerCase() : 'utf8';
start = ~~start;
- end = IS_UNDEFINED(end) ? this.length : ~~end;
+ end = util.isUndefined(end) ? this.length : ~~end;
if (start < 0) start = 0;
if (end > this.length) end = this.length;
@@ -243,7 +243,7 @@ var writeMsg = '.write(string, encoding, offset, length) is deprecated.' +
' Use write(string, offset, length, encoding) instead.';
Buffer.prototype.write = function(string, offset, length, encoding) {
// allow write(string, encoding)
- if (IS_STRING(offset) && IS_UNDEFINED(length)) {
+ if (util.isString(offset) && util.isUndefined(length)) {
encoding = offset;
offset = 0;
@@ -276,7 +276,7 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
}
var remaining = this.length - offset;
- if (IS_UNDEFINED(length) || length > remaining)
+ if (util.isUndefined(length) || length > remaining)
length = remaining;
encoding = !!encoding ? (encoding + '').toLowerCase() : 'utf8';
@@ -336,7 +336,7 @@ Buffer.prototype.toJSON = function() {
Buffer.prototype.slice = function(start, end) {
var len = this.length;
start = ~~start;
- end = IS_UNDEFINED(end) ? len : ~~end;
+ end = util.isUndefined(end) ? len : ~~end;
if (start < 0) {
start += len;
@@ -361,7 +361,7 @@ Buffer.prototype.slice = function(start, end) {
sliceOnto(this, buf, start, end);
buf.length = end - start;
if (buf.length > 0)
- buf.parent = IS_UNDEFINED(this.parent) ? this : this.parent;
+ buf.parent = util.isUndefined(this.parent) ? this : this.parent;
return buf;
};
diff --git a/lib/child_process.js b/lib/child_process.js
index b034fa65c..a0a250963 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -39,7 +39,7 @@ function handleWrapGetter(name, callback) {
Object.defineProperty(handleWraps, name, {
get: function() {
- if (!IS_UNDEFINED(cons)) return cons;
+ if (!util.isUndefined(cons)) return cons;
return cons = callback();
}
});
@@ -312,9 +312,9 @@ function getSocketList(type, slave, key) {
var INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
var eventName = 'message';
- if (!IS_NULL(message) &&
- IS_OBJECT(message) &&
- IS_STRING(message.cmd) &&
+ if (!util.isNull(message) &&
+ util.isObject(message) &&
+ util.isString(message.cmd) &&
message.cmd.length > INTERNAL_PREFIX.length &&
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
eventName = 'internalMessage';
@@ -370,7 +370,7 @@ function setupChannel(target, channel) {
target.on('internalMessage', function(message, handle) {
// Once acknowledged - continue sending handles.
if (message.cmd === 'NODE_HANDLE_ACK') {
- assert(IS_ARRAY(target._handleQueue));
+ assert(util.isArray(target._handleQueue));
var queue = target._handleQueue;
target._handleQueue = null;
queue.forEach(function(args) {
@@ -399,7 +399,7 @@ function setupChannel(target, channel) {
});
target.send = function(message, handle) {
- if (IS_UNDEFINED(message)) {
+ if (util.isUndefined(message)) {
throw new TypeError('message cannot be undefined');
}
@@ -512,7 +512,7 @@ exports.fork = function(modulePath /*, args, options*/) {
// Get options and args arguments.
var options, args, execArgv;
- if (IS_ARRAY(arguments[1])) {
+ if (util.isArray(arguments[1])) {
args = arguments[1];
options = util._extend({}, arguments[2]);
} else {
@@ -557,7 +557,7 @@ exports._forkChild = function(fd) {
exports.exec = function(command /*, options, callback */) {
var file, args, options, callback;
- if (IS_FUNCTION(arguments[1])) {
+ if (util.isFunction(arguments[1])) {
options = undefined;
callback = arguments[1];
} else {
@@ -597,11 +597,11 @@ exports.execFile = function(file /* args, options, callback */) {
// Parse the parameters.
- if (IS_FUNCTION(arguments[arguments.length - 1])) {
+ if (util.isFunction(arguments[arguments.length - 1])) {
callback = arguments[arguments.length - 1];
}
- if (IS_ARRAY(arguments[1])) {
+ if (util.isArray(arguments[1])) {
args = arguments[1];
options = util._extend(options, arguments[2]);
} else {
@@ -839,14 +839,14 @@ ChildProcess.prototype.spawn = function(options) {
stdio = options.stdio || 'pipe';
// Replace shortcut with an array
- if (IS_STRING(stdio)) {
+ if (util.isString(stdio)) {
switch (stdio) {
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break;
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break;
case 'inherit': stdio = [0, 1, 2]; break;
default: throw new TypeError('Incorrect value of stdio option: ' + stdio);
}
- } else if (!IS_ARRAY(stdio)) {
+ } else if (!util.isArray(stdio)) {
throw new TypeError('Incorrect value of stdio option: ' + stdio);
}
@@ -868,16 +868,16 @@ ChildProcess.prototype.spawn = function(options) {
}
// Defaults
- if (IS_NULL_OR_UNDEFINED(stdio)) {
+ if (util.isNullOrUndefined(stdio)) {
stdio = i < 3 ? 'pipe' : 'ignore';
}
if (stdio === 'ignore') {
acc.push({type: 'ignore'});
- } else if (stdio === 'pipe' || IS_NUMBER(stdio) && stdio < 0) {
+ } else if (stdio === 'pipe' || util.isNumber(stdio) && stdio < 0) {
acc.push({type: 'pipe', handle: createPipe()});
} else if (stdio === 'ipc') {
- if (!IS_UNDEFINED(ipc)) {
+ if (!util.isUndefined(ipc)) {
// Cleanup previously created pipes
cleanup();
throw Error('Child process can have only one IPC pipe');
@@ -887,7 +887,7 @@ ChildProcess.prototype.spawn = function(options) {
ipcFd = i;
acc.push({ type: 'pipe', handle: ipc, ipc: true });
- } else if (IS_NUMBER(stdio) || IS_NUMBER(stdio.fd)) {
+ } else if (util.isNumber(stdio) || util.isNumber(stdio.fd)) {
acc.push({ type: 'fd', fd: stdio.fd || stdio });
} else if (getHandleWrapType(stdio) || getHandleWrapType(stdio.handle) ||
getHandleWrapType(stdio._handle)) {
@@ -911,7 +911,7 @@ ChildProcess.prototype.spawn = function(options) {
options.stdio = stdio;
- if (!IS_UNDEFINED(ipc)) {
+ if (!util.isUndefined(ipc)) {
// Let child process know about opened IPC channel
options.envPairs = options.envPairs || [];
options.envPairs.push('NODE_CHANNEL_FD=' + ipcFd);
@@ -956,19 +956,19 @@ ChildProcess.prototype.spawn = function(options) {
}
});
- this.stdin = stdio.length >= 1 && !IS_UNDEFINED(stdio[0].socket) ?
+ this.stdin = stdio.length >= 1 && !util.isUndefined(stdio[0].socket) ?
stdio[0].socket : null;
- this.stdout = stdio.length >= 2 && !IS_UNDEFINED(stdio[1].socket) ?
+ this.stdout = stdio.length >= 2 && !util.isUndefined(stdio[1].socket) ?
stdio[1].socket : null;
- this.stderr = stdio.length >= 3 && !IS_UNDEFINED(stdio[2].socket) ?
+ this.stderr = stdio.length >= 3 && !util.isUndefined(stdio[2].socket) ?
stdio[2].socket : null;
this.stdio = stdio.map(function(stdio) {
- return IS_UNDEFINED(stdio.socket) ? null : stdio.socket;
+ return util.isUndefined(stdio.socket) ? null : stdio.socket;
});
// Add .send() method and start listening for IPC data
- if (!IS_UNDEFINED(ipc)) setupChannel(this, ipc);
+ if (!util.isUndefined(ipc)) setupChannel(this, ipc);
return err;
};
@@ -989,7 +989,7 @@ ChildProcess.prototype.kill = function(sig) {
signal = constants[sig];
}
- if (IS_UNDEFINED(signal)) {
+ if (util.isUndefined(signal)) {
throw new Error('Unknown signal: ' + sig);
}
diff --git a/lib/cluster.js b/lib/cluster.js
index a9ae012ce..50a94f1d0 100644
--- a/lib/cluster.js
+++ b/lib/cluster.js
@@ -67,7 +67,7 @@ function SharedHandle(key, address, port, addressType, backlog, fd) {
else
rval = net._createServerHandle(address, port, addressType, fd);
- if (IS_NUMBER(rval))
+ if (util.isNumber(rval))
this.errno = rval;
else
this.handle = rval;
@@ -134,7 +134,7 @@ RoundRobinHandle.prototype.add = function(worker, send) {
self.handoff(worker); // In case there are connections pending.
}
- if (IS_NULL(this.server)) return done();
+ if (util.isNull(this.server)) return done();
// Still busy binding.
this.server.once('listening', done);
this.server.once('error', function(err) {
@@ -169,7 +169,7 @@ RoundRobinHandle.prototype.handoff = function(worker) {
return; // Worker is closing (or has closed) the server.
}
var handle = this.handles.shift();
- if (IS_UNDEFINED(handle)) {
+ if (util.isUndefined(handle)) {
this.free.push(worker); // Add to ready queue again.
return;
}
@@ -228,7 +228,7 @@ function masterInit() {
'rr': SCHED_RR
}[process.env.NODE_CLUSTER_SCHED_POLICY];
- if (IS_UNDEFINED(schedulingPolicy)) {
+ if (util.isUndefined(schedulingPolicy)) {
// FIXME Round-robin doesn't perform well on Windows right now due to the
// way IOCP is wired up. Bert is going to fix that, eventually.
schedulingPolicy = (process.platform === 'win32') ? SCHED_NONE : SCHED_RR;
@@ -370,7 +370,7 @@ function masterInit() {
message.fd];
var key = args.join(':');
var handle = handles[key];
- if (IS_UNDEFINED(handle)) {
+ if (util.isUndefined(handle)) {
var constructor = RoundRobinHandle;
// UDP is exempt from round-robin connection balancing for what should
// be obvious reasons: it's connectionless. There is nothing to send to
@@ -487,7 +487,7 @@ function workerInit() {
delete handles[key];
return close.apply(this, arguments);
};
- assert(IS_UNDEFINED(handles[key]));
+ assert(util.isUndefined(handles[key]));
handles[key] = handle;
cb(message.errno, handle);
}
@@ -511,7 +511,7 @@ function workerInit() {
// the ack by the master process in which we can still receive handles.
// onconnection() below handles that by sending those handles back to
// the master.
- if (IS_UNDEFINED(key)) return;
+ if (util.isUndefined(key)) return;
send({ act: 'close', key: key });
delete handles[key];
key = undefined;
@@ -532,7 +532,7 @@ function workerInit() {
if (message.sockname) {
handle.getsockname = getsockname; // TCP handles only.
}
- assert(IS_UNDEFINED(handles[key]));
+ assert(util.isUndefined(handles[key]));
handles[key] = handle;
cb(0, handle);
}
@@ -541,7 +541,7 @@ function workerInit() {
function onconnection(message, handle) {
var key = message.key;
var server = handles[key];
- var accepted = !IS_UNDEFINED(server);
+ var accepted = !util.isUndefined(server);
send({ ack: message.seq, accepted: accepted });
if (accepted) server.onconnection(0, handle);
}
@@ -587,7 +587,7 @@ function internal(worker, cb) {
return function(message, handle) {
if (message.cmd !== 'NODE_CLUSTER') return;
var fn = cb;
- if (!IS_UNDEFINED(message.ack)) {
+ if (!util.isUndefined(message.ack)) {
fn = callbacks[message.ack];
delete callbacks[message.ack];
}
diff --git a/lib/console.js b/lib/console.js
index fd7722f0d..1c9816710 100644
--- a/lib/console.js
+++ b/lib/console.js
@@ -25,7 +25,7 @@ function Console(stdout, stderr) {
if (!(this instanceof Console)) {
return new Console(stdout, stderr);
}
- if (!stdout || !IS_FUNCTION(stdout.write)) {
+ if (!stdout || !util.isFunction(stdout.write)) {
throw new TypeError('Console expects a writable stream instance');
}
if (!stderr) {
diff --git a/lib/crypto.js b/lib/crypto.js
index c450f1c15..9cfc09e3c 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -43,7 +43,7 @@ var util = require('util');
// to break them unnecessarily.
function toBuf(str, encoding) {
encoding = encoding || 'binary';
- if (IS_STRING(str)) {
+ if (util.isString(str)) {
if (encoding === 'buffer')
encoding = 'binary';
str = new Buffer(str, encoding);
@@ -100,7 +100,7 @@ exports.createCredentials = function(options, context) {
if (options.ciphers) c.context.setCiphers(options.ciphers);
if (options.ca) {
- if (IS_ARRAY(options.ca)) {
+ if (util.isArray(options.ca)) {
for (var i = 0, len = options.ca.length; i < len; i++) {
c.context.addCACert(options.ca[i]);
}
@@ -112,7 +112,7 @@ exports.createCredentials = function(options, context) {
}
if (options.crl) {
- if (IS_ARRAY(options.crl)) {
+ if (util.isArray(options.crl)) {
for (var i = 0, len = options.crl.length; i < len; i++) {
c.context.addCRL(options.crl[i]);
}
@@ -198,7 +198,7 @@ Hash.prototype._flush = function(callback) {
Hash.prototype.update = function(data, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
- if (encoding === 'buffer' && IS_STRING(data))
+ if (encoding === 'buffer' && util.isString(data))
encoding = 'binary';
this._binding.update(data, encoding);
return this;
@@ -539,7 +539,7 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
exports.pbkdf2 = function(password, salt, iterations, keylen, callback) {
- if (!IS_FUNCTION(callback))
+ if (!util.isFunction(callback))
throw new Error('No callback provided to pbkdf2');
return pbkdf2(password, salt, iterations, keylen, callback);
diff --git a/lib/dgram.js b/lib/dgram.js
index 3ea0665e6..7db3f16e0 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -91,7 +91,7 @@ function newHandle(type) {
exports._createSocketHandle = function(address, port, addressType, fd) {
// Opening an existing fd is not supported for UDP handles.
- assert(!IS_NUMBER(fd) || fd < 0);
+ assert(!util.isNumber(fd) || fd < 0);
var handle = newHandle(addressType);
@@ -119,7 +119,7 @@ function Socket(type, listener) {
this.type = type;
this.fd = null; // compatibility hack
- if (IS_FUNCTION(listener))
+ if (util.isFunction(listener))
this.on('message', listener);
}
util.inherits(Socket, events.EventEmitter);
@@ -165,7 +165,7 @@ Socket.prototype.bind = function(/*port, address, callback*/) {
this._bindState = BIND_STATE_BINDING;
- if (IS_FUNCTION(arguments[arguments.length - 1]))
+ if (util.isFunction(arguments[arguments.length - 1]))
self.once('listening', arguments[arguments.length - 1]);
var UDP = process.binding('udp_wrap').UDP;
@@ -177,7 +177,7 @@ Socket.prototype.bind = function(/*port, address, callback*/) {
var port = arguments[0];
var address = arguments[1];
- if (IS_FUNCTION(address)) address = ''; // a.k.a. "any address"
+ if (util.isFunction(address)) address = ''; // a.k.a. "any address"
// resolve address first
self._handle.lookup(address, function(err, ip) {
@@ -231,10 +231,10 @@ Socket.prototype.sendto = function(buffer,
port,
address,
callback) {
- if (!IS_NUMBER(offset) || !IS_NUMBER(length))
+ if (!util.isNumber(offset) || !util.isNumber(length))
throw new Error('send takes offset and length as args 2 and 3');
- if (!IS_STRING(address))
+ if (!util.isString(address))
throw new Error(this.type + ' sockets must send to port, address');
this.send(buffer, offset, length, port, address, callback);
@@ -249,7 +249,7 @@ Socket.prototype.send = function(buffer,
callback) {
var self = this;
- if (!IS_BUFFER(buffer))
+ if (!util.isBuffer(buffer))
throw new TypeError('First argument must be a buffer object.');
if (offset >= buffer.length)
@@ -339,7 +339,7 @@ Socket.prototype.setBroadcast = function(arg) {
Socket.prototype.setTTL = function(arg) {
- if (!IS_NUMBER(arg)) {
+ if (!util.isNumber(arg)) {
throw new TypeError('Argument must be a number');
}
@@ -353,7 +353,7 @@ Socket.prototype.setTTL = function(arg) {
Socket.prototype.setMulticastTTL = function(arg) {
- if (!IS_NUMBER(arg)) {
+ if (!util.isNumber(arg)) {
throw new TypeError('Argument must be a number');
}
diff --git a/lib/dns.js b/lib/dns.js
index e92b180e9..8e6ed5c06 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -61,7 +61,7 @@ function errnoException(err, syscall) {
// callback.immediately = true;
// }
function makeAsync(callback) {
- if (!IS_FUNCTION(callback)) {
+ if (!util.isFunction(callback)) {
return callback;
}
return function asyncCallback() {
@@ -178,7 +178,7 @@ exports.reverse = resolveMap.PTR = resolver('getHostByAddr');
exports.resolve = function(domain, type_, callback_) {
var resolver, callback;
- if (IS_STRING(type_)) {
+ if (util.isString(type_)) {
resolver = resolveMap[type_];
callback = callback_;
} else {
@@ -186,7 +186,7 @@ exports.resolve = function(domain, type_, callback_) {
callback = type_;
}
- if (IS_FUNCTION(resolver)) {
+ if (util.isFunction(resolver)) {
return resolver(domain, callback);
} else {
throw new Error('Unknown type "' + type_ + '"');
diff --git a/lib/domain.js b/lib/domain.js
index 364d8c7d4..ac02f455e 100644
--- a/lib/domain.js
+++ b/lib/domain.js
@@ -219,7 +219,7 @@ Domain.prototype.dispose = function() {
// so it's quite possible that calling some of these methods
// might cause additional exceptions to be thrown.
endMethods.forEach(function(method) {
- if (IS_FUNCTION(m[method])) {
+ if (util.isFunction(m[method])) {
try {
m[method]();
} catch (er) {}
diff --git a/lib/events.js b/lib/events.js
index b69dc8f20..0e5e85f96 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -20,6 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var domain;
+var util = require('util');
exports.usingDomains = false;
@@ -49,7 +50,7 @@ EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
- if (!IS_NUMBER(n) || n < 0)
+ if (!util.isNumber(n) || n < 0)
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
@@ -64,7 +65,7 @@ EventEmitter.prototype.emit = function(type) {
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
- (IS_OBJECT(this._events.error) && !this._events.error.length)) {
+ (util.isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (this.domain) {
if (!er) er = new TypeError('Uncaught, unspecified "error" event.');
@@ -83,13 +84,13 @@ EventEmitter.prototype.emit = function(type) {
handler = this._events[type];
- if (IS_UNDEFINED(handler))
+ if (util.isUndefined(handler))
return false;
if (this.domain && this !== process)
this.domain.enter();
- if (IS_FUNCTION(handler)) {
+ if (util.isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
@@ -109,7 +110,7 @@ EventEmitter.prototype.emit = function(type) {
args[i - 1] = arguments[i];
handler.apply(this, args);
}
- } else if (IS_OBJECT(handler)) {
+ } else if (util.isObject(handler)) {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
@@ -130,7 +131,7 @@ EventEmitter.prototype.emit = function(type) {
EventEmitter.prototype.addListener = function(type, listener) {
var m;
- if (!IS_FUNCTION(listener))
+ if (!util.isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
@@ -140,12 +141,13 @@ EventEmitter.prototype.addListener = function(type, listener) {
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
- IS_FUNCTION(listener.listener) ? listener.listener : listener);
+ util.isFunction(listener.listener) ?
+ listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
- else if (IS_OBJECT(this._events[type]))
+ else if (util.isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
@@ -153,9 +155,9 @@ EventEmitter.prototype.addListener = function(type, listener) {
this._events[type] = [this._events[type], listener];
// Check for listener leak
- if (IS_OBJECT(this._events[type]) && !this._events[type].warned) {
+ if (util.isObject(this._events[type]) && !this._events[type].warned) {
var m;
- if (!IS_UNDEFINED(this._maxListeners)) {
+ if (!util.isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
@@ -177,7 +179,7 @@ EventEmitter.prototype.addListener = function(type, listener) {
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
- if (!IS_FUNCTION(listener))
+ if (!util.isFunction(listener))
throw TypeError('listener must be a function');
function g() {
@@ -195,7 +197,7 @@ EventEmitter.prototype.once = function(type, listener) {
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
- if (!IS_FUNCTION(listener))
+ if (!util.isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
@@ -206,12 +208,12 @@ EventEmitter.prototype.removeListener = function(type, listener) {
position = -1;
if (list === listener ||
- (IS_FUNCTION(list.listener) && list.listener === listener)) {
+ (util.isFunction(list.listener) && list.listener === listener)) {
this._events[type] = undefined;
if (this._events.removeListener)
this.emit('removeListener', type, listener);
- } else if (IS_OBJECT(list)) {
+ } else if (util.isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
@@ -265,7 +267,7 @@ EventEmitter.prototype.removeAllListeners = function(type) {
listeners = this._events[type];
- if (IS_FUNCTION(listeners)) {
+ if (util.isFunction(listeners)) {
this.removeListener(type, listeners);
} else {
// LIFO order
@@ -281,7 +283,7 @@ EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
- else if (IS_FUNCTION(this._events[type]))
+ else if (util.isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
@@ -292,7 +294,7 @@ EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
- else if (IS_FUNCTION(emitter._events[type]))
+ else if (util.isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
diff --git a/lib/fs.js b/lib/fs.js
index 78e63c9c7..3a3fe56c2 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -81,14 +81,14 @@ function rethrow() {
}
function maybeCallback(cb) {
- return IS_FUNCTION(cb) ? cb : rethrow();
+ return util.isFunction(cb) ? cb : rethrow();
}
// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
function makeCallback(cb) {
- if (!IS_FUNCTION(cb)) {
+ if (!util.isFunction(cb)) {
return rethrow();
}
@@ -171,13 +171,13 @@ fs.existsSync = function(path) {
fs.readFile = function(path, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (IS_FUNCTION(options) || !options) {
+ if (util.isFunction(options) || !options) {
options = { encoding: null, flag: 'r' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, flag: 'r' };
} else if (!options) {
options = { encoding: null, flag: 'r' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
@@ -260,9 +260,9 @@ fs.readFile = function(path, options, callback_) {
fs.readFileSync = function(path, options) {
if (!options) {
options = { encoding: null, flag: 'r' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, flag: 'r' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
@@ -332,7 +332,7 @@ fs.readFileSync = function(path, options) {
// Used by binding.open and friends
function stringToFlags(flag) {
// Only mess with strings
- if (!IS_STRING(flag)) {
+ if (!util.isString(flag)) {
return flag;
}
@@ -381,9 +381,9 @@ fs.closeSync = function(fd) {
};
function modeNum(m, def) {
- if (IS_NUMBER(m))
+ if (util.isNumber(m))
return m;
- if (IS_STRING(m))
+ if (util.isString(m))
return parseInt(m, 8);
if (def)
return modeNum(def);
@@ -408,7 +408,7 @@ fs.openSync = function(path, flags, mode) {
};
fs.read = function(fd, buffer, offset, length, position, callback) {
- if (!IS_BUFFER(buffer)) {
+ if (!util.isBuffer(buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
var cb = arguments[4],
encoding = arguments[3];
@@ -439,7 +439,7 @@ fs.read = function(fd, buffer, offset, length, position, callback) {
fs.readSync = function(fd, buffer, offset, length, position) {
var legacy = false;
- if (!IS_BUFFER(buffer)) {
+ if (!util.isBuffer(buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
legacy = true;
var encoding = arguments[3];
@@ -467,9 +467,9 @@ fs.readSync = function(fd, buffer, offset, length, position) {
// OR
// fs.write(fd, string[, position[, encoding]], callback);
fs.write = function(fd, buffer, offset, length, position, callback) {
- if (IS_BUFFER(buffer)) {
+ if (util.isBuffer(buffer)) {
// if no position is passed then assume null
- if (IS_FUNCTION(position)) {
+ if (util.isFunction(position)) {
callback = position;
position = null;
}
@@ -481,10 +481,10 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
return binding.writeBuffer(fd, buffer, offset, length, position, wrapper);
}
- if (IS_STRING(buffer))
+ if (util.isString(buffer))
buffer += '';
- if (!IS_FUNCTION(position)) {
- if (IS_FUNCTION(offset)) {
+ if (!util.isFunction(position)) {
+ if (util.isFunction(offset)) {
position = offset;
offset = null;
} else {
@@ -505,14 +505,14 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
// OR
// fs.writeSync(fd, string[, position[, encoding]]);
fs.writeSync = function(fd, buffer, offset, length, position) {
- if (IS_BUFFER(buffer)) {
- if (IS_UNDEFINED(position))
+ if (util.isBuffer(buffer)) {
+ if (util.isUndefined(position))
position = null;
return binding.writeBuffer(fd, buffer, offset, length, position);
}
- if (!IS_STRING(buffer))
+ if (!util.isString(buffer))
buffer += '';
- if (IS_UNDEFINED(offset))
+ if (util.isUndefined(offset))
offset = null;
return binding.writeString(fd, buffer, offset, length, position);
};
@@ -534,14 +534,14 @@ fs.renameSync = function(oldPath, newPath) {
};
fs.truncate = function(path, len, callback) {
- if (IS_NUMBER(path)) {
+ if (util.isNumber(path)) {
// legacy
return fs.ftruncate(path, len, callback);
}
- if (IS_FUNCTION(len)) {
+ if (util.isFunction(len)) {
callback = len;
len = 0;
- } else if (IS_UNDEFINED(len)) {
+ } else if (util.isUndefined(len)) {
len = 0;
}
callback = maybeCallback(callback);
@@ -556,11 +556,11 @@ fs.truncate = function(path, len, callback) {
};
fs.truncateSync = function(path, len) {
- if (IS_NUMBER(path)) {
+ if (util.isNumber(path)) {
// legacy
return fs.ftruncateSync(path, len);
}
- if (IS_UNDEFINED(len)) {
+ if (util.isUndefined(len)) {
len = 0;
}
// allow error to be thrown, but still close fd.
@@ -574,17 +574,17 @@ fs.truncateSync = function(path, len) {
};
fs.ftruncate = function(fd, len, callback) {
- if (IS_FUNCTION(len)) {
+ if (util.isFunction(len)) {
callback = len;
len = 0;
- } else if (IS_UNDEFINED(len)) {
+ } else if (util.isUndefined(len)) {
len = 0;
}
binding.ftruncate(fd, len, makeCallback(callback));
};
fs.ftruncateSync = function(fd, len) {
- if (IS_UNDEFINED(len)) {
+ if (util.isUndefined(len)) {
len = 0;
}
return binding.ftruncate(fd, len);
@@ -618,7 +618,7 @@ fs.fsyncSync = function(fd) {
};
fs.mkdir = function(path, mode, callback) {
- if (IS_FUNCTION(mode)) callback = mode;
+ if (util.isFunction(mode)) callback = mode;
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.mkdir(pathModule._makeLong(path),
@@ -698,7 +698,7 @@ function preprocessSymlinkDestination(path, type) {
}
fs.symlink = function(destination, path, type_, callback) {
- var type = (IS_STRING(type_) ? type_ : null);
+ var type = (util.isString(type_) ? type_ : null);
var callback = makeCallback(arguments[arguments.length - 1]);
if (!nullCheck(destination, callback)) return;
@@ -711,7 +711,7 @@ fs.symlink = function(destination, path, type_, callback) {
};
fs.symlinkSync = function(destination, path, type) {
- type = (IS_STRING(type) ? type : null);
+ type = (util.isString(type) ? type : null);
nullCheck(destination);
nullCheck(path);
@@ -849,10 +849,10 @@ fs.chownSync = function(path, uid, gid) {
// converts Date or number to a fractional UNIX timestamp
function toUnixTimestamp(time) {
- if (IS_NUMBER(time)) {
+ if (util.isNumber(time)) {
return time;
}
- if (IS_DATE(time)) {
+ if (util.isDate(time)) {
// convert to 123.456 UNIX timestamp
return time.getTime() / 1000;
}
@@ -915,13 +915,13 @@ function writeAll(fd, buffer, offset, length, position, callback) {
fs.writeFile = function(path, data, options, callback) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (IS_FUNCTION(options) || !options) {
+ if (util.isFunction(options) || !options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, mode: 438, flag: 'w' };
} else if (!options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
@@ -932,7 +932,7 @@ fs.writeFile = function(path, data, options, callback) {
if (openErr) {
if (callback) callback(openErr);
} else {
- var buffer = IS_BUFFER(data) ? data : new Buffer('' + data,
+ var buffer = util.isBuffer(data) ? data : new Buffer('' + data,
options.encoding || 'utf8');
var position = /a/.test(flag) ? null : 0;
writeAll(fd, buffer, 0, buffer.length, position, callback);
@@ -943,9 +943,9 @@ fs.writeFile = function(path, data, options, callback) {
fs.writeFileSync = function(path, data, options) {
if (!options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, mode: 438, flag: 'w' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
@@ -953,7 +953,7 @@ fs.writeFileSync = function(path, data, options) {
var flag = options.flag || 'w';
var fd = fs.openSync(path, flag, options.mode);
- if (!IS_BUFFER(data)) {
+ if (!util.isBuffer(data)) {
data = new Buffer('' + data, options.encoding || 'utf8');
}
var written = 0;
@@ -972,13 +972,13 @@ fs.writeFileSync = function(path, data, options) {
fs.appendFile = function(path, data, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (IS_FUNCTION(options) || !options) {
+ if (util.isFunction(options) || !options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, mode: 438, flag: 'a' };
} else if (!options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
@@ -990,9 +990,9 @@ fs.appendFile = function(path, data, options, callback_) {
fs.appendFileSync = function(path, data, options) {
if (!options) {
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' };
- } else if (IS_STRING(options)) {
+ } else if (util.isString(options)) {
options = { encoding: options, mode: 438, flag: 'a' };
- } else if (!IS_OBJECT(options)) {
+ } else if (!util.isObject(options)) {
throw new TypeError('Bad arguments');
}
if (!options.flag)
@@ -1039,7 +1039,7 @@ fs.watch = function(filename) {
var options;
var listener;
- if (IS_OBJECT(arguments[1])) {
+ if (util.isObject(arguments[1])) {
options = arguments[1];
listener = arguments[2];
} else {
@@ -1047,7 +1047,7 @@ fs.watch = function(filename) {
listener = arguments[1];
}
- if (IS_UNDEFINED(options.persistent)) options.persistent = true;
+ if (util.isUndefined(options.persistent)) options.persistent = true;
watcher = new FSWatcher();
watcher.start(filename, options.persistent);
@@ -1119,7 +1119,7 @@ fs.watchFile = function(filename) {
persistent: true
};
- if (IS_OBJECT(arguments[1])) {
+ if (util.isObject(arguments[1])) {
options = util._extend(options, arguments[1]);
listener = arguments[2];
} else {
@@ -1146,7 +1146,7 @@ fs.unwatchFile = function(filename, listener) {
var stat = statWatchers[filename];
- if (IS_FUNCTION(listener)) {
+ if (util.isFunction(listener)) {
stat.removeListener('change', listener);
} else {
stat.removeAllListeners('change');
@@ -1255,7 +1255,7 @@ fs.realpathSync = function realpathSync(p, cache) {
linkTarget = seenLinks[id];
}
}
- if (IS_NULL(linkTarget)) {
+ if (util.isNull(linkTarget)) {
fs.statSync(base);
linkTarget = fs.readlinkSync(base);
}
@@ -1277,7 +1277,7 @@ fs.realpathSync = function realpathSync(p, cache) {
fs.realpath = function realpath(p, cache, cb) {
- if (!IS_FUNCTION(cb)) {
+ if (!util.isFunction(cb)) {
cb = maybeCallback(cache);
cache = null;
}
@@ -1438,13 +1438,13 @@ function ReadStream(path, options) {
options.autoClose : true;
this.pos = undefined;
- if (!IS_UNDEFINED(this.start)) {
- if (!IS_NUMBER(this.start)) {
+ if (!util.isUndefined(this.start)) {
+ if (!util.isNumber(this.start)) {
throw TypeError('start must be a Number');
}
- if (IS_UNDEFINED(this.end)) {
+ if (util.isUndefined(this.end)) {
this.end = Infinity;
- } else if (!IS_NUMBER(this.end)) {
+ } else if (!util.isNumber(this.end)) {
throw TypeError('end must be a Number');
}
@@ -1455,7 +1455,7 @@ function ReadStream(path, options) {
this.pos = this.start;
}
- if (!IS_NUMBER(this.fd))
+ if (!util.isNumber(this.fd))
this.open();
this.on('end', function() {
@@ -1486,7 +1486,7 @@ ReadStream.prototype.open = function() {
};
ReadStream.prototype._read = function(n) {
- if (!IS_NUMBER(this.fd))
+ if (!util.isNumber(this.fd))
return this.once('open', function() {
this._read(n);
});
@@ -1507,7 +1507,7 @@ ReadStream.prototype._read = function(n) {
var toRead = Math.min(pool.length - pool.used, n);
var start = pool.used;
- if (!IS_UNDEFINED(this.pos))
+ if (!util.isUndefined(this.pos))
toRead = Math.min(this.end - this.pos + 1, toRead);
// already read everything we were supposed to read!
@@ -1520,7 +1520,7 @@ ReadStream.prototype._read = function(n) {
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread);
// move the pool positions, and internal position for reading.
- if (!IS_UNDEFINED(this.pos))
+ if (!util.isUndefined(this.pos))
this.pos += toRead;
pool.used += toRead;
@@ -1546,7 +1546,7 @@ ReadStream.prototype.destroy = function() {
return;
this.destroyed = true;
- if (IS_NUMBER(this.fd))
+ if (util.isNumber(this.fd))
this.close();
};
@@ -1555,8 +1555,8 @@ ReadStream.prototype.close = function(cb) {
var self = this;
if (cb)
this.once('close', cb);
- if (this.closed || !IS_NUMBER(this.fd)) {
- if (!IS_NUMBER(this.fd)) {
+ if (this.closed || !util.isNumber(this.fd)) {
+ if (!util.isNumber(this.fd)) {
this.once('open', close);
return;
}
@@ -1604,8 +1604,8 @@ function WriteStream(path, options) {
this.pos = undefined;
this.bytesWritten = 0;
- if (!IS_UNDEFINED(this.start)) {
- if (!IS_NUMBER(this.start)) {
+ if (!util.isUndefined(this.start)) {
+ if (!util.isNumber(this.start)) {
throw TypeError('start must be a Number');
}
if (this.start < 0) {
@@ -1615,7 +1615,7 @@ function WriteStream(path, options) {
this.pos = this.start;
}
- if (!IS_NUMBER(this.fd))
+ if (!util.isNumber(this.fd))
this.open();
// dispose on finish.
@@ -1640,10 +1640,10 @@ WriteStream.prototype.open = function() {
WriteStream.prototype._write = function(data, encoding, cb) {
- if (!IS_BUFFER(data))
+ if (!util.isBuffer(data))
return this.emit('error', new Error('Invalid data'));
- if (!IS_NUMBER(this.fd))
+ if (!util.isNumber(this.fd))
return this.once('open', function() {
this._write(data, encoding, cb);
});
@@ -1658,7 +1658,7 @@ WriteStream.prototype._write = function(data, encoding, cb) {
cb();
});
- if (!IS_UNDEFINED(this.pos))
+ if (!util.isUndefined(this.pos))
this.pos += data.length;
};
@@ -1692,10 +1692,10 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) {
// parse arguments
if (arg1) {
- if (IS_STRING(arg1)) {
+ if (util.isString(arg1)) {
encoding = arg1;
cb = arg2;
- } else if (IS_FUNCTION(arg1)) {
+ } else if (util.isFunction(arg1)) {
cb = arg1;
} else {
throw new Error('bad arg');
@@ -1704,7 +1704,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) {
assertEncoding(encoding);
// Change strings to buffers. SLOW
- if (IS_STRING(data)) {
+ if (util.isString(data)) {
data = new Buffer(data, encoding);
}
diff --git a/lib/https.js b/lib/https.js
index 4ffc1e6a3..a00b8bd6f 100644
--- a/lib/https.js
+++ b/lib/https.js
@@ -60,21 +60,21 @@ exports.createServer = function(opts, requestListener) {
// HTTPS agents.
function createConnection(port, host, options) {
- if (IS_OBJECT(port)) {
+ if (util.isObject(port)) {
options = port;
- } else if (IS_OBJECT(host)) {
+ } else if (util.isObject(host)) {
options = host;
- } else if (IS_OBJECT(options)) {
+ } else if (util.isObject(options)) {
options = options;
} else {
options = {};
}
- if (IS_NUMBER(port)) {
+ if (util.isNumber(port)) {
options.port = port;
}
- if (IS_STRING(host)) {
+ if (util.isString(host)) {
options.host = host;
}
@@ -115,7 +115,7 @@ Agent.prototype.getName = function(options) {
name += options.pfx;
name += ':';
- if (!IS_UNDEFINED(options.rejectUnauthorized))
+ if (!util.isUndefined(options.rejectUnauthorized))
name += options.rejectUnauthorized;
return name;
diff --git a/lib/module.js b/lib/module.js
index ec0e76172..07730ff65 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -20,6 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var NativeModule = require('native_module');
+var util = NativeModule.require('util');
var Script = process.binding('evals').NodeScript;
var runInThisContext = Script.runInThisContext;
var runInNewContext = Script.runInNewContext;
@@ -62,7 +63,7 @@ Module.wrap = NativeModule.wrap;
var path = NativeModule.require('path');
-Module._debug = NativeModule.require('util').debuglog('module');
+Module._debug = util.debuglog('module');
// We use this alias for the preprocessor that filters it out
@@ -352,7 +353,7 @@ Module.prototype.load = function(filename) {
Module.prototype.require = function(path) {
- assert(IS_STRING(path), 'path must be a string');
+ assert(util.isString(path), 'path must be a string');
assert(path, 'missing path');
return Module._load(path, this);
};
diff --git a/lib/net.js b/lib/net.js
index 6bd86e189..e39a79b07 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -57,7 +57,7 @@ function createHandle(fd) {
var debug = util.debuglog('net');
function isPipeName(s) {
- return IS_STRING(s) && toNumber(s) === false;
+ return util.isString(s) && toNumber(s) === false;
}
@@ -90,7 +90,7 @@ exports.connect = exports.createConnection = function() {
function normalizeConnectArgs(args) {
var options = {};
- if (IS_OBJECT(args[0])) {
+ if (util.isObject(args[0])) {
// connect(options, [cb])
options = args[0];
} else if (isPipeName(args[0])) {
@@ -99,13 +99,13 @@ function normalizeConnectArgs(args) {
} else {
// connect(port, [host], [cb])
options.port = args[0];
- if (IS_STRING(args[1])) {
+ if (util.isString(args[1])) {
options.host = args[1];
}
}
var cb = args[args.length - 1];
- return IS_FUNCTION(cb) ? [options, cb] : [options];
+ return util.isFunction(cb) ? [options, cb] : [options];
}
exports._normalizeConnectArgs = normalizeConnectArgs;
@@ -135,16 +135,16 @@ function Socket(options) {
this._hadError = false;
this._handle = null;
- if (IS_NUMBER(options))
+ if (util.isNumber(options))
options = { fd: options }; // Legacy interface.
- else if (IS_UNDEFINED(options))
+ else if (util.isUndefined(options))
options = {};
stream.Duplex.call(this, options);
if (options.handle) {
this._handle = options.handle; // private
- } else if (!IS_UNDEFINED(options.fd)) {
+ } else if (!util.isUndefined(options.fd)) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
this.readable = options.readable !== false;
@@ -259,7 +259,7 @@ function onSocketEnd() {
// of the other side sending a FIN. The standard 'write after end'
// is overly vague, and makes it seem like the user's code is to blame.
function writeAfterFIN(chunk, encoding, cb) {
- if (IS_FUNCTION(encoding)) {
+ if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
@@ -269,7 +269,7 @@ function writeAfterFIN(chunk, encoding, cb) {
var self = this;
// TODO: defer error events consistently everywhere, not just the cb
self.emit('error', er);
- if (IS_FUNCTION(cb)) {
+ if (util.isFunction(cb)) {
process.nextTick(function() {
cb(er);
});
@@ -322,7 +322,7 @@ Socket.prototype._onTimeout = function() {
Socket.prototype.setNoDelay = function(enable) {
// backwards compatibility: assume true when `enable` is omitted
if (this._handle && this._handle.setNoDelay)
- this._handle.setNoDelay(IS_UNDEFINED(enable) ? true : !!enable);
+ this._handle.setNoDelay(util.isUndefined(enable) ? true : !!enable);
};
@@ -601,7 +601,7 @@ Socket.prototype.__defineGetter__('localPort', function() {
Socket.prototype.write = function(chunk, encoding, cb) {
- if (!IS_STRING(chunk) && !IS_BUFFER(chunk))
+ if (!util.isString(chunk) && !util.isBuffer(chunk))
throw new TypeError('invalid data');
return stream.Duplex.prototype.write.apply(this, arguments);
};
@@ -646,7 +646,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
// Retain chunks
if (err === 0) req._chunks = chunks;
} else {
- var enc = IS_BUFFER(data) ? 'buffer' : encoding;
+ var enc = util.isBuffer(data) ? 'buffer' : encoding;
err = createWriteReq(req, this._handle, data, enc);
}
@@ -728,14 +728,14 @@ Socket.prototype.__defineGetter__('bytesWritten', function() {
encoding = this._pendingEncoding;
state.buffer.forEach(function(el) {
- if (IS_BUFFER(el.chunk))
+ if (util.isBuffer(el.chunk))
bytes += el.chunk.length;
else
bytes += Buffer.byteLength(el.chunk, el.encoding);
});
if (data) {
- if (IS_BUFFER(data))
+ if (util.isBuffer(data))
bytes += data.length;
else
bytes += Buffer.byteLength(data, encoding);
@@ -813,7 +813,7 @@ Socket.prototype.connect = function(options, cb) {
if (this.write !== Socket.prototype.write)
this.write = Socket.prototype.write;
- if (!IS_OBJECT(options)) {
+ if (!util.isObject(options)) {
// Old API:
// connect(port, [host], [cb])
// connect(path, [cb]);
@@ -840,7 +840,7 @@ Socket.prototype.connect = function(options, cb) {
initSocketHandle(this);
}
- if (IS_FUNCTION(cb)) {
+ if (util.isFunction(cb)) {
self.once('connect', cb);
}
@@ -948,13 +948,13 @@ function Server(/* [ options, ] listener */) {
var options;
- if (IS_FUNCTION(arguments[0])) {
+ if (util.isFunction(arguments[0])) {
options = {};
self.on('connection', arguments[0]);
} else {
options = arguments[0] || {};
- if (IS_FUNCTION(arguments[1])) {
+ if (util.isFunction(arguments[1])) {
self.on('connection', arguments[1]);
}
}
@@ -994,7 +994,7 @@ var createServerHandle = exports._createServerHandle =
// assign handle in listen, and clean up if bind or listen fails
var handle;
- if (IS_NUMBER(fd) && fd >= 0) {
+ if (util.isNumber(fd) && fd >= 0) {
try {
handle = createHandle(fd);
}
@@ -1047,7 +1047,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
if (!self._handle) {
debug('_listen2: create a handle');
var rval = createServerHandle(address, port, addressType, fd);
- if (IS_NUMBER(rval)) {
+ if (util.isNumber(rval)) {
var error = errnoException(rval, 'listen');
process.nextTick(function() {
self.emit('error', error);
@@ -1125,7 +1125,7 @@ Server.prototype.listen = function() {
var self = this;
var lastArg = arguments[arguments.length - 1];
- if (IS_FUNCTION(lastArg)) {
+ if (util.isFunction(lastArg)) {
self.once('listening', lastArg);
}
@@ -1137,11 +1137,11 @@ Server.prototype.listen = function() {
var TCP = process.binding('tcp_wrap').TCP;
- if (arguments.length == 0 || IS_FUNCTION(arguments[0])) {
+ if (arguments.length == 0 || util.isFunction(arguments[0])) {
// Bind to a random port.
listen(self, '0.0.0.0', 0, null, backlog);
- } else if (arguments[0] && IS_OBJECT(arguments[0])) {
+ } else if (arguments[0] && util.isObject(arguments[0])) {
var h = arguments[0];
if (h._handle) {
h = h._handle;
@@ -1151,7 +1151,7 @@ Server.prototype.listen = function() {
if (h instanceof TCP) {
self._handle = h;
listen(self, null, -1, -1, backlog);
- } else if (IS_NUMBER(h.fd) && h.fd >= 0) {
+ } else if (util.isNumber(h.fd) && h.fd >= 0) {
listen(self, null, null, null, backlog, h.fd);
} else {
throw new Error('Invalid listen argument: ' + h);
@@ -1161,9 +1161,9 @@ Server.prototype.listen = function() {
var pipeName = self._pipeName = arguments[0];
listen(self, pipeName, -1, -1, backlog);
- } else if (IS_UNDEFINED(arguments[1]) ||
- IS_FUNCTION(arguments[1]) ||
- IS_NUMBER(arguments[1])) {
+ } else if (util.isUndefined(arguments[1]) ||
+ util.isFunction(arguments[1]) ||
+ util.isNumber(arguments[1])) {
// The first argument is the port, no IP given.
listen(self, '0.0.0.0', port, 4, backlog);
@@ -1350,11 +1350,11 @@ if (process.platform === 'win32') {
var simultaneousAccepts;
exports._setSimultaneousAccepts = function(handle) {
- if (IS_UNDEFINED(handle)) {
+ if (util.isUndefined(handle)) {
return;
}
- if (IS_UNDEFINED(simultaneousAccepts)) {
+ if (util.isUndefined(simultaneousAccepts)) {
simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
process.env.NODE_MANY_ACCEPTS !== '0');
}
diff --git a/lib/path.js b/lib/path.js
index bd5e43793..aabb80df9 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -112,7 +112,7 @@ if (isWindows) {
}
// Skip empty and invalid entries
- if (!IS_STRING(path)) {
+ if (!util.isString(path)) {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
@@ -214,7 +214,7 @@ if (isWindows) {
// windows version
exports.join = function() {
function f(p) {
- if (!IS_STRING(p)) {
+ if (!util.isString(p)) {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
@@ -323,7 +323,7 @@ if (isWindows) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
- if (!IS_STRING(path)) {
+ if (!util.isString(path)) {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
@@ -374,7 +374,7 @@ if (isWindows) {
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(paths.filter(function(p, index) {
- if (!IS_STRING(p)) {
+ if (!util.isString(p)) {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
@@ -476,7 +476,7 @@ exports.existsSync = util.deprecate(function(path) {
if (isWindows) {
exports._makeLong = function(path) {
// Note: this will *probably* throw somewhere.
- if (!IS_STRING(path))
+ if (!util.isString(path))
return path;
if (!path) {
diff --git a/lib/querystring.js b/lib/querystring.js
index ce9853d7f..e9ff825d5 100644
--- a/lib/querystring.js
+++ b/lib/querystring.js
@@ -22,6 +22,7 @@
// Query String Utilities
var QueryString = exports;
+var util = require('util');
// If obj.hasOwnProperty has been overridden, then calling
@@ -114,11 +115,11 @@ QueryString.escape = function(str) {
};
var stringifyPrimitive = function(v) {
- if (IS_STRING(v))
+ if (util.isString(v))
return v;
- if (IS_BOOLEAN(v))
+ if (util.isBoolean(v))
return v ? 'true' : 'false';
- if (IS_NUMBER(v))
+ if (util.isNumber(v))
return isFinite(v) ? v : '';
return '';
};
@@ -127,14 +128,14 @@ var stringifyPrimitive = function(v) {
QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
- if (IS_NULL(obj)) {
+ if (util.isNull(obj)) {
obj = undefined;
}
- if (IS_OBJECT(obj)) {
+ if (util.isObject(obj)) {
return Object.keys(obj).map(function(k) {
var ks = QueryString.escape(stringifyPrimitive(k)) + eq;
- if (IS_ARRAY(obj[k])) {
+ if (util.isArray(obj[k])) {
return obj[k].map(function(v) {
return ks + QueryString.escape(stringifyPrimitive(v));
}).join(sep);
@@ -156,7 +157,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
eq = eq || '=';
var obj = {};
- if (!IS_STRING(qs) || qs.length === 0) {
+ if (!util.isString(qs) || qs.length === 0) {
return obj;
}
@@ -164,7 +165,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
qs = qs.split(sep);
var maxKeys = 1000;
- if (options && IS_NUMBER(options.maxKeys)) {
+ if (options && util.isNumber(options.maxKeys)) {
maxKeys = options.maxKeys;
}
@@ -197,7 +198,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
- } else if (IS_ARRAY(obj[k])) {
+ } else if (util.isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
diff --git a/lib/readline.js b/lib/readline.js
index f2035306d..60e725c8b 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -63,13 +63,13 @@ function Interface(input, output, completer, terminal) {
completer = completer || function() { return []; };
- if (!IS_FUNCTION(completer)) {
+ if (!util.isFunction(completer)) {
throw new TypeError('Argument \'completer\' must be a function');
}
// backwards compat; check the isTTY prop of the output stream
// when `terminal` was not specified
- if (IS_UNDEFINED(terminal)) {
+ if (util.isUndefined(terminal)) {
terminal = !!output.isTTY;
}
@@ -154,7 +154,7 @@ Interface.prototype.setPrompt = function(prompt) {
Interface.prototype._setRawMode = function(mode) {
- if (IS_FUNCTION(this.input.setRawMode)) {
+ if (util.isFunction(this.input.setRawMode)) {
return this.input.setRawMode(mode);
}
};
@@ -172,7 +172,7 @@ Interface.prototype.prompt = function(preserveCursor) {
Interface.prototype.question = function(query, cb) {
- if (IS_FUNCTION(cb)) {
+ if (util.isFunction(cb)) {
if (this._questionCallback) {
this.prompt();
} else {
@@ -290,7 +290,7 @@ Interface.prototype.write = function(d, key) {
// \r\n, \n, or \r followed by something other than \n
var lineEnding = /\r?\n|\r(?!\n)/;
Interface.prototype._normalWrite = function(b) {
- if (IS_UNDEFINED(b)) {
+ if (util.isUndefined(b)) {
return;
}
var string = this._decoder.write(b);
@@ -843,7 +843,7 @@ Interface.prototype._ttyWrite = function(s, key) {
break;
default:
- if (IS_BUFFER(s))
+ if (util.isBuffer(s))
s = s.toString('utf-8');
if (s) {
@@ -944,8 +944,8 @@ function emitKey(stream, s) {
},
parts;
- if (IS_BUFFER(s)) {
- if (s[0] > 127 && IS_UNDEFINED(s[1])) {
+ if (util.isBuffer(s)) {
+ if (s[0] > 127 && util.isUndefined(s[1])) {
s[0] -= 128;
s = '\x1b' + s.toString(stream.encoding || 'utf-8');
} else {
@@ -1124,7 +1124,7 @@ function emitKey(stream, s) {
}
// Don't emit a key if no name was found
- if (IS_UNDEFINED(key.name)) {
+ if (util.isUndefined(key.name)) {
key = undefined;
}
@@ -1143,13 +1143,13 @@ function emitKey(stream, s) {
*/
function cursorTo(stream, x, y) {
- if (!IS_NUMBER(x) && !IS_NUMBER(y))
+ if (!util.isNumber(x) && !util.isNumber(y))
return;
- if (!IS_NUMBER(x))
+ if (!util.isNumber(x))
throw new Error("Can't set cursor row without also setting it's column");
- if (!IS_NUMBER(y)) {
+ if (!util.isNumber(y)) {
stream.write('\x1b[' + (x + 1) + 'G');
} else {
stream.write('\x1b[' + (y + 1) + ';' + (x + 1) + 'H');
diff --git a/lib/repl.js b/lib/repl.js
index 2fd5821e3..692471c3f 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -83,7 +83,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
EventEmitter.call(this);
var options, input, output, dom;
- if (IS_OBJECT(prompt)) {
+ if (util.isObject(prompt)) {
// an options object was given
options = prompt;
stream = options.stream || options.socket;
@@ -94,7 +94,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
ignoreUndefined = options.ignoreUndefined;
prompt = options.prompt;
dom = options.domain;
- } else if (!IS_STRING(prompt)) {
+ } else if (!util.isString(prompt)) {
throw new Error('An options Object, or a prompt String are required');
} else {
options = {};
@@ -160,7 +160,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
self.resetContext();
self.bufferedCommand = '';
- self.prompt = !IS_UNDEFINED(prompt) ? prompt : '> ';
+ self.prompt = !util.isUndefined(prompt) ? prompt : '> ';
function complete(text, callback) {
self.complete(text, callback);
@@ -180,7 +180,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
// figure out which "writer" function to use
self.writer = options.writer || exports.writer;
- if (IS_UNDEFINED(options.useColors)) {
+ if (util.isUndefined(options.useColors)) {
options.useColors = rli.terminal;
}
self.useColors = !!options.useColors;
@@ -256,7 +256,8 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
function(e, ret) {
if (e && !isSyntaxError(e)) return finish(e);
- if (IS_FUNCTION(ret) && /^[\r\n\s]*function/.test(evalCmd) || e) {
+ if (util.isFunction(ret) &&
+ /^[\r\n\s]*function/.test(evalCmd) || e) {
// Now as statement without parens.
self.eval(evalCmd, self.context, 'repl', finish);
} else {
@@ -298,7 +299,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
self.bufferedCommand = '';
// If we got any output - print it (if no error)
- if (!e && (!self.ignoreUndefined || !IS_UNDEFINED(ret))) {
+ if (!e && (!self.ignoreUndefined || !util.isUndefined(ret))) {
self.context._ = ret;
self.outputStream.write(self.writer(ret) + '\n');
}
@@ -420,7 +421,7 @@ var simpleExpressionRE =
// getter code.
REPLServer.prototype.complete = function(line, callback) {
// There may be local variables to evaluate, try a nested REPL
- if (!IS_UNDEFINED(this.bufferedCommand) && this.bufferedCommand.length) {
+ if (!util.isUndefined(this.bufferedCommand) && this.bufferedCommand.length) {
// Get a new array of inputed lines
var tmp = this.lines.slice();
// Kill off all function declarations to push all local variables into
@@ -562,7 +563,7 @@ REPLServer.prototype.complete = function(line, callback) {
this.eval('.scope', this.context, 'repl', function(err, globals) {
if (err || !globals) {
addStandardGlobals(completionGroups, filter);
- } else if (IS_ARRAY(globals[0])) {
+ } else if (util.isArray(globals[0])) {
// Add grouped globals
globals.forEach(function(group) {
completionGroups.push(group);
@@ -579,19 +580,19 @@ REPLServer.prototype.complete = function(line, callback) {
// if (e) console.log(e);
if (obj != null) {
- if (IS_OBJECT(obj) || IS_FUNCTION(obj)) {
+ if (util.isObject(obj) || util.isFunction(obj)) {
memberGroups.push(Object.getOwnPropertyNames(obj));
}
// works for non-objects
try {
var sentinel = 5;
var p;
- if (IS_OBJECT(obj) || IS_FUNCTION(obj)) {
+ if (util.isObject(obj) || util.isFunction(obj)) {
p = Object.getPrototypeOf(obj);
} else {
p = obj.constructor ? obj.constructor.prototype : null;
}
- while (!IS_NULL(p)) {
+ while (!util.isNull(p)) {
memberGroups.push(Object.getOwnPropertyNames(p));
p = Object.getPrototypeOf(p);
// Circular refs possible? Let's guard against that.
@@ -690,9 +691,9 @@ REPLServer.prototype.parseREPLKeyword = function(keyword, rest) {
REPLServer.prototype.defineCommand = function(keyword, cmd) {
- if (IS_FUNCTION(cmd)) {
+ if (util.isFunction(cmd)) {
cmd = {action: cmd};
- } else if (!IS_FUNCTION(cmd.action)) {
+ } else if (!util.isFunction(cmd.action)) {
throw new Error('bad argument, action must be a function');
}
this.commands['.' + keyword] = cmd;
diff --git a/lib/smalloc.js b/lib/smalloc.js
index b6e909347..cba96ac8d 100644
--- a/lib/smalloc.js
+++ b/lib/smalloc.js
@@ -21,6 +21,7 @@
var smalloc = process.binding('smalloc');
var kMaxLength = smalloc.kMaxLength;
+var util = require('util');
exports.alloc = alloc;
exports.copyOnto = smalloc.copyOnto;
@@ -39,15 +40,15 @@ function alloc(n, obj) {
if (n > kMaxLength)
throw new RangeError('n > kMaxLength');
- if (IS_ARRAY(obj))
+ if (util.isArray(obj))
throw new TypeError('Arrays are not supported');
- return smalloc.alloc(IS_UNDEFINED(obj) ? {} : obj, n);
+ return smalloc.alloc(util.isUndefined(obj) ? {} : obj, n);
}
function dispose(obj) {
- if (IS_BUFFER(obj))
+ if (util.isBuffer(obj))
throw new TypeError('obj cannot be a Buffer');
smalloc.dispose(obj);
}
diff --git a/lib/stream.js b/lib/stream.js
index 5d8021ebd..073c6ed33 100644
--- a/lib/stream.js
+++ b/lib/stream.js
@@ -84,7 +84,7 @@ Stream.prototype.pipe = function(dest, options) {
if (didOnEnd) return;
didOnEnd = true;
- if (IS_FUNCTION(dest.destroy)) dest.destroy();
+ if (util.isFunction(dest.destroy)) dest.destroy();
}
// don't leave dangling pipes when there are errors.
diff --git a/lib/tls.js b/lib/tls.js
index a0d31bf60..ab8d665a2 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -51,7 +51,7 @@ exports.getCiphers = function() {
// ("\x06spdy/2\x08http/1.1\x08http/1.0")
exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {
// If NPNProtocols is Array - translate it into buffer
- if (IS_ARRAY(NPNProtocols)) {
+ if (util.isArray(NPNProtocols)) {
var buff = new Buffer(NPNProtocols.reduce(function(p, c) {
return p + 1 + Buffer.byteLength(c);
}, 0));
@@ -68,7 +68,7 @@ exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {
}
// If it's already a Buffer - store it
- if (IS_BUFFER(NPNProtocols)) {
+ if (util.isBuffer(NPNProtocols)) {
out.NPNProtocols = NPNProtocols;
}
};
@@ -166,7 +166,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
// RFC6125
if (matchCN) {
var commonNames = cert.subject.CN;
- if (IS_ARRAY(commonNames)) {
+ if (util.isArray(commonNames)) {
for (var i = 0, k = commonNames.length; i < k; ++i) {
dnsNames.push(regexpify(commonNames[i], true));
}
@@ -194,7 +194,7 @@ exports.parseCertString = function parseCertString(s) {
var key = parts[i].slice(0, sepIndex);
var value = parts[i].slice(sepIndex + 1);
if (key in out) {
- if (!IS_ARRAY(out[key])) {
+ if (!util.isArray(out[key])) {
out[key] = [out[key]];
}
out[key].push(value);
diff --git a/lib/url.js b/lib/url.js
index f10ba5fb0..887ac0c43 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -20,6 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var punycode = require('punycode');
+var util = require('util');
exports.parse = urlParse;
exports.resolve = urlResolve;
@@ -94,7 +95,7 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
querystring = require('querystring');
function urlParse(url, parseQueryString, slashesDenoteHost) {
- if (url && IS_OBJECT(url) && url instanceof Url) return url;
+ if (url && util.isObject(url) && url instanceof Url) return url;
var u = new Url;
u.parse(url, parseQueryString, slashesDenoteHost);
@@ -102,7 +103,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
}
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
- if (!IS_STRING(url)) {
+ if (!util.isString(url)) {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}
@@ -340,7 +341,7 @@ function urlFormat(obj) {
// If it's an obj, this is a no-op.
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
- if (IS_STRING(obj)) obj = urlParse(obj);
+ if (util.isString(obj)) obj = urlParse(obj);
if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
return obj.format();
}
@@ -370,7 +371,9 @@ Url.prototype.format = function() {
}
}
- if (this.query && IS_OBJECT(this.query) && Object.keys(this.query).length) {
+ if (this.query &&
+ util.isObject(this.query) &&
+ Object.keys(this.query).length) {
query = querystring.stringify(this.query);
}
@@ -413,7 +416,7 @@ function urlResolveObject(source, relative) {
}
Url.prototype.resolveObject = function(relative) {
- if (IS_STRING(relative)) {
+ if (util.isString(relative)) {
var rel = new Url();
rel.parse(relative, false, true);
relative = rel;
@@ -553,7 +556,7 @@ Url.prototype.resolveObject = function(relative) {
srcPath = srcPath.concat(relPath);
result.search = relative.search;
result.query = relative.query;
- } else if (!IS_NULL_OR_UNDEFINED(relative.search)) {
+ } else if (!util.isNullOrUndefined(relative.search)) {
// just pull out the search.
// like href='?foo'.
// Put this after the other two cases because it simplifies the booleans
@@ -572,7 +575,7 @@ Url.prototype.resolveObject = function(relative) {
result.search = relative.search;
result.query = relative.query;
//to support http.request
- if (!IS_NULL(result.pathname) || !IS_NULL(result.search)) {
+ if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
@@ -666,7 +669,7 @@ Url.prototype.resolveObject = function(relative) {
}
//to support request.http
- if (!IS_NULL(result.pathname) || !IS_NULL(result.search)) {
+ if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
diff --git a/lib/util.js b/lib/util.js
index 23de9df84..b59bae506 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -21,7 +21,7 @@
var formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
- if (!IS_STRING(f)) {
+ if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
@@ -49,7 +49,7 @@ exports.format = function(f) {
}
});
for (var x = args[i]; i < len; x = args[++i]) {
- if (IS_NULL(x) || !IS_OBJECT(x)) {
+ if (isNull(x) || !isObject(x)) {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
@@ -63,6 +63,13 @@ exports.format = function(f) {
// Returns a modified function which warns once by default.
// If --no-deprecation is set, then it is a no-op.
exports.deprecate = function(fn, msg) {
+ // Allow for deprecating things in the process of starting up.
+ if (isUndefined(global.process)) {
+ return function() {
+ return exports.deprecate(fn, msg).apply(this, arguments);
+ };
+ }
+
if (process.noDeprecation === true) {
return fn;
}
@@ -87,8 +94,10 @@ exports.deprecate = function(fn, msg) {
var debugs = {};
-var debugEnviron = process.env.NODE_DEBUG || '';
+var debugEnviron;
exports.debuglog = function(set) {
+ if (isUndefined(debugEnviron))
+ debugEnviron = process.env.NODE_DEBUG || '';
set = set.toUpperCase();
if (!debugs[set]) {
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
@@ -122,7 +131,7 @@ function inspect(obj, opts) {
// legacy...
if (arguments.length >= 3) ctx.depth = arguments[2];
if (arguments.length >= 4) ctx.colors = arguments[3];
- if (IS_BOOLEAN(opts)) {
+ if (isBoolean(opts)) {
// legacy...
ctx.showHidden = opts;
} else if (opts) {
@@ -130,10 +139,10 @@ function inspect(obj, opts) {
exports._extend(ctx, opts);
}
// set default options
- if (IS_UNDEFINED(ctx.showHidden)) ctx.showHidden = false;
- if (IS_UNDEFINED(ctx.depth)) ctx.depth = 2;
- if (IS_UNDEFINED(ctx.colors)) ctx.colors = false;
- if (IS_UNDEFINED(ctx.customInspect)) ctx.customInspect = true;
+ if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
+ if (isUndefined(ctx.depth)) ctx.depth = 2;
+ if (isUndefined(ctx.colors)) ctx.colors = false;
+ if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
if (ctx.colors) ctx.stylize = stylizeWithColor;
return formatValue(ctx, obj, ctx.depth);
}
@@ -204,13 +213,13 @@ function formatValue(ctx, value, recurseTimes) {
// Check that value is an object with an inspect function on it
if (ctx.customInspect &&
value &&
- IS_FUNCTION(value.inspect) &&
+ isFunction(value.inspect) &&
// Filter out the util module, it's inspect function is special
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes);
- if (!IS_STRING(ret)) {
+ if (!isString(ret)) {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
@@ -232,7 +241,7 @@ function formatValue(ctx, value, recurseTimes) {
// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
- if (IS_FUNCTION(value)) {
+ if (isFunction(value)) {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
}
@@ -256,7 +265,7 @@ function formatValue(ctx, value, recurseTimes) {
}
// Make functions say that they are functions
- if (IS_FUNCTION(value)) {
+ if (isFunction(value)) {
var n = value.name ? ': ' + value.name : '';
base = ' [Function' + n + ']';
}
@@ -306,20 +315,20 @@ function formatValue(ctx, value, recurseTimes) {
function formatPrimitive(ctx, value) {
- if (IS_UNDEFINED(value))
+ if (isUndefined(value))
return ctx.stylize('undefined', 'undefined');
- if (IS_STRING(value)) {
+ if (isString(value)) {
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
}
- if (IS_NUMBER(value))
+ if (isNumber(value))
return ctx.stylize('' + value, 'number');
- if (IS_BOOLEAN(value))
+ if (isBoolean(value))
return ctx.stylize('' + value, 'boolean');
// For some reason typeof null is "object", so special case here.
- if (IS_NULL(value))
+ if (isNull(value))
return ctx.stylize('null', 'null');
}
@@ -368,7 +377,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
}
if (!str) {
if (ctx.seen.indexOf(desc.value) < 0) {
- if (IS_NULL(recurseTimes)) {
+ if (isNull(recurseTimes)) {
str = formatValue(ctx, desc.value, null);
} else {
str = formatValue(ctx, desc.value, recurseTimes - 1);
@@ -388,7 +397,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
str = ctx.stylize('[Circular]', 'special');
}
}
- if (IS_UNDEFINED(name)) {
+ if (isUndefined(name)) {
if (array && key.match(/^\d+$/)) {
return str;
}
@@ -432,28 +441,74 @@ function reduceToSingleString(output, base, braces) {
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(ar) {
- return IS_ARRAY(ar);
+ return Array.isArray(ar);
}
exports.isArray = isArray;
+function isBoolean(arg) {
+ return typeof arg === 'boolean';
+}
+exports.isBoolean = isBoolean;
+
+function isNull(arg) {
+ return arg === null;
+}
+exports.isNull = isNull;
+
+function isNullOrUndefined(arg) {
+ return arg == null;
+}
+exports.isNullOrUndefined = isNullOrUndefined;
+
+function isNumber(arg) {
+ return typeof arg === 'number';
+}
+exports.isNumber = isNumber;
+
+function isString(arg) {
+ return typeof arg === 'string';
+}
+exports.isString = isString;
+
+function isSymbol(arg) {
+ return typeof arg === 'symbol';
+}
+exports.isSymbol = isSymbol;
+
+function isUndefined(arg) {
+ return arg === void 0;
+}
+exports.isUndefined = isUndefined;
function isRegExp(re) {
- return IS_OBJECT(re) && objectToString(re) === '[object RegExp]';
+ return isObject(re) && objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
+function isObject(arg) {
+ return typeof arg === 'object' && arg;
+}
+exports.isObject = isObject;
function isDate(d) {
- return IS_OBJECT(d) && objectToString(d) === '[object Date]';
+ return isObject(d) && objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
-
function isError(e) {
- return IS_OBJECT(e) && objectToString(e) === '[object Error]';
+ return isObject(e) && objectToString(e) === '[object Error]';
}
exports.isError = isError;
+function isFunction(arg) {
+ return typeof arg === 'function';
+}
+exports.isFunction = isFunction;
+
+function isBuffer(arg) {
+ return arg instanceof Buffer;
+}
+exports.isBuffer = isBuffer;
function objectToString(o) {
return Object.prototype.toString.call(o);
@@ -511,7 +566,7 @@ exports.inherits = function(ctor, superCtor) {
exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
- if (!add || !IS_OBJECT(add)) return origin;
+ if (!add || !isObject(add)) return origin;
var keys = Object.keys(add);
var i = keys.length;
@@ -606,7 +661,7 @@ exports.pump = exports.deprecate(function(readStream, writeStream, callback) {
var uv;
exports._errnoException = function(err, syscall) {
- if (IS_UNDEFINED(uv)) uv = process.binding('uv');
+ if (isUndefined(uv)) uv = process.binding('uv');
var errname = uv.errname(err);
var e = new Error(syscall + ' ' + errname);
e.code = errname;
diff --git a/lib/vm.js b/lib/vm.js
index f521444b5..f06d5abe9 100644
--- a/lib/vm.js
+++ b/lib/vm.js
@@ -23,6 +23,7 @@ var binding = process.binding('evals');
module.exports = Script;
Script.Script = Script;
+var util = require('util');
function Script(code, ctx, filename) {
if (!(this instanceof Script)) {
@@ -33,7 +34,7 @@ function Script(code, ctx, filename) {
// bind all methods to this Script object
Object.keys(binding.NodeScript.prototype).forEach(function(f) {
- if (IS_FUNCTION(binding.NodeScript.prototype[f])) {
+ if (util.isFunction(binding.NodeScript.prototype[f])) {
this[f] = function() {
if (!(this instanceof Script)) {
throw new TypeError('invalid call to ' + f);
diff --git a/lib/zlib.js b/lib/zlib.js
index 855df06bf..3341588e4 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -108,7 +108,7 @@ exports.createUnzip = function(o) {
// Convenience methods.
// compress/decompress a string or buffer in one step.
exports.deflate = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -116,7 +116,7 @@ exports.deflate = function(buffer, opts, callback) {
};
exports.gzip = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -124,7 +124,7 @@ exports.gzip = function(buffer, opts, callback) {
};
exports.deflateRaw = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -132,7 +132,7 @@ exports.deflateRaw = function(buffer, opts, callback) {
};
exports.unzip = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -140,7 +140,7 @@ exports.unzip = function(buffer, opts, callback) {
};
exports.inflate = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -148,7 +148,7 @@ exports.inflate = function(buffer, opts, callback) {
};
exports.gunzip = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -156,7 +156,7 @@ exports.gunzip = function(buffer, opts, callback) {
};
exports.inflateRaw = function(buffer, opts, callback) {
- if (IS_FUNCTION(opts)) {
+ if (util.isFunction(opts)) {
callback = opts;
opts = {};
}
@@ -305,7 +305,7 @@ function Zlib(opts, mode) {
}
if (opts.dictionary) {
- if (!IS_BUFFER(opts.dictionary)) {
+ if (!util.isBuffer(opts.dictionary)) {
throw new Error('Invalid dictionary: it should be a Buffer instance');
}
}
@@ -327,10 +327,10 @@ function Zlib(opts, mode) {
};
var level = exports.Z_DEFAULT_COMPRESSION;
- if (IS_NUMBER(opts.level)) level = opts.level;
+ if (util.isNumber(opts.level)) level = opts.level;
var strategy = exports.Z_DEFAULT_STRATEGY;
- if (IS_NUMBER(opts.strategy)) strategy = opts.strategy;
+ if (util.isNumber(opts.strategy)) strategy = opts.strategy;
this._binding.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
level,
@@ -390,7 +390,7 @@ Zlib.prototype._flush = function(callback) {
Zlib.prototype.flush = function(kind, callback) {
var ws = this._writableState;
- if (IS_FUNCTION(kind) || (IS_UNDEFINED(kind) && !callback)) {
+ if (util.isFunction(kind) || (util.isUndefined(kind) && !callback)) {
callback = kind;
kind = binding.Z_FULL_FLUSH;
}
@@ -435,7 +435,7 @@ Zlib.prototype._transform = function(chunk, encoding, cb) {
var ending = ws.ending || ws.ended;
var last = ending && (!chunk || ws.length === chunk.length);
- if (!IS_NULL(chunk) && !IS_BUFFER(chunk))
+ if (!util.isNull(chunk) && !util.isBuffer(chunk))
return cb(new Error('invalid input'));
// If it's the last chunk, or a final flush, we use the Z_FINISH flush flag.
diff --git a/node.gyp b/node.gyp
index 1215c8700..d1d7df176 100644
--- a/node.gyp
+++ b/node.gyp
@@ -386,7 +386,6 @@
'<(python)',
'tools/js2c.py',
'<@(_outputs)',
- 'src/macros.py',
'<@(_inputs)',
],
},
diff --git a/src/macros.py b/src/macros.py
deleted file mode 100644
index 39d05c9a4..000000000
--- a/src/macros.py
+++ /dev/null
@@ -1,16 +0,0 @@
-macro IS_BOOLEAN(arg) = (typeof(arg) === 'boolean');
-macro IS_NULL(arg) = (arg === null);
-macro IS_NULL_OR_UNDEFINED(arg) = (arg == null);
-macro IS_NUMBER(arg) = (typeof(arg) === 'number');
-macro IS_STRING(arg) = (typeof(arg) === 'string');
-macro IS_SYMBOL(arg) = (typeof(arg) === 'symbol');
-macro IS_UNDEFINED(arg) = (typeof(arg) === 'undefined');
-
-# These macros follow the semantics of V8's %_Is*() functions.
-macro IS_ARRAY(arg) = (Array.isArray(arg));
-macro IS_DATE(arg) = ((arg) instanceof Date);
-macro IS_FUNCTION(arg) = (typeof(arg) === 'function');
-macro IS_OBJECT(arg) = (typeof(arg) === 'object');
-macro IS_REGEXP(arg) = ((arg) instanceof RegExp);
-
-macro IS_BUFFER(arg) = ((arg) instanceof Buffer);