Skip to content

Commit

Permalink
lib: add support for inherited custom inspection methods
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48306
Fixes: nodejs#48207
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and Ceres6 committed Aug 14, 2023
1 parent 65a0b58 commit 117c65d
Show file tree
Hide file tree
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
Expand Up @@ -13,7 +13,6 @@ const {
ObjectGetOwnPropertyNames,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectPrototypeToString,
RangeError,
ReferenceError,
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-error-serdes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 117c65d

Please sign in to comment.