Author: ygrego Date: 2015-04-14 09:03:21 +0000 (Tue, 14 Apr 2015) New Revision: 1161 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1161 Log: Addition of a verification on parameter of method "addChannelConstraint". And simplification of the constraint addition. Modified: oipf/js/impl/model/MetadataSearch.js Modified: oipf/js/impl/model/MetadataSearch.js =================================================================== --- oipf/js/impl/model/MetadataSearch.js 2015-04-14 08:14:05 UTC (rev 1160) +++ oipf/js/impl/model/MetadataSearch.js 2015-04-14 09:03:21 UTC (rev 1161) @@ -238,21 +238,33 @@ * */ addChannelConstraint: function(channels) { - if (channels) { - if (channels.length) { - for (var i = 0, l = channels.length; i <= l; i++) { - this._constraints.channels && - this._constraints.channels.push(channels[i]); - } - } else { - this._constraints.channels && - this._constraints.channels.push(channels); - } + var parameters = arguments; + + if (parameters.length > 1) { + throw new TypeError("Excessive number of arguments."); + } + + if (parameters.length < 1) { + throw new TypeError("Insufficient number of arguments."); + } + + if (!channels) { + this._constraints.channels.length = 0; - } else if (this._constraints.channels) { - this._constraints.channels = []; + } else if (!(channels instanceof ChannelList) && + !(channels instanceof Channel) || channels != null) { + + throw new TypeError + ("This function cannot be called with this argument."); + } + if (this._constraints.channels) { + this._constraints.channels = + this._constraints.channels.concat(channels); + + } + }, /*