Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 22c68fd

Browse files
committed
src: Replace macros with util functions
1 parent 9a29aa8 commit 22c68fd

38 files changed

+439
-389
lines changed

lib/_debugger.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ exports.Client = Client;
182182

183183

184184
Client.prototype._addHandle = function(desc) {
185-
if (!IS_OBJECT(desc) || !IS_NUMBER(desc.handle)) {
185+
if (!util.isObject(desc) || !util.isNumber(desc.handle)) {
186186
return;
187187
}
188188

@@ -296,7 +296,7 @@ Client.prototype.reqLookup = function(refs, cb) {
296296
this.req(req, function(err, res) {
297297
if (err) return cb(err);
298298
for (var ref in res) {
299-
if (IS_OBJECT(res[ref])) {
299+
if (util.isObject(res[ref])) {
300300
self._addHandle(res[ref]);
301301
}
302302
}
@@ -559,7 +559,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
559559
}
560560

561561

562-
if (IS_ARRAY(mirror) && !IS_NUMBER(prop.name)) {
562+
if (util.isArray(mirror) && !util.isNumber(prop.name)) {
563563
// Skip the 'length' property.
564564
return;
565565
}
@@ -592,7 +592,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
592592
val = function() {};
593593
} else if (handle.type === 'null') {
594594
val = null;
595-
} else if (!IS_UNDEFINED(handle.value)) {
595+
} else if (!util.isUndefined(handle.value)) {
596596
val = handle.value;
597597
} else if (handle.type === 'undefined') {
598598
val = undefined;
@@ -891,7 +891,7 @@ Interface.prototype.print = function(text, oneline) {
891891
if (this.killed) return;
892892
this.clearline();
893893

894-
this.stdout.write(IS_STRING(text) ? text : util.inspect(text));
894+
this.stdout.write(util.isString(text) ? text : util.inspect(text));
895895

896896
if (oneline !== true) {
897897
this.stdout.write('\n');
@@ -1213,7 +1213,7 @@ Interface.prototype.scripts = function() {
12131213
this.pause();
12141214
for (var id in client.scripts) {
12151215
var script = client.scripts[id];
1216-
if (IS_OBJECT(script) && script.name) {
1216+
if (util.isObject(script) && script.name) {
12171217
if (displayNatives ||
12181218
script.name == client.currentScript ||
12191219
!script.isNative) {
@@ -1350,13 +1350,13 @@ Interface.prototype.setBreakpoint = function(script, line,
13501350
ambiguous;
13511351

13521352
// setBreakpoint() should insert breakpoint on current line
1353-
if (IS_UNDEFINED(script)) {
1353+
if (util.isUndefined(script)) {
13541354
script = this.client.currentScript;
13551355
line = this.client.currentSourceLine + 1;
13561356
}
13571357

13581358
// setBreakpoint(line-number) should insert breakpoint in current script
1359-
if (IS_UNDEFINED(line) && IS_NUMBER(script)) {
1359+
if (util.isUndefined(line) && util.isNumber(script)) {
13601360
line = script;
13611361
script = this.client.currentScript;
13621362
}
@@ -1451,7 +1451,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14511451
if (bp.scriptId === script ||
14521452
bp.scriptReq === script ||
14531453
(bp.script && bp.script.indexOf(script) !== -1)) {
1454-
if (!IS_UNDEFINED(index)) {
1454+
if (!util.isUndefined(index)) {
14551455
ambiguous = true;
14561456
}
14571457
if (bp.line === line) {
@@ -1464,7 +1464,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14641464

14651465
if (ambiguous) return this.error('Script name is ambiguous');
14661466

1467-
if (IS_UNDEFINED(breakpoint)) {
1467+
if (util.isUndefined(breakpoint)) {
14681468
return this.error('Script : ' + script + ' not found');
14691469
}
14701470

lib/_http_agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Agent.prototype.destroy = function() {
246246
};
247247

248248
Agent.prototype.request = function(options, cb) {
249-
if (IS_STRING(options)) {
249+
if (util.isString(options)) {
250250
options = url.parse(options);
251251
}
252252
// don't try to do dns lookups of foo.com:8080, just foo.com

lib/_http_client.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ function ClientRequest(options, cb) {
4444
var self = this;
4545
OutgoingMessage.call(self);
4646

47-
self.agent = IS_UNDEFINED(options.agent) ? globalAgent : options.agent;
47+
self.agent = util.isUndefined(options.agent) ? globalAgent : options.agent;
4848

4949
var defaultPort = options.defaultPort || 80;
5050

5151
var port = options.port || defaultPort;
5252
var host = options.hostname || options.host || 'localhost';
5353

54-
if (IS_UNDEFINED(options.setHost)) {
54+
if (util.isUndefined(options.setHost)) {
5555
var setHost = true;
5656
}
5757

@@ -63,7 +63,7 @@ function ClientRequest(options, cb) {
6363
self.once('response', cb);
6464
}
6565

66-
if (!IS_ARRAY(options.headers)) {
66+
if (!util.isArray(options.headers)) {
6767
if (options.headers) {
6868
var keys = Object.keys(options.headers);
6969
for (var i = 0, l = keys.length; i < l; i++) {
@@ -92,7 +92,7 @@ function ClientRequest(options, cb) {
9292
self.useChunkedEncodingByDefault = true;
9393
}
9494

95-
if (IS_ARRAY(options.headers)) {
95+
if (util.isArray(options.headers)) {
9696
self._storeHeader(self.method + ' ' + self.path + ' HTTP/1.1\r\n',
9797
options.headers);
9898
} else if (self.getHeader('expect')) {
@@ -413,7 +413,7 @@ ClientRequest.prototype.onSocket = function(socket) {
413413
httpSocketSetup(socket);
414414

415415
// Propagate headers limit from request object to parser
416-
if (IS_NUMBER(req.maxHeadersCount)) {
416+
if (util.isNumber(req.maxHeadersCount)) {
417417
parser.maxHeaderPairs = req.maxHeadersCount << 1;
418418
} else {
419419
// Set default value because parser may be reused from FreeList

lib/_http_incoming.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
125125
switch (field) {
126126
// Array headers:
127127
case 'set-cookie':
128-
if (!IS_UNDEFINED(dest[field])) {
128+
if (!util.isUndefined(dest[field])) {
129129
dest[field].push(value);
130130
} else {
131131
dest[field] = [value];
@@ -145,7 +145,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
145145
case 'proxy-authenticate':
146146
case 'sec-websocket-extensions':
147147
case 'sec-websocket-protocol':
148-
if (!IS_UNDEFINED(dest[field])) {
148+
if (!util.isUndefined(dest[field])) {
149149
dest[field] += ', ' + value;
150150
} else {
151151
dest[field] = value;
@@ -156,14 +156,14 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
156156
default:
157157
if (field.slice(0, 2) == 'x-') {
158158
// except for x-
159-
if (!IS_UNDEFINED(dest[field])) {
159+
if (!util.isUndefined(dest[field])) {
160160
dest[field] += ', ' + value;
161161
} else {
162162
dest[field] = value;
163163
}
164164
} else {
165165
// drop duplicates
166-
if (IS_UNDEFINED(dest[field])) dest[field] = value;
166+
if (util.isUndefined(dest[field])) dest[field] = value;
167167
}
168168
break;
169169
}

lib/_http_outgoing.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ OutgoingMessage.prototype._send = function(data, encoding) {
115115
// the same packet. Future versions of Node are going to take care of
116116
// this at a lower level and in a more general way.
117117
if (!this._headerSent) {
118-
if (IS_STRING(data)) {
118+
if (util.isString(data)) {
119119
data = this._header + data;
120120
} else {
121121
this.output.unshift(this._header);
@@ -166,7 +166,7 @@ OutgoingMessage.prototype._buffer = function(data, encoding) {
166166

167167
var length = this.output.length;
168168

169-
if (length === 0 || !IS_STRING(data)) {
169+
if (length === 0 || !util.isString(data)) {
170170
this.output.push(data);
171171
this.outputEncodings.push(encoding);
172172
return false;
@@ -205,7 +205,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
205205

206206
if (headers) {
207207
var keys = Object.keys(headers);
208-
var isArray = IS_ARRAY(headers);
208+
var isArray = util.isArray(headers);
209209
var field, value;
210210

211211
for (var i = 0, l = keys.length; i < l; i++) {
@@ -218,7 +218,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
218218
value = headers[key];
219219
}
220220

221-
if (IS_ARRAY(value)) {
221+
if (util.isArray(value)) {
222222
for (var j = 0; j < value.length; j++) {
223223
storeHeader(this, state, field, value[j]);
224224
}
@@ -401,7 +401,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
401401
return true;
402402
}
403403

404-
if (!IS_STRING(chunk) && !IS_BUFFER(chunk)) {
404+
if (!util.isString(chunk) && !util.isBuffer(chunk)) {
405405
throw new TypeError('first argument must be a string or Buffer');
406406
}
407407

@@ -412,7 +412,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
412412

413413
var len, ret;
414414
if (this.chunkedEncoding) {
415-
if (IS_STRING(chunk) &&
415+
if (util.isString(chunk) &&
416416
encoding !== 'hex' &&
417417
encoding !== 'base64' &&
418418
encoding !== 'binary') {
@@ -444,7 +444,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
444444
OutgoingMessage.prototype.addTrailers = function(headers) {
445445
this._trailer = '';
446446
var keys = Object.keys(headers);
447-
var isArray = IS_ARRAY(headers);
447+
var isArray = util.isArray(headers);
448448
var field, value;
449449
for (var i = 0, l = keys.length; i < l; i++) {
450450
var key = keys[i];
@@ -466,7 +466,7 @@ var crlf_buf = new Buffer('\r\n');
466466

467467

468468
OutgoingMessage.prototype.end = function(data, encoding) {
469-
if (data && !IS_STRING(data) && !IS_BUFFER(data)) {
469+
if (data && !util.isString(data) && !util.isBuffer(data)) {
470470
throw new TypeError('first argument must be a string or Buffer');
471471
}
472472

lib/_http_server.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ServerResponse.prototype._implicitHeader = function() {
173173
ServerResponse.prototype.writeHead = function(statusCode) {
174174
var reasonPhrase, headers, headerIndex;
175175

176-
if (IS_STRING(arguments[1])) {
176+
if (util.isString(arguments[1])) {
177177
reasonPhrase = arguments[1];
178178
headerIndex = 2;
179179
} else {
@@ -188,13 +188,13 @@ ServerResponse.prototype.writeHead = function(statusCode) {
188188
// Slow-case: when progressive API and header fields are passed.
189189
headers = this._renderHeaders();
190190

191-
if (IS_ARRAY(obj)) {
191+
if (util.isArray(obj)) {
192192
// handle array case
193193
// TODO: remove when array is no longer accepted
194194
var field;
195195
for (var i = 0, len = obj.length; i < len; ++i) {
196196
field = obj[i][0];
197-
if (!IS_UNDEFINED(headers[field])) {
197+
if (!util.isUndefined(headers[field])) {
198198
obj.push([field, headers[field]]);
199199
}
200200
}
@@ -332,7 +332,7 @@ function connectionListener(socket) {
332332
parser.incoming = null;
333333

334334
// Propagate headers limit from server instance to parser
335-
if (IS_NUMBER(this.maxHeadersCount)) {
335+
if (util.isNumber(this.maxHeadersCount)) {
336336
parser.maxHeaderPairs = this.maxHeadersCount << 1;
337337
} else {
338338
// Set default value because parser may be reused from FreeList
@@ -442,7 +442,7 @@ function connectionListener(socket) {
442442
}
443443
});
444444

445-
if (!IS_UNDEFINED(req.headers.expect) &&
445+
if (!util.isUndefined(req.headers.expect) &&
446446
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1) &&
447447
continueExpression.test(req.headers['expect'])) {
448448
res._expect_continue = true;

lib/_stream_readable.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function Readable(options) {
111111
Readable.prototype.push = function(chunk, encoding) {
112112
var state = this._readableState;
113113

114-
if (IS_STRING(chunk) && !state.objectMode) {
114+
if (util.isString(chunk) && !state.objectMode) {
115115
encoding = encoding || state.defaultEncoding;
116116
if (encoding !== state.encoding) {
117117
chunk = new Buffer(chunk, encoding);
@@ -132,7 +132,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
132132
var er = chunkInvalid(state, chunk);
133133
if (er) {
134134
stream.emit('error', er);
135-
} else if (IS_NULL_OR_UNDEFINED(chunk)) {
135+
} else if (util.isNullOrUndefined(chunk)) {
136136
state.reading = false;
137137
if (!state.ended)
138138
onEofChunk(stream, state);
@@ -213,7 +213,7 @@ function howMuchToRead(n, state) {
213213
if (state.objectMode)
214214
return n === 0 ? 0 : 1;
215215

216-
if (isNaN(n) || IS_NULL(n)) {
216+
if (isNaN(n) || util.isNull(n)) {
217217
// only flow one buffer at a time
218218
if (state.flowing && state.buffer.length)
219219
return state.buffer[0].length;
@@ -249,7 +249,7 @@ Readable.prototype.read = function(n) {
249249
var state = this._readableState;
250250
var nOrig = n;
251251

252-
if (!IS_NUMBER(n) || n > 0)
252+
if (!util.isNumber(n) || n > 0)
253253
state.emittedReadable = false;
254254

255255
// if we're doing read(0) to trigger a readable event, but we
@@ -337,7 +337,7 @@ Readable.prototype.read = function(n) {
337337
else
338338
ret = null;
339339

340-
if (IS_NULL(ret)) {
340+
if (util.isNull(ret)) {
341341
state.needReadable = true;
342342
n = 0;
343343
}
@@ -353,17 +353,17 @@ Readable.prototype.read = function(n) {
353353
if (nOrig !== n && state.ended && state.length === 0)
354354
endReadable(this);
355355

356-
if (!IS_NULL(ret))
356+
if (!util.isNull(ret))
357357
this.emit('data', ret);
358358

359359
return ret;
360360
};
361361

362362
function chunkInvalid(state, chunk) {
363363
var er = null;
364-
if (!IS_BUFFER(chunk) &&
365-
!IS_STRING(chunk) &&
366-
!IS_NULL_OR_UNDEFINED(chunk) &&
364+
if (!util.isBuffer(chunk) &&
365+
!util.isString(chunk) &&
366+
!util.isNullOrUndefined(chunk) &&
367367
!state.objectMode &&
368368
!er) {
369369
er = new TypeError('Invalid non-string/buffer chunk');
@@ -761,7 +761,7 @@ Readable.prototype.wrap = function(stream) {
761761
// proxy all the other methods.
762762
// important when wrapping filters and duplexes.
763763
for (var i in stream) {
764-
if (IS_FUNCTION(stream[i]) && IS_UNDEFINED(this[i])) {
764+
if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
765765
this[i] = function(method) { return function() {
766766
return stream[method].apply(stream, arguments);
767767
}}(i);

lib/_stream_transform.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function afterTransform(stream, er, data) {
9292
ts.writechunk = null;
9393
ts.writecb = null;
9494

95-
if (!IS_NULL_OR_UNDEFINED(data))
95+
if (!util.isNullOrUndefined(data))
9696
stream.push(data);
9797

9898
if (cb)
@@ -126,7 +126,7 @@ function Transform(options) {
126126
this._readableState.sync = false;
127127

128128
this.once('prefinish', function() {
129-
if (IS_FUNCTION(this._flush))
129+
if (util.isFunction(this._flush))
130130
this._flush(function(er) {
131131
done(stream, er);
132132
});
@@ -174,7 +174,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
174174
Transform.prototype._read = function(n) {
175175
var ts = this._transformState;
176176

177-
if (!IS_NULL(ts.writechunk) && ts.writecb && !ts.transforming) {
177+
if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
178178
ts.transforming = true;
179179
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
180180
} else {

0 commit comments

Comments
 (0)