From 2dd272e429ee28238d088fff4b2691e7efe804c0 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sun, 2 Aug 2015 07:06:35 -0700 Subject: [PATCH] Do not call isFrozen on non-freezables fixes #1 --- lib/freeze.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/freeze.js b/lib/freeze.js index e4d8eb4..cd1ae6a 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -1,9 +1,10 @@ function isFreezable(obj) { - if (Object.isFrozen(obj)) { - return false; - } + return Array.isArray(obj) || + typeof obj === 'object'; +} - return Array.isArray(obj) || typeof obj === 'object'; +function needsFreezing(obj) { + return isFreezable(obj) && !Object.isFrozen(obj); } function recur(obj) { @@ -11,7 +12,7 @@ function recur(obj) { Object.keys(obj).forEach((key) => { const value = obj[key]; - if (isFreezable(value)) { + if (needsFreezing(value)) { recur(value); } }); @@ -24,7 +25,7 @@ export default function freeze(obj) { return obj; } - if (isFreezable(obj)) { + if (needsFreezing(obj)) { recur(obj); }