util: inspect objects with throwing Symbol.toStringTag · nodejs/node@3c62b38

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -935,7 +935,14 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {

935935

protoProps = undefined;

936936

}

937937
938-

let tag = value[SymbolToStringTag];

938+

let tag = '';

939+
940+

try {

941+

tag = value[SymbolToStringTag];

942+

} catch {

943+

// Ignore error.

944+

}

945+
939946

// Only list the tag in case it's non-enumerable / not an own property.

940947

// Otherwise we'd print this twice.

941948

if (typeof tag !== 'string' ||

Original file line numberDiff line numberDiff line change

@@ -1646,7 +1646,7 @@ util.inspect(process);

16461646

}

16471647

}

16481648
1649-

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

1649+

assert.strictEqual(util.inspect(new ThrowingClass()), 'ThrowingClass {}');

16501650
16511651

const y = {

16521652

get [Symbol.toStringTag]() {

@@ -1655,7 +1655,11 @@ util.inspect(process);

16551655

};

16561656

const x = { y };

16571657

y.x = x;

1658-

assert.throws(() => util.inspect(x), /TypeError: Converting circular structure to JSON/);

1658+
1659+

assert.strictEqual(

1660+

util.inspect(x),

1661+

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

1662+

);

16591663
16601664

class NotStringClass {

16611665

get [Symbol.toStringTag]() {