Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix definition of "listen" of net$Server and its subclasses #8290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 23 additions & 45 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,50 +1399,14 @@ declare class http$ServerResponse extends stream$Writable {
}

declare class http$Server extends net$Server {
listen(port?: number, hostname?: string, backlog?: number, callback?: Function): this;
// The following signatures are added to allow omitting intermediate arguments
listen(port?: number, backlog?: number, callback?: Function): this;
listen(port?: number, hostname?: string, callback?: Function): this;
listen(port?: number, callback?: Function): this;
listen(path: string, callback?: Function): this;
listen(handle: {
port?: number,
host?: string,
path?: string,
backlog?: number,
exclusive?: boolean,
readableAll?: boolean,
writableAll?: boolean,
ipv6Only?: boolean,
...
}, callback?: Function): this;
listening: boolean;
close(callback?: (error: ?Error) => mixed): this;
maxHeadersCount: number;
keepAliveTimeout: number;
setTimeout(msecs: number, callback: Function): this;
timeout: number;
}

declare class https$Server extends tls$Server {
listen(port?: number, hostname?: string, backlog?: number, callback?: Function): this;
// The following signatures are added to allow omitting intermediate arguments
listen(port?: number, backlog?: number, callback?: Function): this;
listen(port?: number, hostname?: string, callback?: Function): this;
listen(port?: number, callback?: Function): this;
listen(path: string, callback?: Function): this;
listen(handle: {
port?: number,
host?: string,
path?: string,
backlog?: number,
exclusive?: boolean,
readableAll?: boolean,
writableAll?: boolean,
ipv6Only?: boolean,
...
}, callback?: Function): this;
close(callback?: (error: ?Error) => mixed): this;
maxHeadersCount: number;
keepAliveTimeout: number;
setTimeout(msecs: number, callback: Function): this;
timeout: number;
Expand Down Expand Up @@ -1590,11 +1554,29 @@ declare class net$Socket extends stream$Duplex {
}

declare class net$Server extends events$EventEmitter {
listen(port?: number, hostname?: string, backlog?: number, callback?: Function): net$Server;
listen(path: string, callback?: Function): net$Server;
listen(handle: Object, callback?: Function): net$Server;
listen(port?: number, hostname?: string, backlog?: number, callback?: () => mixed): this;
// The following signatures are added to allow omitting intermediate arguments
listen(port?: number, backlog?: number, callback?: () => mixed): this;
listen(port?: number, hostname?: string, callback?: () => mixed): this;
listen(port?: number, callback?: () => mixed): this;
listen(path: string, callback?: () => mixed): this;
listen(callback?: () => mixed): this;
// port or path is required. Let the object have at least one non-optional property to avoid matching "handle" type.
listen(options: ({port: numberm, ...} | {path: string, ...}) & {
port?: number,
host?: string,
path?: string,
backlog?: number,
exclusive?: boolean,
readableAll?: boolean,
writableAll?: boolean,
ipv6Only?: boolean,
...
}, callback?: () => mixed): this;
listen(handle: net$Server | net$Socket | {_handle: any, ...} | {fd: number, ...}, backlog?: number, callback?: () => mixed): this;
listen(handle: net$Server | net$Socket | {_handle: any, ...} | {fd: number, ...}, callback?: () => mixed): this;
listening: boolean;
close(callback?: Function): net$Server;
close(callback?: (error: ?Error) => mixed): this;
address(): net$Socket$address;
connections: number;
maxConnections: number;
Expand Down Expand Up @@ -2100,10 +2082,6 @@ declare class tls$TLSSocket extends net$Socket {
}

declare class tls$Server extends net$Server {
listen(port?: number, hostname?: string, backlog?: number, callback?: Function): tls$Server;
listen(path: string, callback?: Function): tls$Server;
listen(handle: Object, callback?: Function): tls$Server;
close(callback?: Function): tls$Server;
addContext(hostname: string, context: Object): void;
getTicketKeys(): Buffer;
setTicketKeys(keys: Buffer): void;
Expand Down
32 changes: 23 additions & 9 deletions tests/node_tests/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ const server = http.createServer((req, res) => {
res.end();
});

// server.listen(handle[, callback])
// server.listen(options[, callback])
// -
// server.listen(handle);
server.listen({});
// server.listen(options);
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true});
server.listen({fd: '/var/run/mysocket'});
// server.listen(handle, callback);
server.listen({}, () => {});
server.listen({}, function() {});
server.listen({path: '/var/run/mysocket'});
// server.listen(options, callback);
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true}, () => {});
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true}, function() {});
server.listen({fd: '/var/run/mysocket'}, () => {});
server.listen({fd: '/var/run/mysocket'}, function() {});
server.listen({path: '/var/run/mysocket'}, () => {});
server.listen({path: '/var/run/mysocket'}, function() {});

