Skip to content

Commit 2a0bce0

Browse files
fix: handle empty null-prototyped objects (#5506)
Co-authored-by: alxndrsn <alxndrsn> Co-authored-by: Mark Wiemer <[email protected]>
1 parent fb0215b commit 2a0bce0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function emptyRepresentation(value, typeHint) {
108108
switch (typeHint) {
109109
case "function":
110110
return "[Function]";
111+
case "null-prototype":
111112
case "object":
112113
return "{}";
113114
case "array":

test/unit/utils.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ describe("lib/utils", function () {
290290
});
291291

292292
describe("should represent null prototypes", function () {
293+
it("Without properties", function () {
294+
const foo = Object.create(null, {});
295+
const expected = "{}";
296+
297+
expect(stringify(foo), "to be", expected);
298+
});
299+
293300
it("With explicit names", function () {
294301
const foo = Object.create(null, {
295302
[Symbol.toStringTag]: { value: "Foo" },

0 commit comments

Comments
 (0)