Skip to content

Commit 0162a0f

Browse files
aduh95RafaelGSS
authored andcommitted
lib: add support for inherited custom inspection methods
PR-URL: #48306 Fixes: #48207 Reviewed-By: James M Snell <[email protected]>
1 parent 84fe811 commit 0162a0f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/internal/error_serdes.js

Lines changed: 1 addition & 3 deletions
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

Lines changed: 8 additions & 0 deletions
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)