prefs.set: enforce value type based on defaults

This commit is contained in:
tophf 2017-04-11 16:12:18 +03:00
parent 97c5972348
commit 8c539dabd6

View File

@ -85,6 +85,19 @@ var prefs = new function Prefs() {
set(key, value, {noBroadcast, noSync} = {}) { set(key, value, {noBroadcast, noSync} = {}) {
const oldValue = deepCopy(values[key]); const oldValue = deepCopy(values[key]);
switch (typeof defaults[key]) {
case typeof value:
break;
case 'string':
value = String(value);
break;
case 'number':
value |= 0;
break;
case 'boolean':
value = value === true || value === 'true';
break;
}
values[key] = value; values[key] = value;
defineReadonlyProperty(this.readOnlyValues, key, value); defineReadonlyProperty(this.readOnlyValues, key, value);
if (BG && BG != window) { if (BG && BG != window) {