From 8b79d0f94b13ce9837245c49cb32db9358df0ef0 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 4 Apr 2016 19:02:20 -0500 Subject: [PATCH] Use Object.freeze in a backwards compatible way --- storage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/storage.js b/storage.js index d10fe299..98218d8d 100644 --- a/storage.js +++ b/storage.js @@ -541,7 +541,10 @@ function equal(a, b) { function defineReadonlyProperty(obj, key, value) { var copy = deepCopy(value); - Object.freeze(copy); + // In ES6, freezing a literal is OK (it returns the same value), but in previous versions it's an exception. + if (typeof copy == "object") { + Object.freeze(copy); + } Object.defineProperty(obj, key, {value: copy, configurable: true}) }