Skip to content
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
9 changes: 8 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,14 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
protoProps = undefined;
}

let tag = value[SymbolToStringTag];
let tag = '';

try {
tag = value[SymbolToStringTag];
} catch {
// Ignore error.
}

// Only list the tag in case it's non-enumerable / not an own property.
// Otherwise we'd print this twice.
if (typeof tag !== 'string' ||
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ util.inspect(process);
}
}

assert.throws(() => util.inspect(new ThrowingClass()), /toStringTag error/);
assert.strictEqual(util.inspect(new ThrowingClass()), 'ThrowingClass {}');

const y = {
get [Symbol.toStringTag]() {
Expand All @@ -1655,7 +1655,11 @@ util.inspect(process);
};
const x = { y };
y.x = x;
assert.throws(() => util.inspect(x), /TypeError: Converting circular structure to JSON/);

assert.strictEqual(
util.inspect(x),
'<ref *1> {\n y: { x: [Circular *1], Symbol(Symbol.toStringTag): [Getter] }\n}'
);

class NotStringClass {
get [Symbol.toStringTag]() {
Expand Down
Loading