Skip to content

Commit 2c6698b

Browse files
authored
lib: add support for inherited custom inspection methods
PR-URL: #48306 Fixes: #48207 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0c875bb commit 2c6698b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/internal/error_serdes.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {
1313
ObjectGetOwnPropertyNames,
1414
ObjectGetPrototypeOf,
1515
ObjectKeys,
16-
ObjectPrototypeHasOwnProperty,
1716
ObjectPrototypeToString,
1817
RangeError,
1918
ReferenceError,
@@ -134,8 +133,7 @@ function serializeError(error) {
134133
// Continue regardless of error.
135134
}
136135
try {
137-
if (error != null &&
138-
ObjectPrototypeHasOwnProperty(error, customInspectSymbol)) {
136+
if (error != null && customInspectSymbol in error) {
139137
return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8');
140138
}
141139
} catch {

test/parallel/test-error-serdes.js

+8
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,11 @@ const data = {
125125
}
126126
};
127127
assert.strictEqual(inspect(cycle(data)), 'barbaz');
128+
129+
const inheritedCustomInspect = new class {
130+
foo = 'bar';
131+
[inspect.custom]() {
132+
return 'barbaz';
133+
}
134+
}();
135+
assert.strictEqual(inspect(cycle(inheritedCustomInspect)), 'barbaz');

0 commit comments

Comments
 (0)