Skip to content

Commit 6adb527

Browse files
inspect: correctly handle custom objects without class name (#2075)
1 parent 37c527d commit 6adb527

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/jsutils/__tests__/inspect-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,10 @@ describe('inspect', () => {
177177

178178
(Foo.prototype: any)[Symbol.toStringTag] = 'Bar';
179179
expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]');
180+
181+
const objectWithoutClassName = new (function() {
182+
this.foo = 1;
183+
})();
184+
expect(inspect([[objectWithoutClassName]])).to.equal('[[[Object]]]');
180185
});
181186
});

src/jsutils/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function getObjectTag(object) {
117117

118118
if (tag === 'Object' && typeof object.constructor === 'function') {
119119
const name = object.constructor.name;
120-
if (typeof name === 'string') {
120+
if (typeof name === 'string' && name !== '') {
121121
return name;
122122
}
123123
}

0 commit comments

Comments
 (0)