Skip to content

Commit ffd4a9a

Browse files
committed
Tighten conn.subscribe() argument checking
1 parent 8e4806e commit ffd4a9a

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

lib/connection.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,27 +325,13 @@ pingPromisified = nodbUtil.promisify(ping);
325325

326326
// create a subscription which can be used to get notifications of database
327327
// changes
328-
function subscribe(name, a2, a3) {
328+
function subscribe(name, options, subscribeCb) {
329329
var self = this;
330-
var options = {};
331-
var subscribeCb;
332330

333-
nodbUtil.assert(arguments.length >= 2 && arguments.length <= 3, 'NJS-009');
331+
nodbUtil.assert(arguments.length == 3, 'NJS-009');
334332
nodbUtil.assert(typeof name === 'string', 'NJS-006', 1);
335-
336-
switch (arguments.length) {
337-
case 2:
338-
nodbUtil.assert(typeof a2 === 'function', 'NJS-006', 2);
339-
subscribeCb = a2;
340-
break;
341-
case 3:
342-
nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-006', 2);
343-
nodbUtil.assert(typeof a3 === 'function', 'NJS-006', 3);
344-
options = a2;
345-
subscribeCb = a3;
346-
break;
347-
}
348-
333+
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-006', 2);
334+
nodbUtil.assert(typeof subscribeCb === 'function', 'NJS-006', 3);
349335
self._subscribe.call(self, name, options, subscribeCb);
350336
}
351337

0 commit comments

Comments
 (0)