Do not call isFrozen on non-freezables

fixes #1
This commit is contained in:
Aaron Jensen 2015-08-02 07:06:35 -07:00
parent 49201f539a
commit 2dd272e429

View File

@ -1,9 +1,10 @@
function isFreezable(obj) { function isFreezable(obj) {
if (Object.isFrozen(obj)) { return Array.isArray(obj) ||
return false; typeof obj === 'object';
} }
return Array.isArray(obj) || typeof obj === 'object'; function needsFreezing(obj) {
return isFreezable(obj) && !Object.isFrozen(obj);
} }
function recur(obj) { function recur(obj) {
@ -11,7 +12,7 @@ function recur(obj) {
Object.keys(obj).forEach((key) => { Object.keys(obj).forEach((key) => {
const value = obj[key]; const value = obj[key];
if (isFreezable(value)) { if (needsFreezing(value)) {
recur(value); recur(value);
} }
}); });
@ -24,7 +25,7 @@ export default function freeze(obj) {
return obj; return obj;
} }
if (isFreezable(obj)) { if (needsFreezing(obj)) {
recur(obj); recur(obj);
} }