Skip to content

Commit

Permalink
Tighten conn.subscribe() argument checking
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbj committed Jun 5, 2018
1 parent 8e4806e commit ffd4a9a
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,13 @@ pingPromisified = nodbUtil.promisify(ping);

// create a subscription which can be used to get notifications of database
// changes
function subscribe(name, a2, a3) {
function subscribe(name, options, subscribeCb) {
var self = this;
var options = {};
var subscribeCb;

nodbUtil.assert(arguments.length >= 2 && arguments.length <= 3, 'NJS-009');
nodbUtil.assert(arguments.length == 3, 'NJS-009');
nodbUtil.assert(typeof name === 'string', 'NJS-006', 1);

switch (arguments.length) {
case 2:
nodbUtil.assert(typeof a2 === 'function', 'NJS-006', 2);
subscribeCb = a2;
break;
case 3:
nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-006', 2);
nodbUtil.assert(typeof a3 === 'function', 'NJS-006', 3);
options = a2;
subscribeCb = a3;
break;
}

nodbUtil.assert(nodbUtil.isObject(options), 'NJS-006', 2);
nodbUtil.assert(typeof subscribeCb === 'function', 'NJS-006', 3);
self._subscribe.call(self, name, options, subscribeCb);
}

Expand Down

0 comments on commit ffd4a9a

Please sign in to comment.