// server.listen(handle[, backlog][, callback])
// -
// server.listen(handle);
server.listen(server);
server.listen({_handle: {}});
server.listen({fd: 13});
// server.listen(handle, backlog);
server.listen({fd: 13}, 123);
// server.listen(handle, callback);
server.listen({fd: 13}, () => {});
server.listen({fd: 13}, function() {});
// server.listen(handle, backlog, callback);
server.listen({fd: 13}, 123, () => {});
server.listen({fd: 13}, 123, function() {});

// server.listen(path[, callback])
// -
Expand Down Expand Up @@ -64,6 +76,8 @@ server.listen(8000, undefined, 123, () => {});
server.listen(8000, undefined, 123, function() {});

// These should fail
server.listen({});
server.listen({fd: 'file descriptor must be a number'});
server.listen(() => {}, {});
server.listen(function() {}, {});
server.listen({}, () => {}, 'localhost', 123);
Expand Down
34 changes: 24 additions & 10 deletions tests/node_tests/https/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ const server = https.createServer((req, res) => {
res.end();
});

// server.listen(handle[, callback])
// server.listen(options[, callback])
// -
// server.listen(options);
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true});
server.listen({path: '/var/run/mysocket'});
// server.listen(options, callback);
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true}, () => {});
server.listen({port: 8080, host: 'localhost', backlog: 123, exclusive: true}, function() {});
server.listen({path: '/var/run/mysocket'}, () => {});
server.listen({path: '/var/run/mysocket'}, function() {});

// server.listen(handle[, backlog][, callback])
// -
// server.listen(handle);
server.listen({});
server.listen({port: 8443, host: 'localhost', backlog: 123, exclusive: true});
server.listen({fd: '/var/run/mysocket'});
server.listen(server);
server.listen({_handle: {}});
server.listen({fd: 13});
// server.listen(handle, backlog);
server.listen({fd: 13}, 123);
// server.listen(handle, callback);
server.listen({}, () => {});
server.listen({}, function() {});
server.listen({port: 8443, host: 'localhost', backlog: 123, exclusive: true}, () => {});
server.listen({port: 8443, host: 'localhost', backlog: 123, exclusive: true}, function() {});
server.listen({fd: '/var/run/mysocket'}, () => {});
server.listen({fd: '/var/run/mysocket'}, function() {});
server.listen({fd: 13}, () => {});
server.listen({fd: 13}, function() {});
// server.listen(handle, backlog, callback);
server.listen({fd: 13}, 123, () => {});
server.listen({fd: 13}, 123, function() {});

// server.listen(path[, callback])
// -
Expand Down Expand Up @@ -64,6 +76,8 @@ server.listen(8000, undefined, 123, () => {});
server.listen(8000, undefined, 123, function() {});

// These should fail
server.listen({});
server.listen({fd: 'file descriptor must be a number'});
server.listen(() => {}, {});
server.listen(function() {}, {});
server.listen({}, () => {}, 'localhost', 123);
Expand Down
Loading