tolerate harden() of objects with null prototypes
refs
MODIFY
index.js
index.js
@@ -72,7 +72,7 @@ function makeHardener(initialFringe) {
const path = paths.get(obj) || 'unknown';
// console.log(`adding ${proto} to prototypes under ${path}`);
- if (!prototypes.has(proto)) {
+ if (proto !== null && !prototypes.has(proto)) {
prototypes.set(proto, path);
paths.set(proto, `${path}.__proto__`);
}

MODIFY
test/test.js
test/test.js
@@ -100,3 +100,13 @@ test('can harden all objects in a single call', t => {
t.end();
});
+
+test('harden() tolerates objects with null prototypes', t => {
+ const h = makeHardener([Object.prototype]);
+ const o = { a: 1 };
+ Object.setPrototypeOf(o, null);
+ t.equal(h(o), o);
+ t.ok(Object.isFrozen(o));
+ t.ok(Object.isFrozen(o.a));
+ t.end();
+});

tolerate harden() of objects with null prototypes

refs #11