diff --git a/lib/net.js b/lib/net.js index 2442bcdee36cd4..79692da3524ca9 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1090,12 +1090,14 @@ function Server(options, connectionListener) { connectionListener = options; options = {}; self.on('connection', connectionListener); - } else { + } else if (options == null || typeof options === 'object') { options = options || {}; if (typeof connectionListener === 'function') { self.on('connection', connectionListener); } + } else { + throw new TypeError('options must be an object'); } this._connections = 0; diff --git a/test/parallel/test-net-server-options.js b/test/parallel/test-net-server-options.js new file mode 100644 index 00000000000000..1445c3e6b8245f --- /dev/null +++ b/test/parallel/test-net-server-options.js @@ -0,0 +1,7 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +assert.throws(function() { net.createServer('path'); }, TypeError); +assert.throws(function() { net.createServer(common.PORT); }, TypeError);