tls: document and test option-less createServer · nodejs/node@980acb4 · GitHub
Skip to content

Commit 980acb4

Browse files
sam-githubItalo A. Casas
authored andcommitted
tls: document and test option-less createServer
Either the options or the listener argument to tls.createServer() was optional, but not both. This makes no sense, so align the argument checking and documentation with net.createServer(), which accepts the same option sequence, and which tls.createServer() is modelled on. PR-URL: #9800 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 41e1e6e commit 980acb4

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

doc/api/tls.md

Lines changed: 1 addition & 1 deletion

lib/_tls_wrap.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,19 @@ TLSSocket.prototype.getProtocol = function() {
745745
// "PATH_LENGTH_EXCEEDED", "INVALID_PURPOSE" "CERT_UNTRUSTED",
746746
// "CERT_REJECTED"
747747
//
748-
function Server(/* [options], listener */) {
749-
var options, listener;
748+
function Server(options, listener) {
749+
if (!(this instanceof Server))
750+
return new Server(options, listener);
750751

751-
if (arguments[0] !== null && typeof arguments[0] === 'object') {
752-
options = arguments[0];
753-
listener = arguments[1];
754-
} else if (typeof arguments[0] === 'function') {
752+
if (typeof options === 'function') {
753+
listener = options;
755754
options = {};
756-
listener = arguments[0];
755+
} else if (options == null || typeof options === 'object') {
756+
options = options || {};
757+
} else {
758+
throw new TypeError('options must be an object');
757759
}
758760

759-
if (!(this instanceof Server)) return new Server(options, listener);
760761

761762
this._contexts = [];
762763

test/parallel/test-tls-no-cert-required.js

Lines changed: 17 additions & 2 deletions

0 commit comments

Comments
 (0)