net: fix permanent deoptimizations
PR-URL: https://github.com/nodejs/node/pull/12456 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d5925af8d7
commit
3c098ee7e2
33
lib/net.js
33
lib/net.js
@ -81,15 +81,15 @@ function createServer(options, connectionListener) {
|
|||||||
// connect(path, [cb]);
|
// connect(path, [cb]);
|
||||||
//
|
//
|
||||||
function connect() {
|
function connect() {
|
||||||
const args = new Array(arguments.length);
|
var args = new Array(arguments.length);
|
||||||
for (var i = 0; i < arguments.length; i++)
|
for (var i = 0; i < arguments.length; i++)
|
||||||
args[i] = arguments[i];
|
args[i] = arguments[i];
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
||||||
const normalized = normalizeArgs(args);
|
var normalized = normalizeArgs(args);
|
||||||
const options = normalized[0];
|
var options = normalized[0];
|
||||||
const cb = normalized[1];
|
var cb = normalized[1];
|
||||||
debug('createConnection', normalized);
|
debug('createConnection', normalized);
|
||||||
const socket = new Socket(options);
|
var socket = new Socket(options);
|
||||||
|
|
||||||
if (options.timeout) {
|
if (options.timeout) {
|
||||||
socket.setTimeout(options.timeout);
|
socket.setTimeout(options.timeout);
|
||||||
@ -915,13 +915,13 @@ function internalConnect(
|
|||||||
|
|
||||||
|
|
||||||
Socket.prototype.connect = function() {
|
Socket.prototype.connect = function() {
|
||||||
const args = new Array(arguments.length);
|
var args = new Array(arguments.length);
|
||||||
for (var i = 0; i < arguments.length; i++)
|
for (var i = 0; i < arguments.length; i++)
|
||||||
args[i] = arguments[i];
|
args[i] = arguments[i];
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
||||||
const normalized = normalizeArgs(args);
|
var normalized = normalizeArgs(args);
|
||||||
const options = normalized[0];
|
var options = normalized[0];
|
||||||
const cb = normalized[1];
|
var cb = normalized[1];
|
||||||
return realConnect.call(this, options, cb);
|
return realConnect.call(this, options, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1373,19 +1373,19 @@ function listenInCluster(server, address, port, addressType,
|
|||||||
|
|
||||||
|
|
||||||
Server.prototype.listen = function() {
|
Server.prototype.listen = function() {
|
||||||
const args = new Array(arguments.length);
|
var args = new Array(arguments.length);
|
||||||
for (var i = 0; i < arguments.length; i++)
|
for (var i = 0; i < arguments.length; i++)
|
||||||
args[i] = arguments[i];
|
args[i] = arguments[i];
|
||||||
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
// TODO(joyeecheung): use destructuring when V8 is fast enough
|
||||||
const normalized = normalizeArgs(args);
|
var normalized = normalizeArgs(args);
|
||||||
var options = normalized[0];
|
var options = normalized[0];
|
||||||
const cb = normalized[1];
|
var cb = normalized[1];
|
||||||
|
|
||||||
var hasCallback = (cb !== null);
|
var hasCallback = (cb !== null);
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
this.once('listening', cb);
|
this.once('listening', cb);
|
||||||
}
|
}
|
||||||
const backlogFromArgs =
|
var backlogFromArgs =
|
||||||
// (handle, backlog) or (path, backlog) or (port, backlog)
|
// (handle, backlog) or (path, backlog) or (port, backlog)
|
||||||
toNumber(args.length > 1 && args[1]) ||
|
toNumber(args.length > 1 && args[1]) ||
|
||||||
toNumber(args.length > 2 && args[2]); // (port, host, backlog)
|
toNumber(args.length > 2 && args[2]); // (port, host, backlog)
|
||||||
@ -1414,11 +1414,12 @@ Server.prototype.listen = function() {
|
|||||||
// ([port][, host][, backlog][, cb]) where port is specified
|
// ([port][, host][, backlog][, cb]) where port is specified
|
||||||
// or (options[, cb]) where options.port is specified
|
// or (options[, cb]) where options.port is specified
|
||||||
// or if options.port is normalized as 0 before
|
// or if options.port is normalized as 0 before
|
||||||
|
var backlog;
|
||||||
if (typeof options.port === 'number' || typeof options.port === 'string') {
|
if (typeof options.port === 'number' || typeof options.port === 'string') {
|
||||||
if (!isLegalPort(options.port)) {
|
if (!isLegalPort(options.port)) {
|
||||||
throw new RangeError('"port" argument must be >= 0 and < 65536');
|
throw new RangeError('"port" argument must be >= 0 and < 65536');
|
||||||
}
|
}
|
||||||
const backlog = options.backlog || backlogFromArgs;
|
backlog = options.backlog || backlogFromArgs;
|
||||||
// start TCP server listening on host:port
|
// start TCP server listening on host:port
|
||||||
if (options.host) {
|
if (options.host) {
|
||||||
lookupAndListen(this, options.port | 0, options.host, backlog,
|
lookupAndListen(this, options.port | 0, options.host, backlog,
|
||||||
@ -1434,8 +1435,8 @@ Server.prototype.listen = function() {
|
|||||||
// (path[, backlog][, cb]) or (options[, cb])
|
// (path[, backlog][, cb]) or (options[, cb])
|
||||||
// where path or options.path is a UNIX domain socket or Windows pipe
|
// where path or options.path is a UNIX domain socket or Windows pipe
|
||||||
if (options.path && isPipeName(options.path)) {
|
if (options.path && isPipeName(options.path)) {
|
||||||
const pipeName = this._pipeName = options.path;
|
var pipeName = this._pipeName = options.path;
|
||||||
const backlog = options.backlog || backlogFromArgs;
|
backlog = options.backlog || backlogFromArgs;
|
||||||
listenInCluster(this, pipeName, -1, -1,
|
listenInCluster(this, pipeName, -1, -1,
|
||||||
backlog, undefined, options.exclusive);
|
backlog, undefined, options.exclusive);
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user