checkTypes() must only check the shortest array (#1297)

* Allow optional arguments when checking types
This commit is contained in:
Kenneth Geisshirt 2017-09-12 15:17:59 +02:00 committed by GitHub
parent 12a8cd5398
commit eac393571d
1 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ function node_require(module) {
function checkTypes(args, types) { function checkTypes(args, types) {
args = Array.prototype.slice.call(args); args = Array.prototype.slice.call(args);
for (var i = 0; i < types.length; ++i) { for (var i = 0; i < types.length; ++i) {
if (typeof args[i] !== types[i]) { if (args.length > i && typeof args[i] !== types[i]) {
throw new TypeError('param ' + i + ' must be of type ' + types[i]); throw new TypeError('param ' + i + ' must be of type ' + types[i]);
} }
} }
@ -154,7 +154,7 @@ const staticMethods = {
}, },
adminUser(token, server) { adminUser(token, server) {
checkTypes(arguments, ['string']); checkTypes(arguments, ['string', 'string']);
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);