diff --git a/index.js b/index.js index 0a27ca8..0f289f8 100644 --- a/index.js +++ b/index.js @@ -165,6 +165,11 @@ export function inspect(value, options) { return inspectObject(value, options) } + // last chance to check if it's an object + if (value === Object(value)) { + return inspectObject(value, options) + } + // We have run out of options! Just stringify the value return options.stylize(String(value), type) } diff --git a/test/objects.js b/test/objects.js index deda334..880f584 100644 --- a/test/objects.js +++ b/test/objects.js @@ -39,6 +39,10 @@ for (const [suite, inspect] of Object.entries({ expect(inspect(Object.create({ a: 1 }))).to.equal('{}') }) + it('returns `{}` for empty objects with a null prototype', () => { + expect(inspect(Object.create(Object.create(null)))).to.equal('{}') + }) + it("shows objects' own properties for objects with an anonoymous prototype", () => { const obj = Object.create({ a: 1 }) obj.b = 2