Don't freeze regexps (#65)

This commit is contained in:
David Golightly 2016-07-06 18:20:59 -07:00 committed by Aaron Jensen
parent 5bccf497ea
commit cea10920cd
2 changed files with 8 additions and 0 deletions

View File

@ -1,5 +1,6 @@
function isFreezable(object) { function isFreezable(object) {
if (object === null) return false; if (object === null) return false;
if (object instanceof RegExp) return false;
return Array.isArray(object) || return Array.isArray(object) ||
typeof object === 'object'; typeof object === 'object';

View File

@ -35,6 +35,13 @@ describe('u.freeze', () => {
expect(Object.isFrozen(object.foo)).to.be.false; expect(Object.isFrozen(object.foo)).to.be.false;
}); });
it('ignores regexps', () => {
const object = { foo: /\d/ };
u.freeze(object);
expect(Object.isFrozen(object.foo)).to.be.false;
});
it('does not freeze children if the parent is already frozen', () => { it('does not freeze children if the parent is already frozen', () => {
const object = { foo: {} }; const object = { foo: {} };
Object.freeze(object); Object.freeze(object);