From 2f110e5a2320d83390688d877c6d3d8d9abeec40 Mon Sep 17 00:00:00 2001 From: Matthew Findley Date: Mon, 3 Aug 2015 10:37:26 -0700 Subject: [PATCH] Handle freezing with null values --- lib/freeze.js | 2 ++ test/freeze.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/freeze.js b/lib/freeze.js index cd1ae6a..dd852a8 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -1,4 +1,6 @@ function isFreezable(obj) { + if (obj === null) return false; + return Array.isArray(obj) || typeof obj === 'object'; } diff --git a/test/freeze.js b/test/freeze.js index ca4a381..91c4d5f 100644 --- a/test/freeze.js +++ b/test/freeze.js @@ -50,4 +50,10 @@ describe('freeze', () => { expect(Object.isFrozen(obj)).to.be.false; }); + + it('handles null objects', () => { + const obj = { foo: null }; + freeze(obj); + expect(Object.isFrozen(obj)).to.be.true; + }); });