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: #48306
Fixes: #48207
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and ruyadorno committed Sep 1, 2023
1 parent 27a4bc7 commit 5260f53
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
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
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 5260f53

Please sign in to comment.