Skip to content

Commit

Permalink
src: Replace macros with util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 1, 2013
1 parent 9a29aa8 commit 22c68fd
Show file tree
Hide file tree
Showing 38 changed files with 439 additions and 389 deletions.
20 changes: 10 additions & 10 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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++) {
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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');
}

Expand All @@ -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') {
Expand Down Expand Up @@ -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];
Expand All @@ -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');
}

Expand Down
10 changes: 5 additions & 5 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]]);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -353,17 +353,17 @@ 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;
};

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');
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 22c68fd

Please sign in to comment.