--- /dev/null
+'use strict';
+
+module.exports = { isLegalPort };
+
+// Check that the port number is not NaN when coerced to a number,
+// is an integer and that it falls within the legal range of port numbers.
+function isLegalPort(port) {
+ if (typeof port === 'string' && port.trim() === '')
+ return false;
+ return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF;
+}
const timers = require('timers');
const util = require('util');
const internalUtil = require('internal/util');
+const internalNet = require('internal/net');
const assert = require('assert');
const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
var cluster;
const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;
+const isLegalPort = internalNet.isLegalPort;
function noop() {}
}
-// Check that the port number is not NaN when coerced to a number,
-// is an integer and that it falls within the legal range of port numbers.
-function isLegalPort(port) {
- if (typeof port === 'string' && port.trim() === '')
- return false;
- return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF;
-}
-
-
Socket.prototype.connect = function(options, cb) {
if (this.write !== Socket.prototype.write)
this.write = Socket.prototype.write;
'lib/internal/child_process.js',
'lib/internal/cluster.js',
'lib/internal/freelist.js',
+ 'lib/internal/net.js',
'lib/internal/module.js',
'lib/internal/socket_list.js',
'lib/internal/repl.js',
--- /dev/null
+'use strict';
+
+// Flags: --expose-internals
+
+require('../common');
+const assert = require('assert');
+const net = require('internal/net');
+
+assert.strictEqual(net.isLegalPort(''), false);
+assert.strictEqual(net.isLegalPort('0'), true);
+assert.strictEqual(net.isLegalPort(0), true);
+assert.strictEqual(net.isLegalPort(65536), false);
+assert.strictEqual(net.isLegalPort('65535'), true);
+assert.strictEqual(net.isLegalPort(undefined), false);
+assert.strictEqual(net.isLegalPort(null), true);