GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: macro-ify type checks · lightsofapollo/node@0330bdf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _debugger.js
    • _http_agent.js
    • _http_client.js
    • _http_incoming.js
    • _http_outgoing.js
    • _http_server.js
    • _stream_readable.js
    • _stream_transform.js
    • _stream_writable.js
    • _tls_legacy.js
    • _tls_wrap.js
    • assert.js
    • buffer.js
    • child_process.js
    • cluster.js
    • console.js
    • crypto.js
    • dgram.js
    • dns.js
    • domain.js
    • events.js
    • fs.js
    • https.js
    • module.js
    • net.js
    • path.js
    • querystring.js
    • readline.js
    • repl.js
    • smalloc.js
    • stream.js
    • tls.js
    • url.js
    • util.js
    • vm.js
    • zlib.js
  • node.gyp
  • src
    • macros.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_debugger.js‎

Copy file name to clipboardExpand all lines: lib/_debugger.js
+10-11Lines changed: 10 additions & 11 deletions
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 (typeof desc != 'object' || typeof desc.handle != 'number') {
185+
if (!IS_OBJECT(desc) || !IS_NUMBER(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 (typeof res[ref] == 'object') {
299+
if (IS_OBJECT(res[ref])) {
300300
self._addHandle(res[ref]);
301301
}
302302
}
@@ -559,8 +559,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
559559
}
560560

561561

562-
if (Array.isArray(mirror) &&
563-
typeof prop.name != 'number') {
562+
if (IS_ARRAY(mirror) && !IS_NUMBER(prop.name)) {
564563
// Skip the 'length' property.
565564
return;
566565
}
@@ -593,7 +592,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
593592
val = function() {};
594593
} else if (handle.type === 'null') {
595594
val = null;
596-
} else if (handle.value !== undefined) {
595+
} else if (!IS_UNDEFINED(handle.value)) {
597596
val = handle.value;
598597
} else if (handle.type === 'undefined') {
599598
val = undefined;
@@ -892,7 +891,7 @@ Interface.prototype.print = function(text, oneline) {
892891
if (this.killed) return;
893892
this.clearline();
894893

895-
this.stdout.write(typeof text === 'string' ? text : util.inspect(text));
894+
this.stdout.write(IS_STRING(text) ? text : util.inspect(text));
896895

897896
if (oneline !== true) {
898897
this.stdout.write('\n');
@@ -1214,7 +1213,7 @@ Interface.prototype.scripts = function() {
12141213
this.pause();
12151214
for (var id in client.scripts) {
12161215
var script = client.scripts[id];
1217-
if (typeof script == 'object' && script.name) {
1216+
if (IS_OBJECT(script) && script.name) {
12181217
if (displayNatives ||
12191218
script.name == client.currentScript ||
12201219
!script.isNative) {
@@ -1351,13 +1350,13 @@ Interface.prototype.setBreakpoint = function(script, line,
13511350
ambiguous;
13521351

13531352
// setBreakpoint() should insert breakpoint on current line
1354-
if (script === undefined) {
1353+
if (IS_UNDEFINED(script)) {
13551354
script = this.client.currentScript;
13561355
line = this.client.currentSourceLine + 1;
13571356
}
13581357

13591358
// setBreakpoint(line-number) should insert breakpoint in current script
1360-
if (line === undefined && typeof script === 'number') {
1359+
if (IS_UNDEFINED(line) && IS_NUMBER(script)) {
13611360
line = script;
13621361
script = this.client.currentScript;
13631362
}
@@ -1452,7 +1451,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14521451
if (bp.scriptId === script ||
14531452
bp.scriptReq === script ||
14541453
(bp.script && bp.script.indexOf(script) !== -1)) {
1455-
if (index !== undefined) {
1454+
if (!IS_UNDEFINED(index)) {
14561455
ambiguous = true;
14571456
}
14581457
if (bp.line === line) {
@@ -1465,7 +1464,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14651464

14661465
if (ambiguous) return this.error('Script name is ambiguous');
14671466

1468-
if (breakpoint === undefined) {
1467+
if (IS_UNDEFINED(breakpoint)) {
14691468
return this.error('Script : ' + script + ' not found');
14701469
}
14711470

Collapse file

‎lib/_http_agent.js‎

Copy file name to clipboardExpand all lines: lib/_http_agent.js
+1-1Lines changed: 1 addition & 1 deletion
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 (typeof options === 'string') {
249+
if (IS_STRING(options)) {
250250
options = url.parse(options);
251251
}
252252
// don't try to do dns lookups of foo.com:8080, just foo.com
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+5-5Lines changed: 5 additions & 5 deletions
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 = options.agent === undefined ? globalAgent : options.agent;
47+
self.agent = IS_UNDEFINED(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 (options.setHost === undefined) {
54+
if (IS_UNDEFINED(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 (!Array.isArray(options.headers)) {
66+
if (!IS_ARRAY(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 (Array.isArray(options.headers)) {
95+
if (IS_ARRAY(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 (typeof req.maxHeadersCount === 'number') {
416+
if (IS_NUMBER(req.maxHeadersCount)) {
417417
parser.maxHeaderPairs = req.maxHeadersCount << 1;
418418
} else {
419419
// Set default value because parser may be reused from FreeList
Collapse file

‎lib/_http_incoming.js‎

Copy file name to clipboardExpand all lines: lib/_http_incoming.js
+4-4Lines changed: 4 additions & 4 deletions
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 (dest[field] !== undefined) {
128+
if (!IS_UNDEFINED(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 (dest[field] !== undefined) {
148+
if (!IS_UNDEFINED(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 (dest[field] !== undefined) {
159+
if (!IS_UNDEFINED(dest[field])) {
160160
dest[field] += ', ' + value;
161161
} else {
162162
dest[field] = value;
163163
}
164164
} else {
165165
// drop duplicates
166-
if (dest[field] === undefined) dest[field] = value;
166+
if (IS_UNDEFINED(dest[field])) dest[field] = value;
167167
}
168168
break;
169169
}
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+8-8Lines changed: 8 additions & 8 deletions
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 (typeof data === 'string') {
118+
if (IS_STRING(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 || typeof data != 'string') {
169+
if (length === 0 || !IS_STRING(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 = (Array.isArray(headers));
208+
var isArray = IS_ARRAY(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 (Array.isArray(value)) {
221+
if (IS_ARRAY(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 (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) {
404+
if (!IS_STRING(chunk) && !IS_BUFFER(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 (typeof(chunk) === 'string' &&
415+
if (IS_STRING(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 = (Array.isArray(headers));
447+
var isArray = IS_ARRAY(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 && typeof data !== 'string' && !Buffer.isBuffer(data)) {
469+
if (data && !IS_STRING(data) && !IS_BUFFER(data)) {
470470
throw new TypeError('first argument must be a string or Buffer');
471471
}
472472

Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+5-5Lines changed: 5 additions & 5 deletions
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 (typeof arguments[1] == 'string') {
176+
if (IS_STRING(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 (Array.isArray(obj)) {
191+
if (IS_ARRAY(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 (headers[field] !== undefined) {
197+
if (!IS_UNDEFINED(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 (typeof this.maxHeadersCount === 'number') {
335+
if (IS_NUMBER(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 (req.headers.expect !== undefined &&
445+
if (!IS_UNDEFINED(req.headers.expect) &&
446446
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1) &&
447447
continueExpression.test(req.headers['expect'])) {
448448
res._expect_continue = true;
Collapse file

‎lib/_stream_readable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_readable.js
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function Readable(options) {
117117
Readable.prototype.push = function(chunk, encoding) {
118118
var state = this._readableState;
119119

120-
if (typeof chunk === 'string' && !state.objectMode) {
120+
if (IS_STRING(chunk) && !state.objectMode) {
121121
encoding = encoding || state.defaultEncoding;
122122
if (encoding !== state.encoding) {
123123
chunk = new Buffer(chunk, encoding);
@@ -138,7 +138,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
138138
var er = chunkInvalid(state, chunk);
139139
if (er) {
140140
stream.emit('error', er);
141-
} else if (chunk === null || chunk === undefined) {
141+
} else if (IS_NULL_OR_UNDEFINED(chunk)) {
142142
state.reading = false;
143143
if (!state.ended)
144144
onEofChunk(stream, state);
@@ -219,7 +219,7 @@ function howMuchToRead(n, state) {
219219
if (state.objectMode)
220220
return n === 0 ? 0 : 1;
221221

222-
if (isNaN(n) || n === null) {
222+
if (isNaN(n) || IS_NULL(n)) {
223223
// only flow one buffer at a time
224224
if (state.flowing && state.buffer.length)
225225
return state.buffer[0].length;
@@ -256,7 +256,7 @@ Readable.prototype.read = function(n) {
256256
state.calledRead = true;
257257
var nOrig = n;
258258

259-
if (typeof n !== 'number' || n > 0)
259+
if (!IS_NUMBER(n) || n > 0)
260260
state.emittedReadable = false;
261261

262262
// if we're doing read(0) to trigger a readable event, but we
@@ -345,7 +345,7 @@ Readable.prototype.read = function(n) {
345345
else
346346
ret = null;
347347

348-
if (ret === null) {
348+
if (IS_NULL(ret)) {
349349
state.needReadable = true;
350350
n = 0;
351351
}
@@ -363,17 +363,16 @@ Readable.prototype.read = function(n) {
363363
if (state.ended && !state.endEmitted && state.length === 0)
364364
endReadable(this);
365365

366-
if (ret !== null)
366+
if (!IS_NULL(ret))
367367
this.emit('data', ret);
368368
return ret;
369369
};
370370

371371
function chunkInvalid(state, chunk) {
372372
var er = null;
373-
if (!Buffer.isBuffer(chunk) &&
374-
'string' !== typeof chunk &&
375-
chunk !== null &&
376-
chunk !== undefined &&
373+
if (!IS_BUFFER(chunk) &&
374+
!IS_STRING(chunk) &&
375+
!IS_NULL_OR_UNDEFINED(chunk) &&
377376
!state.objectMode &&
378377
!er) {
379378
er = new TypeError('Invalid non-string/buffer chunk');
@@ -775,8 +774,7 @@ Readable.prototype.wrap = function(stream) {
775774
// proxy all the other methods.
776775
// important when wrapping filters and duplexes.
777776
for (var i in stream) {
778-
if (typeof stream[i] === 'function' &&
779-
typeof this[i] === 'undefined') {
777+
if (IS_FUNCTION(stream[i]) && IS_UNDEFINED(this[i])) {
780778
this[i] = function(method) { return function() {
781779
return stream[method].apply(stream, arguments);
782780
}}(i);
Collapse file

‎lib/_stream_transform.js‎

Copy file name to clipboardExpand all lines: lib/_stream_transform.js
+3-3Lines changed: 3 additions & 3 deletions
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 (data !== null && data !== undefined)
95+
if (!IS_NULL_OR_UNDEFINED(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 ('function' === typeof this._flush)
129+
if (IS_FUNCTION(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 (ts.writechunk !== null && ts.writecb && !ts.transforming) {
177+
if (!IS_NULL(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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.