From 8c539dabd6c6975deab2f8d8075d5744960106c4 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 11 Apr 2017 16:12:18 +0300 Subject: [PATCH] prefs.set: enforce value type based on defaults --- prefs.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/prefs.js b/prefs.js index 1d80488a..854c06d6 100644 --- a/prefs.js +++ b/prefs.js @@ -85,6 +85,19 @@ var prefs = new function Prefs() { set(key, value, {noBroadcast, noSync} = {}) { 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; defineReadonlyProperty(this.readOnlyValues, key, value); if (BG && BG != window) {