Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add support for inherited custom inspection methods
Browse files Browse the repository at this point in the history
PR-URL: #48306
Fixes: #48207
Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95 authored and ruyadorno committed Aug 29, 2023
1 parent 22c4a9b commit f10ebb0
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/internal/error_serdes.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ const {
ObjectGetOwnPropertyNames,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectPrototypeToString,
RangeError,
ReferenceError,
@@ -134,8 +133,7 @@ function serializeError(error) {
// Continue regardless of error.
}
try {
if (error != null &&
ObjectPrototypeHasOwnProperty(error, customInspectSymbol)) {
if (error != null && customInspectSymbol in error) {
return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8');
}
} catch {
8 changes: 8 additions & 0 deletions test/parallel/test-error-serdes.js
Original file line number Diff line number Diff line change
@@ -125,3 +125,11 @@ const data = {
}
};
assert.strictEqual(inspect(cycle(data)), 'barbaz');

const inheritedCustomInspect = new class {
foo = 'bar';
[inspect.custom]() {
return 'barbaz';
}
}();
assert.strictEqual(inspect(cycle(inheritedCustomInspect)), 'barbaz');

0 comments on commit f10ebb0

Please sign in to comment.