Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inspect null prototype objects #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down