From 2a1e48f1b80d569de4870215881f46fb67a85d3a Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 1 Aug 2019 14:14:38 +0300 Subject: [PATCH] inspect: correctly handle custom objects without class name --- src/jsutils/__tests__/inspect-test.js | 5 +++++ src/jsutils/inspect.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jsutils/__tests__/inspect-test.js b/src/jsutils/__tests__/inspect-test.js index bd2e5ee0ee..66b0609b58 100644 --- a/src/jsutils/__tests__/inspect-test.js +++ b/src/jsutils/__tests__/inspect-test.js @@ -177,5 +177,10 @@ describe('inspect', () => { (Foo.prototype: any)[Symbol.toStringTag] = 'Bar'; expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]'); + + const objectWithoutClassName = new (function() { + this.foo = 1; + })(); + expect(inspect([[objectWithoutClassName]])).to.equal('[[[Object]]]'); }); }); diff --git a/src/jsutils/inspect.js b/src/jsutils/inspect.js index 0e444898a9..49e0d8babc 100644 --- a/src/jsutils/inspect.js +++ b/src/jsutils/inspect.js @@ -117,7 +117,7 @@ function getObjectTag(object) { if (tag === 'Object' && typeof object.constructor === 'function') { const name = object.constructor.name; - if (typeof name === 'string') { + if (typeof name === 'string' && name !== '') { return name; } }