Throw an error if configure() is called with unrecognised options.

This commit is contained in:
James Coglan
2014-12-17 21:37:01 +00:00
parent e7619d9091
commit a71a06180a
2 changed files with 20 additions and 1 deletions
+7
View File
@@ -29,6 +29,13 @@ var common = {
return _default;
},
validateOptions: function(options, validKeys) {
for (var key in options) {
if (validKeys.indexOf(key) < 0)
throw new Error('Unrecognized option: ' + key);
}
},
validParams: function(params) {
var keys = Object.keys(params), i = keys.length;
while (i--) {
+13 -1
View File
@@ -1,10 +1,22 @@
'use strict';
var ClientSession = require('./client_session'),
ServerSession = require('./server_session');
ServerSession = require('./server_session'),
common = require('./common');
var VALID_OPTIONS = [
'level',
'memLevel',
'strategy',
'noContextTakeover',
'maxWindowBits',
'requestNoContextTakeover',
'requestMaxWindowBits'
];
var PermessageDeflate = {
configure: function(options) {
common.validateOptions(options, VALID_OPTIONS);
var opts = this._options || {};
for (var key in opts) options[key] = opts[key];
return Object.create(this, {_options: {value: options}});